-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathase.cpp
executable file
·133 lines (114 loc) · 2.84 KB
/
ase.cpp
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
132
133
#include "ase.h"
#include "text.h"
#include "vector3f.h"
#include <cmath>
#ifdef _WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
CASEModel::CASEModel()
{
}
const std::vector<triangle> & CASEModel::getTriangles() const {
return m_triangles;
}
const vector3f CASEModel::get_vertex(unsigned i) const {
return m_vertices[i];
}
bool CASEModel::load(const char* filename)
{
CText t(filename);
t.Seek("*MESH_NUMVERTEX");
int n = t.GetInt();
m_vertices.resize(n);
t.Seek("*MESH_NUMFACES");
n = t.GetInt();
m_triangles.resize(n);
unsigned i;
for (i=0; i<m_vertices.size(); i++)
{
t.Seek("*MESH_VERTEX");
if (t.GetInt()== (int) i)
{
// MAX TO OPENGL CONVERSION: +x,+y,+z -> -x,+z,+y
m_vertices[i].x=-t.GetFloat();
m_vertices[i].z=t.GetFloat();
m_vertices[i].y=t.GetFloat();
}
else
return false;
}
for (i=0;i<m_triangles.size(); i++)
{
t.Seek("*MESH_FACE");
if (t.GetInt()== (int) i)
{
t.Seek("A:");
m_triangles[i].a=t.GetInt();
t.Seek("B:");
m_triangles[i].b=t.GetInt();
t.Seek("C:");
m_triangles[i].c=t.GetInt();
}
}
return true;
}
void CASEModel::render() const{
unsigned i;
for (i=0;i<m_triangles.size();i++) {
const triangle & t = m_triangles[i];
/*
vector3 normal;
normal = cross(
m_vertices[t.b] - m_vertices[t.a],
m_vertices[t.c] - m_vertices[t.a]);
normal.normalize();
glNormal3fv(normal);
*/
glPolygonMode(GL_BACK, GL_FILL);
glColor3f(0.4f, 0.4f, 0.4f);
glBegin(GL_TRIANGLES);
glVertex3fv(m_vertices[t.a]);
glVertex3fv(m_vertices[t.b]);
glVertex3fv(m_vertices[t.c]);
glPolygonMode(GL_BACK, GL_LINE);
glEnable(GL_POLYGON_OFFSET_LINE);
glPolygonOffset(-1.f, -1.f);
glColor3f(0.f, 0.f, 0.f);
glBegin(GL_TRIANGLES);
glVertex3fv(m_vertices[t.a]);
glVertex3fv(m_vertices[t.b]);
glVertex3fv(m_vertices[t.c]);
}
glEnd();
}
box3f CASEModel::get_BBox() const {
if (m_vertices.size() == 0) {
return box3f(0,0,0,0,0,0);
}
vector3f f = m_vertices[0];
box3f bBox(f.x, f.x, f.y, f.y, f.z, f.z);
for (unsigned i = 1; i < m_vertices.size(); i++) {
if (bBox.top < m_vertices[i].y) {
bBox.top = m_vertices[i].y;
}
else if (bBox.bottom > m_vertices[i].y) {
bBox.bottom = m_vertices[i].y;
}
if (bBox.right < m_vertices[i].x) {
bBox.right = m_vertices[i].x;
}
else if (bBox.left > m_vertices[i].x) {
bBox.left = m_vertices[i].x;
}
if (bBox.front < m_vertices[i].z) {
bBox.front = m_vertices[i].z;
}
else if (bBox.back > m_vertices[i].z) {
bBox.back = m_vertices[i].z;
}
}
return bBox;
}