Browse Source

erweiterungen, modelklasse

seba 12 years ago
parent
commit
35bc9783ea
6 changed files with 59 additions and 6 deletions
  1. 1
    1
      models/Makefile
  2. 50
    3
      models/load3ds.cpp
  3. 2
    1
      models/load3ds.h
  4. 4
    0
      punkt2d.cpp
  5. 1
    0
      punkt2d.h
  6. 1
    1
      punkt3d.cpp

+ 1
- 1
models/Makefile View File

@@ -1,6 +1,6 @@
1 1
 CC = g++
2 2
 OBJOPT = -c `sdl-config --cflags` -Wall
3
-OBJECTS = load3ds.o
3
+OBJECTS = load3ds.o model.o
4 4
 
5 5
 glguilib: $(OBJECTS)
6 6
 # 	rm glgui.a -f

+ 50
- 3
models/load3ds.cpp View File

@@ -6,12 +6,12 @@ Load3ds::Load3ds(std::string _fname, bool _parse) {
6 6
 	parsed = false;
7 7
 	error = false;
8 8
 	
9
-	if(_parse)
10
-		parse();
9
+// 	if(_parse)
10
+// 		parse();
11 11
 }
12 12
 
13 13
 
14
-bool Load3ds::parse() {
14
+bool Load3ds::parse(Model *m) {
15 15
 	if(parsed)
16 16
 		unload();
17 17
 	std::ifstream mfile(filename.c_str(), std::ios::binary);
@@ -22,6 +22,9 @@ bool Load3ds::parse() {
22 22
 	
23 23
 	unsigned short ident;
24 24
 	unsigned int len;
25
+	bool modelloaded = false;
26
+	ModelObject modobj;
27
+	m->clear();
25 28
 	std::cout << "size: " << sizeof(int) << std::endl;
26 29
 	while(!mfile.eof()) {
27 30
 		ident = len = 0;
@@ -41,6 +44,12 @@ bool Load3ds::parse() {
41 44
 			break;
42 45
 			case 0x4000:
43 46
 			{
47
+				if(modelloaded) {
48
+					modobj.calcNormales();
49
+					m->addObject(modobj);
50
+					modobj.clear();
51
+				}
52
+				modelloaded = true;
44 53
 				std::cout << "namechunk" << std::endl;
45 54
 				std::string name;
46 55
 				char c;
@@ -49,6 +58,7 @@ bool Load3ds::parse() {
49 58
 					name += c;
50 59
 				} while(c!=0);
51 60
 				std::cout << "Name: " << name << std::endl;
61
+				modobj.name = name;
52 62
 			}
53 63
 			break;
54 64
 			case 0x4100:
@@ -63,11 +73,41 @@ bool Load3ds::parse() {
63 73
 					mfile.read((char*)&p.y, sizeof(float));
64 74
 					mfile.read((char*)&p.z, sizeof(float));
65 75
 // 					p.print("Punkt");
76
+					modobj.vertex.push_back(p);
66 77
 					glVertex3f(p);
67 78
 				}
68 79
 				glEnd();
69 80
 			}
70 81
 			break;
82
+			case 0x4120:
83
+			{
84
+				unsigned short panz, tp;
85
+				Punkt3D p;
86
+				mfile.read((char*)&panz, 2);
87
+				for(unsigned int i=0; i<panz; i++) {
88
+					mfile.read((char*)&tp, 2);
89
+					p.x = tp;
90
+					mfile.read((char*)&tp, 2);
91
+					p.y = tp;
92
+					mfile.read((char*)&tp, 2);
93
+					p.z = tp;
94
+					p.print("Polygon");
95
+					modobj.polygon.push_back(p);
96
+				}
97
+			}
98
+			break;
99
+			case 0x4140:
100
+			{
101
+				unsigned short panz;
102
+				Punkt2D p;
103
+				mfile.read((char*)&panz, 2);
104
+				for(unsigned int i=0; i<panz; i++) {
105
+					mfile.read((char*)&p.x, sizeof(float));
106
+					mfile.read((char*)&p.y, sizeof(float));
107
+					modobj.mapcoord.push_back(p);
108
+				}
109
+			}
110
+			break;
71 111
 			default:
72 112
 				//Switch Chunk
73 113
 				std::cout << "einfach ignorieren..." << std::endl;
@@ -75,6 +115,13 @@ bool Load3ds::parse() {
75 115
 			break;
76 116
 		}
77 117
 	}
118
+
119
+	if(modelloaded) {
120
+		modobj.calcNormales();
121
+		m->addObject(modobj);
122
+		modobj.clear();
123
+	}
124
+	
78 125
 	mfile.close();
79 126
 
80 127
 	return true;

+ 2
- 1
models/load3ds.h View File

@@ -5,6 +5,7 @@
5 5
 #include <fstream>
6 6
 #include <string>
7 7
 #include <vector>
8
+#include "model.h"
8 9
 
9 10
 class Chunk {
10 11
 	private:
@@ -26,7 +27,7 @@ class Load3ds {
26 27
 	public:
27 28
 		Load3ds(std::string _fname, bool parse=true);
28 29
 		
29
-		bool parse();
30
+		bool parse(Model *m);
30 31
 		void unload();
31 32
 };
32 33
 

+ 4
- 0
punkt2d.cpp View File

@@ -127,6 +127,10 @@ Punkt2D operator/(const float& _m, const Punkt2D& b) {
127 127
 	return Punkt2D(b.x/_m, b.y/_m);
128 128
 }
129 129
 
130
+void glTexCoord2f(Punkt2D p) {
131
+	glTexCoord2f(p.x, p.y);
132
+}
133
+
130 134
 // float abs(Punkt2D p) {
131 135
 // 	return p.abs();
132 136
 // }

+ 1
- 0
punkt2d.h View File

@@ -44,6 +44,7 @@ class Punkt2D {
44 44
 		
45 45
 };
46 46
 
47
+void glTexCoord2f(Punkt2D);
47 48
 // float abs(Punkt3D);
48 49
 
49 50
 #endif

+ 1
- 1
punkt3d.cpp View File

@@ -198,7 +198,7 @@ void glTranslatef(Punkt3D p) {
198 198
 	glTranslatef(p.x, p.y, p.z);
199 199
 }
200 200
 
201
-void glNormal(Punkt3D p) {
201
+void glNormal3f(Punkt3D p) {
202 202
 	glNormal3f(p.x, p.y, p.z);
203 203
 }
204 204
 

Loading…
Cancel
Save