-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjects.cpp
108 lines (86 loc) · 2.19 KB
/
Objects.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
#include "Objects.h"
basematerial::basematerial ( char color[8] )
{
for ( int i = 0; i<8; i++ )
{
HEX_color[i] = color[i];
switch (i)
{
case 1:
r+=color[i];
break;
case 2:
r+=color[i];
break;
case 3:
g+=color[i];
break;
case 4:
g+=color[i];
break;
case 5:
b+=color[i];break;
case 6: b+=color[i];
break;
case 7:
a+=color[i];
break;
case 8:
a+=color[i];
break;
}
}
}
basematerial::basematerial () {}
materials::materials ( std::vector<basematerial> _basematerials )
{
basematerials = _basematerials;
}
materials::materials() {}
vertex::vertex ( double _x, double _y, double _z )
{
x = _x;
y = _y;
z = _z;
}
vertex::vertex() {}
triangle::triangle ( int first, int second, int third, int _material )
{
vertices[0] = first;
vertices[1] = second;
vertices[2] = third;
material = _material;
}
triangle::triangle ( int first, int second, int third )
{
vertices[0] = first;
vertices[1] = second;
vertices[2] = third;
}
object::object ( std::vector<vertex> _vertices, std::vector<triangle> _triangles )
{
for ( int i = 0; i < _vertices.size(); i++ )
{
vertices.push_back ( _vertices[i] );
}
for ( int i = 0; i < _triangles.size(); i++ )
{
triangles.push_back ( _triangles[i] );
}
}
void object::draw ()
{
glPushMatrix ();
glBegin ( GL_TRIANGLES );
for (int i = 0; i < triangles.size (); i++ )
{
for (int v = 0; v < 3; v++)
{
glVertex3d ( vertices[triangles[i].vertices[v]].x,
vertices[triangles[i].vertices[v]].y,
vertices[triangles[i].vertices[v]].z );
}
}
glEnd();
glPopMatrix();
}