-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGLSRMesh.hxx
More file actions
131 lines (99 loc) · 3.04 KB
/
GLSRMesh.hxx
File metadata and controls
131 lines (99 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
////////////////////////////////////////////////////////////////////
//
// $Id: GLSRMesh.hxx 2021/06/05 13:19:11 kanai Exp $
//
// OpenGL SRMesh rendering class
//
// Copyright (c) 2021 Takashi Kanai
// Released under the MIT license
//
////////////////////////////////////////////////////////////////////
#ifndef _GLSRMESH_HXX
#define _GLSRMESH_HXX 1
#include "envDep.h"
#include "mydef.h"
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
// #include <Point3.h>
#include <Vector3.h>
#ifdef VM_INCLUDE_NAMESPACE
using namespace kh_vecmath;
#endif // VM_INCLUDE_NAMESPACE
#include "SRMesh.hxx"
#include "PMVertex.hxx"
#include "GLMesh.hxx"
//static float blackvec[] = {0.0f, 0.0f, 0.0f};
//static float bluevec[] = {0.0f, 0.0f, 1.0f};
// static float redvec[] = {1.000, 0.000, 0.000};
// static float greenvec[] = {0.000, 1.000, 0.000};
//static GLfloat onespecA[] = {1.f, 1.f, 1.f, 1.f};
//static float grayvec[] = { .5f, .5f, .5f };
class GLSRMesh : public GLMesh {
public:
GLSRMesh() { mesh_ = NULL; };
virtual ~GLSRMesh() {};
void setMesh( SRMesh& mesh ) { mesh_ = &mesh; };
SRMesh& mesh() { return *mesh_; };
void deleteMesh() { delete mesh_; mesh_ = NULL; };
bool empty() const { return ( mesh_ != NULL ) ? false : true; };
void drawShading() {
if ( empty() ) return;
// ::glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, onespecA);
// ::glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 128);
// ::glColor3fv( grayvec );
//::glColor3f( 0, .5, 1.0 );
// GLMaterial glm;
::glEnable( GL_LIGHTING );
mtl_.bind();
::glBegin( GL_TRIANGLES );
foreach ( std::list<PMAFace*>, mesh_->active_faces(), fc )
{
Vector3d& nrm = (*fc)->normal();
::glNormal3d( nrm.x, nrm.y, nrm.z );
//glm.bindingMaterial( &(mesh_->material) );
for ( int i = 0; i < 3; ++i )
{
//foreach ( std::vector<PMAVertex*>, (*fc)->vertex, fv ) {
// PMVertex& vt = (*fc)->pmavertex(i)->pmvertex();
Point3d& p = (*fc)->pmavertex(i)->pmvertex().point();
::glVertex3d( p.x, p.y, p.z );
//cout << "\tmate " << fc->face_mate[i]->id << endl;
}
}
::glEnd();
::glDisable( GL_LIGHTING );
};
void drawWireframe() {
if ( empty() ) return;
//::glColor3fv( darkgreenvec );
::glColor3fv( blackvec );
::glLineWidth( .1f );
foreach ( std::list<PMAFace*>, mesh_->active_faces(), fc ) {
::glBegin( GL_LINE_LOOP );
for ( int i = 0; i < 3; ++i ) {
Point3d& p = (*fc)->pmavertex(i)->pmvertex().point();
::glVertex3d( p.x, p.y, p.z );
}
::glEnd();
}
};
void drawPoint() {
if ( empty() ) return;
::glPointSize( 2.5 );
::glColor3fv( bluevec );
::glBegin( GL_POINTS );
foreach ( std::list<PMAVertex*>, mesh_->active_vertices(), vt )
{
// PMVertex* p = (*vt)->vertex;
Point3d& p = (*vt)->pmvertex().point();
::glVertex3d( p.x, p.y, p.z );
}
::glEnd();
};
private:
SRMesh* mesh_;
};
#endif // _GLSRMESH_HXX