|
@@ -0,0 +1,61 @@
|
|
1
|
+#include "model.h"
|
|
2
|
+
|
|
3
|
+ModelObject::ModelObject() {
|
|
4
|
+
|
|
5
|
+}
|
|
6
|
+
|
|
7
|
+void ModelObject::clear() {
|
|
8
|
+ normal.clear();
|
|
9
|
+ vertex.clear();
|
|
10
|
+ mapcoord.clear();
|
|
11
|
+ polygon.clear();
|
|
12
|
+}
|
|
13
|
+
|
|
14
|
+void ModelObject::calcNormales() {
|
|
15
|
+ normal.clear();
|
|
16
|
+ Punkt3D a, b;
|
|
17
|
+ for(unsigned int i=0; i<polygon.size(); i++) {
|
|
18
|
+ a = vertex.at((unsigned short)polygon[i].x) - vertex.at((unsigned short)polygon[i].z);
|
|
19
|
+ b = vertex.at((unsigned short)polygon[i].y) - vertex.at((unsigned short)polygon[i].z);
|
|
20
|
+ normal.push_back(a.kreuzprodukt(b));
|
|
21
|
+ }
|
|
22
|
+
|
|
23
|
+}
|
|
24
|
+
|
|
25
|
+void ModelObject::render() {
|
|
26
|
+ std::cout << "render " << name << std::endl;
|
|
27
|
+ glBegin(GL_TRIANGLES);
|
|
28
|
+ for(unsigned int i=0; i<polygon.size(); i++) {
|
|
29
|
+ // glNormal3f(normal.at( (unsigned short)polygon[i].x));
|
|
30
|
+ // glTexCoord2f(mapcoord.at((unsigned short)polygon[i].x));
|
|
31
|
+ glVertex3f(vertex.at( (unsigned short)polygon[i].x));
|
|
32
|
+
|
|
33
|
+ // glNormal3f(normal.at( (unsigned short)polygon[i].y));
|
|
34
|
+ // glTexCoord2f(mapcoord.at((unsigned short)polygon[i].y));
|
|
35
|
+ glVertex3f(vertex.at( (unsigned short)polygon[i].y));
|
|
36
|
+
|
|
37
|
+ // glNormal3f(normal.at( (unsigned short)polygon[i].z));
|
|
38
|
+ // glTexCoord2f(mapcoord.at((unsigned short)polygon[i].z));
|
|
39
|
+ glVertex3f(vertex.at( (unsigned short)polygon[i].z));
|
|
40
|
+ vertex.at( (unsigned short)polygon[i].x).print();
|
|
41
|
+ }
|
|
42
|
+ glEnd();
|
|
43
|
+}
|
|
44
|
+
|
|
45
|
+Model::Model() {
|
|
46
|
+
|
|
47
|
+}
|
|
48
|
+
|
|
49
|
+void Model::clear() {
|
|
50
|
+ objects.clear();
|
|
51
|
+}
|
|
52
|
+
|
|
53
|
+void Model::addObject(ModelObject c) {
|
|
54
|
+ objects.push_back(c);
|
|
55
|
+}
|
|
56
|
+
|
|
57
|
+void Model::render() {
|
|
58
|
+ std::cout << "Render Model " << objects.size() << std::endl;
|
|
59
|
+ for(unsigned int i=0; i<objects.size(); i++)
|
|
60
|
+ objects[i].render();
|
|
61
|
+}
|