Browse Source

modelobject

seba 13 years ago
parent
commit
4db04f28c7
2 changed files with 101 additions and 0 deletions
  1. 61
    0
      models/model.cpp
  2. 40
    0
      models/model.h

+ 61
- 0
models/model.cpp View File

@@ -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
+}

+ 40
- 0
models/model.h View File

@@ -0,0 +1,40 @@
1
+#ifndef __MODEL_H
2
+#define __MODEL_H
3
+
4
+#include <iostream>
5
+#include <vector>
6
+#include "../punkt2d.h"
7
+#include "../punkt3d.h"
8
+#include "../gltexture.h"
9
+// #include "load3ds.h"
10
+
11
+class ModelObject {
12
+	friend class Load3ds;
13
+	private:
14
+		std::vector<Punkt3D> normal;
15
+		std::vector<Punkt3D> vertex;
16
+		std::vector<Punkt2D> mapcoord;
17
+		std::vector<Punkt3D> polygon;
18
+		void calcNormales();
19
+		std::string name;
20
+	public:
21
+		ModelObject();
22
+		
23
+		void render();
24
+		void clear();
25
+	
26
+};
27
+
28
+class Model {
29
+	private:
30
+		std::vector<ModelObject> objects;
31
+		
32
+		
33
+	public:
34
+		Model();
35
+		void addObject(ModelObject c);
36
+		void clear();
37
+		void render();
38
+};
39
+
40
+#endif

Loading…
Cancel
Save