Browse Source

Doc hinzugefuegt, alte modelfiles weggemacht

Sebastian 11 years ago
parent
commit
393f1c9a65
7 changed files with 1417 additions and 456 deletions
  1. 1417
    0
      Doxyfile
  2. 0
    0
      doc/.gitignore
  3. 0
    13
      model/old/Makefile
  4. 0
    228
      model/old/load3ds.cpp
  5. 0
    37
      model/old/load3ds.h
  6. 0
    112
      model/old/model.cpp
  7. 0
    66
      model/old/model.h

+ 1417
- 0
Doxyfile
File diff suppressed because it is too large
View File


+ 0
- 0
doc/.gitignore View File


+ 0
- 13
model/old/Makefile View File

@@ -1,13 +0,0 @@
1
-CC = g++
2
-OBJOPT = -c `sdl-config --cflags` -Wall
3
-OBJECTS = load3ds.o model.o
4
-
5
-glguilib: $(OBJECTS)
6
-# 	rm glgui.a -f
7
-	ar crus glmenu.a $(OBJECTS)
8
-
9
-%.o: %.cpp %.h
10
-	$(CC) $(OBJOPT) $<
11
-
12
-clean:
13
-	rm -f $(OBJECTS)

+ 0
- 228
model/old/load3ds.cpp View File

@@ -1,228 +0,0 @@
1
-#include "load3ds.h"
2
-#include "../punkt3d.h"
3
-
4
-Load3ds::Load3ds(std::string _fname, bool _parse) {
5
-	filename = _fname;
6
-	parsed = false;
7
-	error = false;
8
-	
9
-// 	if(_parse)
10
-// 		parse();
11
-}
12
-
13
-
14
-bool Load3ds::parse(Model *m) {
15
-	if(parsed)
16
-		unload();
17
-	std::ifstream mfile(filename.c_str(), std::ios::binary);
18
-	
19
-	if(!mfile) {
20
-		return false;
21
-	}
22
-	
23
-	unsigned short ident;
24
-	unsigned int len;
25
-	
26
-	bool modelloaded = false;
27
-	bool materialloaded = false;
28
-	
29
-	Material mat;
30
-	ModelObject modobj;
31
-	m->clear();
32
-	while(!mfile.eof()) {
33
-		ident = len = 0;
34
-		mfile.read((char *)&ident, 2);
35
-		mfile.read((char *)&len, 4);
36
-
37
-		std::cout << "Chunk: 0x" << std::hex << ident << " (" << std::dec << len << ")" << std::endl;
38
-		switch(ident) {
39
-			case 0x4d4d:
40
-				// Main Chunk
41
-			break;
42
-			case 0x3d3d:
43
-				// 3D Editor Chunk
44
-			break;
45
-			case 0x4000:
46
-			{
47
-				if(modelloaded) {
48
-					modobj.calcNormales();			
49
-					m->addObject(modobj);
50
-					modobj.clear();
51
-				}
52
-				modelloaded = true;
53
-// 				std::cout << "namechunk" << std::endl;
54
-				std::string name;
55
-				char c;
56
-				do {
57
-					mfile.read(&c, 1);
58
-					name += c;
59
-				} while(c!=0);
60
-				std::cout << "Name: " << name << std::endl;
61
-				modobj.name = name;
62
-			}
63
-			break;
64
-			case 0x4100:
65
-			break;
66
-			case 0x4110:{
67
-				unsigned short panz;
68
-				Punkt3D p;
69
-				mfile.read((char*)&panz, 2);
70
-// 				std::cout << "\t\t\tVertexanz: " << panz << std::endl;
71
-				glBegin(GL_LINE_LOOP);
72
-				for(unsigned int i=0; i<panz; i++) {
73
-					mfile.read((char*)&p.x, sizeof(float));
74
-					mfile.read((char*)&p.y, sizeof(float));
75
-					mfile.read((char*)&p.z, sizeof(float));
76
-// 					p.print("Punkt");
77
-					modobj.vertex.push_back(p);
78
-					glVertex3f(p);
79
-				}
80
-				glEnd();
81
-			}
82
-			break;
83
-			case 0x4120:
84
-			{
85
-				unsigned short panz, tp;
86
-				Punkt3D p;
87
-				mfile.read((char*)&panz, 2);
88
-// 				std::cout << "\t\t\tPolygonanz: " << panz << std::endl;
89
-				for(unsigned int i=0; i<panz; i++) {
90
-					mfile.read((char*)&tp, 2);
91
-					p.x = tp;
92
-					mfile.read((char*)&tp, 2);
93
-					p.y = tp;
94
-					mfile.read((char*)&tp, 2);
95
-					p.z = tp;
96
-					mfile.read((char*)&tp, 2);
97
-					tp; // flags
98
-// 					p.print("Polygon");
99
-					modobj.polygon.push_back(p);
100
-				}
101
-			}
102
-			break;
103
-			// Komischer Chunk, ein haufen Zahlen sind sich selber zugewiesen
104
-
105
-			case 0x4130:
106
-			{
107
-				std::string name;
108
-				char c;
109
-				do {
110
-					mfile.read(&c, 1);
111
-					name += c;
112
-				} while(c!=0);
113
-				modobj.mat = m->findMaterial(name);
114
-				std::cout << "Mat Name: " << name << std::endl;
115
-				unsigned short panz, tp;
116
-				mfile.read((char*)&panz, 2);
117
-				mfile.ignore(panz*2);
118
-// 				for(unsigned int i=0; i<panz; i++) {
119
-// 					mfile.read((char*)&tp, 2);
120
-// 					std::cout << i << " ==> " << tp << std::endl;
121
-// 				}
122
-			}
123
-			break;
124
-			case 0x4140:
125
-			{
126
-				unsigned short panz;
127
-				Punkt2D p;
128
-				mfile.read((char*)&panz, 2);
129
-// 				std::cout << "\t\t\tUV-Anz: " << panz << std::endl;
130
-				for(unsigned int i=0; i<panz; i++) {
131
-					mfile.read((char*)&p.x, sizeof(float));
132
-					mfile.read((char*)&p.y, sizeof(float));
133
-					modobj.mapcoord.push_back(p);
134
-				}
135
-			}
136
-			break;
137
-			case 0xafff:
138
-				// Materialchunk
139
-			break;
140
-			case 0xa000:
141
-			{
142
-				if(materialloaded) {
143
-					m->addMaterial(mat);
144
-					mat.clear();
145
-				}
146
-				materialloaded = true;
147
-				std::string name;
148
-				char c;
149
-				do {
150
-					mfile.read(&c, 1);
151
-					name += c;
152
-				} while(c!=0);
153
-				mat.name = name;
154
-				std::cout << "Mat Name: " << name << std::endl;
155
-			}
156
-			break;
157
-			case 0xa010:
158
-			{
159
-				GLColor col;
160
-				col = readColorChunk(&mfile);
161
-				mat.ambient = col;
162
-				std::cout << col.r << ", " << col.g << ", " << col.b << std::endl;
163
-			}
164
-			break;
165
-			case 0xa020:
166
-			{
167
-				GLColor col;
168
-				col = readColorChunk(&mfile);
169
-				mat.diffuse = col;
170
-				std::cout << col.r << ", " << col.g << ", " << col.b << std::endl;
171
-			}
172
-			break;
173
-			case 0xa030:
174
-			{
175
-				GLColor col;
176
-				col = readColorChunk(&mfile);
177
-				mat.specular = col;
178
-				std::cout << col.r << ", " << col.g << ", " << col.b << std::endl;
179
-			}
180
-			break;
181
-			default:
182
-				//Switch Chunk
183
-// 				std::cout << "einfach ignorieren..." << std::endl;
184
-				mfile.ignore(len-6);
185
-// 				std::cout << "moep" << std::endl;
186
-			break;
187
-		}
188
-	}
189
-	if(materialloaded)
190
-		m->addMaterial(mat);
191
-
192
-	if(modelloaded) {
193
-		modobj.calcNormales();
194
-// 		modobj.mat = m->findMaterial(modobj.getName());
195
-		m->addObject(modobj);
196
-	}
197
-	std::cout << "Ende Load" << std::endl;
198
-	mfile.close();
199
-
200
-	return true;
201
-}
202
-
203
-GLColor Load3ds::readColorChunk(std::ifstream *file) {
204
-	GLColor col;
205
-	unsigned short id, tp;
206
-	unsigned int clen;
207
-	file->read((char*)&id, 2); // Color, warscheinlich nur bytes, wenn nich implementiere funktion
208
-	file->read((char*)&clen, 4); // len, gleiches wie oben
209
-	switch(id)  {
210
-		case 0x11:
211
-				file->read((char*)&tp, 1);
212
-				col.r = tp/255.0f;
213
-				file->read((char*)&tp, 1);
214
-				col.g = tp/255.0f;
215
-				file->read((char*)&tp, 1);
216
-				col.b = tp/255.0f;
217
-		break;
218
-		default:
219
-			file->ignore(clen-6);
220
-		break;
221
-	}
222
-	return col;
223
-}
224
-
225
-void Load3ds::unload() {
226
-	parsed = false;
227
-	error = false;
228
-}

+ 0
- 37
model/old/load3ds.h View File

@@ -1,37 +0,0 @@
1
-#ifndef __LOAD3DS_H
2
-#define __LOAD3DS_H
3
-
4
-#include <iostream>
5
-#include <fstream>
6
-#include <string>
7
-#include <vector>
8
-#include "model.h"
9
-#include "../glcolor.h"
10
-
11
-class Chunk {
12
-	private:
13
-		short ident;
14
-		char m;
15
-		char n;
16
-		
17
-	public:
18
-		Chunk() { };
19
-		void parse();
20
-};
21
-
22
-class Load3ds {
23
-	private:
24
-		std::string filename;
25
-		
26
-		bool parsed;
27
-		bool error;
28
-		
29
-		GLColor readColorChunk(std::ifstream *file);
30
-	public:
31
-		Load3ds(std::string _fname, bool parse=true);
32
-		
33
-		bool parse(Model *m);
34
-		void unload();
35
-};
36
-
37
-#endif

+ 0
- 112
model/old/model.cpp View File

@@ -1,112 +0,0 @@
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, c;
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
-		c = a.kreuzprodukt(b);
21
-		c.normalize();
22
-		normal.push_back(c);
23
-// 		c.print("Normale");
24
-	}
25
-	
26
-}
27
-
28
-void ModelObject::render() {
29
-// 	std::cout << "render " << name << " mit " << polygon.size()<< std::endl;
30
-// 	std::cout << "Vertex: " << vertex.size() << std::endl;
31
-
32
-// 	if(mat.name[0]=='g') {
33
-// 		std::cout << "Render NOT: " << name << std::endl;
34
-// 		return;
35
-// 	}
36
-// 	mat.diffuse.print(mat.name);
37
-	glBegin(GL_TRIANGLES);
38
-		for(unsigned int i=0; i<polygon.size(); i++) {
39
-
40
-			glColorGLC(mat.diffuse);
41
-			
42
-
43
-			glNormal3f(normal.at(i));
44
-				
45
-			glTexCoord2f(mapcoord.at((unsigned short)polygon[i].x));
46
-			glVertex3f(vertex.at(    (unsigned short)polygon[i].x));
47
-			
48
-
49
-			glTexCoord2f(mapcoord.at((unsigned short)polygon[i].y));
50
-			glVertex3f(vertex.at(    (unsigned short)polygon[i].y));
51
-	
52
-
53
-			glTexCoord2f(mapcoord.at((unsigned short)polygon[i].z));
54
-			glVertex3f(vertex.at(    (unsigned short)polygon[i].z));
55
-// 			vertex.at(    (unsigned short)polygon[i].x).print();
56
-		}
57
-	glEnd();
58
-}
59
-
60
-std::string ModelObject::getName() {
61
-	return name;
62
-}
63
-
64
-Material::Material() {
65
-	clear();
66
-}
67
-		
68
-void Material::clear() {
69
-	name = "";
70
-		
71
-	ambient.set(0.0f, 0.0f, 0.0f);
72
-	diffuse.set(0.0f, 0.0f, 0.0f);
73
-	specular.set(0.0f, 0.0f, 0.0f);
74
-	percent = 0.0f;
75
-}
76
-
77
-std::string Material::getName() {
78
-	return name;
79
-}
80
-
81
-
82
-Model::Model() {
83
-	
84
-}
85
-
86
-void Model::clear() {
87
-	objects.clear();
88
-}
89
-
90
-void Model::addObject(ModelObject c) {
91
-	objects.push_back(c);
92
-}
93
-
94
-void Model::render() {
95
-// 	std::cout << "Render Model " << objects.size() << std::endl;
96
-	for(unsigned int i=0; i<objects.size(); i++) 
97
-		objects[i].render();
98
-}
99
-
100
-void Model::addMaterial(Material m) {
101
-	materials.push_back(m);
102
-}
103
-
104
-Material Model::findMaterial(std::string name) {
105
-	for(unsigned int i=0; i<materials.size(); i++) {
106
-		if(name==materials[i].getName()) {
107
-			std::cout<<"found!"<<std::endl;
108
-			return materials[i];
109
-		}
110
-	}
111
-	return Material();
112
-}

+ 0
- 66
model/old/model.h View File

@@ -1,66 +0,0 @@
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 "../glcolor.h"
10
-// #include "load3ds.h"
11
-
12
-
13
-class Material {
14
-	friend class Load3ds;
15
-	friend class ModelObject;
16
-	private:
17
-		std::string name;
18
-		
19
-		GLColor ambient;
20
-		GLColor diffuse;
21
-		GLColor specular;
22
-		float percent;
23
-	public:
24
-		Material();
25
-		
26
-		void clear();
27
-		std::string getName();
28
-};
29
-
30
-
31
-class ModelObject {
32
-	friend class Load3ds;
33
-	private:
34
-		std::vector<Punkt3D> normal;
35
-		std::vector<Punkt3D> vertex;
36
-		std::vector<Punkt2D> mapcoord;
37
-		std::vector<Punkt3D> polygon;
38
-		void calcNormales();
39
-		std::string name;
40
-		
41
-		Material mat;
42
-	public:
43
-		ModelObject();
44
-		
45
-		std::string getName();
46
-		void render();
47
-		void clear();
48
-	
49
-};
50
-
51
-class Model {
52
-	private:
53
-		std::vector<ModelObject> objects;
54
-		std::vector<Material> materials;
55
-		
56
-	public:
57
-		Model();
58
-		void addObject(ModelObject c);
59
-		void addMaterial(Material m);
60
-		void clear();
61
-		void render();
62
-		
63
-		Material findMaterial(std::string name);
64
-};
65
-
66
-#endif

Loading…
Cancel
Save