1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2006 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: bottac@ee.ethz.ch |
---|
13 | */ |
---|
14 | |
---|
15 | #include "bsp_file.h" |
---|
16 | #include "bsp_tree_node.h" |
---|
17 | #include <fstream> |
---|
18 | #include <sys/stat.h> |
---|
19 | #include <string.h> |
---|
20 | #include "debug.h" |
---|
21 | #include "material.h" |
---|
22 | #include "vertex_array_model.h" |
---|
23 | // Necessary ? |
---|
24 | #include "base_object.h" |
---|
25 | #include "vector.h" |
---|
26 | #include "util/loading/resource_manager.h" |
---|
27 | #include "movie_player.h" |
---|
28 | |
---|
29 | #include <SDL/SDL_endian.h> |
---|
30 | #include <SDL/SDL_image.h> |
---|
31 | |
---|
32 | using namespace std; |
---|
33 | |
---|
34 | |
---|
35 | // Constructor |
---|
36 | BspFile::BspFile() |
---|
37 | {} |
---|
38 | |
---|
39 | /** |
---|
40 | * Loads a quake3 level (*.bsp) |
---|
41 | * @param name the Name of the *.bsp file |
---|
42 | */ |
---|
43 | int BspFile::read(const char* name) |
---|
44 | { |
---|
45 | int offset; |
---|
46 | int size; |
---|
47 | struct stat results; |
---|
48 | |
---|
49 | |
---|
50 | if (stat( name , &results) == 0) { |
---|
51 | PRINTF(0)("BSP FILE: Datei %s gefunden. \n", name); |
---|
52 | ifstream bspFile (name, ios::in | ios::binary); |
---|
53 | bspFile.read(this->header, 260); |
---|
54 | PRINTF(0)("BSP FILE: BSPVersion: %i. \n", ((int *)(header) )[1]); |
---|
55 | if(SDL_SwapLE32(((int *)(header) )[1]) == 46) PRINTF(0)("BSP FILE: This is the good one! :-) \n"); |
---|
56 | else PRINTF(0)("BSP FILE: Wrong BSPVersion.\n"); //!< now, we should do some error handling |
---|
57 | |
---|
58 | // Get the Nodes |
---|
59 | offset = SDL_SwapLE32(((int *)(header) )[8]); |
---|
60 | size = SDL_SwapLE32(((int *)(header))[9]); |
---|
61 | PRINTF(4)("BSP FILE: NodeSize: %i Bytes. \n", size); |
---|
62 | PRINTF(4)("BSP FILE: NumNodes: %i. \n", size / sizeof(node)); |
---|
63 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(node)); |
---|
64 | PRINTF(4)("BSP FILE: NodeOffset: %i. \n", offset); |
---|
65 | this->numNodes = size/sizeof(node); |
---|
66 | this->nodes = new node [this->numNodes]; |
---|
67 | bspFile.seekg(offset); |
---|
68 | bspFile.read((char*)this->nodes, size); |
---|
69 | |
---|
70 | // and their Planes |
---|
71 | offset = SDL_SwapLE32(((int *)(header) )[6]); |
---|
72 | size = SDL_SwapLE32(((int *)(header))[7]); |
---|
73 | PRINTF(4)("BSP FILE: PlanesSize: %i Bytes. \n", size); |
---|
74 | PRINTF(4)("BSP FILE: NumPlanes: %i. \n", size / sizeof(plane)); |
---|
75 | PRINTF(4)("BSP FILE: Remainder: %i. \n", sizeof(plane)); |
---|
76 | PRINTF(4)("BSP FILE: PlanesOffset: %i. \n", offset); |
---|
77 | this->numPlanes = size/sizeof(plane); |
---|
78 | this->planes = new plane [this->numPlanes]; |
---|
79 | bspFile.seekg(offset); |
---|
80 | bspFile.read((char*)this->planes, size); |
---|
81 | |
---|
82 | // Get the Leafs |
---|
83 | offset = SDL_SwapLE32(((int *)(header) )[10]); |
---|
84 | size = SDL_SwapLE32(((int *)(header))[11]); |
---|
85 | PRINTF(4)("BSP FILE: LeaveSize: %i Bytes. \n", size); |
---|
86 | PRINTF(4)("BSP FILE: NumLeaves: %i. \n", size / sizeof(leaf)); |
---|
87 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(leaf)); |
---|
88 | PRINTF(4)("BSP FILE: LeaveOffset: %i. \n", offset); |
---|
89 | this->numLeafs = size/sizeof(leaf); |
---|
90 | this->leaves = new leaf [this->numLeafs]; |
---|
91 | bspFile.seekg(offset); |
---|
92 | bspFile.read((char*)this->leaves, size); |
---|
93 | |
---|
94 | // Get the Models |
---|
95 | offset = SDL_SwapLE32(((int *)(header))[16]); |
---|
96 | size = SDL_SwapLE32(((int *)(header))[17]); |
---|
97 | PRINTF(4)("BSP FILE: ModelsSize: %i Bytes. \n", size); |
---|
98 | PRINTF(4)("BSP FILE: NumModels: %i. \n", size / sizeof(model)); |
---|
99 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(model)); |
---|
100 | PRINTF(4)("BSP FILE: ModelsOffset: %i. \n", offset); |
---|
101 | this->numBspModels = size/sizeof(model); |
---|
102 | this->bspModels = new model [this->numBspModels]; |
---|
103 | bspFile.seekg(offset); |
---|
104 | bspFile.read((char*)this->bspModels, size); |
---|
105 | |
---|
106 | // Get the leafFaces |
---|
107 | offset = SDL_SwapLE32(((int *)(header))[12]); |
---|
108 | size = SDL_SwapLE32(((int *)(header))[13]); |
---|
109 | PRINTF(4)("BSP FILE: leafFacesSize: %i Bytes. \n", size); |
---|
110 | PRINTF(4)("BSP FILE: NumleafFaces: %i. \n", size / 4); |
---|
111 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4); |
---|
112 | PRINTF(4)("BSP FILE: leafFacesOffset: %i. \n", offset); |
---|
113 | this->numLeafFaces = size/4; |
---|
114 | this->leafFaces = new char [size]; |
---|
115 | bspFile.seekg(offset); |
---|
116 | bspFile.read(this->leafFaces, size); |
---|
117 | |
---|
118 | // Get the leafBrushes |
---|
119 | offset = SDL_SwapLE32(((int *)(header))[14]); |
---|
120 | size = SDL_SwapLE32(((int *)(header))[15]); |
---|
121 | PRINTF(4)("BSP FILE: leafBrushesSize: %i Bytes. \n", size); |
---|
122 | PRINTF(4)("BSP FILE: NumleafBrushes: %i. \n", size / 4); |
---|
123 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4); |
---|
124 | PRINTF(4)("BSP FILE: leafBrushesOffset: %i. \n", offset); |
---|
125 | this->numLeafBrushes = size/4; |
---|
126 | this->leafBrushes = new char [size]; |
---|
127 | bspFile.seekg(offset); |
---|
128 | bspFile.read(this->leafBrushes, size); |
---|
129 | |
---|
130 | // Get the brushes |
---|
131 | offset = SDL_SwapLE32(((int *)(header))[18]); |
---|
132 | size = SDL_SwapLE32(((int *)(header))[19]); |
---|
133 | PRINTF(4)("BSP FILE: BrushesSize: %i Bytes. \n", size); |
---|
134 | PRINTF(4)("BSP FILE: NumBrushes: %i. \n", size / sizeof(brush)); |
---|
135 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(brush)); |
---|
136 | PRINTF(4)("BSP FILE: BrushesOffset: %i. \n", offset); |
---|
137 | this->brushes = new brush [size/sizeof(brush)]; |
---|
138 | bspFile.seekg(offset); |
---|
139 | bspFile.read((char*)this->brushes, size); |
---|
140 | |
---|
141 | // Get the brushSides |
---|
142 | offset = SDL_SwapLE32(((int *)(header))[20]); |
---|
143 | size = SDL_SwapLE32(((int *)(header))[21]); |
---|
144 | PRINTF(4)("BSP FILE: BrushSidesSize: %i Bytes. \n", size); |
---|
145 | PRINTF(4)("BSP FILE: NumBrushSides: %i. \n", size / 8); |
---|
146 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 8); |
---|
147 | PRINTF(4)("BSP FILE: BrushSidesOffset: %i. \n", offset); |
---|
148 | this->numBrushSides = size/sizeof(brushside); |
---|
149 | this->brushSides = new brushside [this->numBrushSides]; |
---|
150 | bspFile.seekg(offset); |
---|
151 | bspFile.read((char*)this->brushSides, size); |
---|
152 | |
---|
153 | // Get the Vertice |
---|
154 | offset = SDL_SwapLE32(((int *)(header))[22]); |
---|
155 | size = SDL_SwapLE32(((int *)(header))[23]); |
---|
156 | PRINTF(4)("BSP FILE: VerticeSize: %i Bytes. \n", size); |
---|
157 | PRINTF(4)("BSP FILE: NumVertice: %i. \n", size / 44); |
---|
158 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 44); |
---|
159 | PRINTF(4)("BSP FILE: VerticeOffset: %i. \n", offset); |
---|
160 | this->numVertex = size/44; |
---|
161 | this->vertice = new char [size]; |
---|
162 | bspFile.seekg(offset); |
---|
163 | bspFile.read(this->vertice, size); |
---|
164 | |
---|
165 | // Get the MeshVerts |
---|
166 | offset = SDL_SwapLE32(((int *)(header))[24]); |
---|
167 | size = SDL_SwapLE32(((int *)(header))[25]); |
---|
168 | PRINTF(4)("BSP FILE: MeshVertsSize: %i Bytes. \n", size); |
---|
169 | PRINTF(4)("BSP FILE: NumMeshVerts: %i. \n", size / sizeof(meshvert)); |
---|
170 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(meshvert)); |
---|
171 | PRINTF(4)("BSP FILE: MeshVertsOffset: %i. \n", offset); |
---|
172 | this->meshverts = new meshvert [size / sizeof(meshvert)]; |
---|
173 | bspFile.seekg(offset); |
---|
174 | bspFile.read((char*)this->meshverts, size); |
---|
175 | |
---|
176 | // Get the Faces |
---|
177 | offset = SDL_SwapLE32(((int *)(header))[28]); |
---|
178 | size = SDL_SwapLE32(((int *)(header))[29]); |
---|
179 | PRINTF(4)("BSP FILE: FacesSize: %i Bytes. \n", size); |
---|
180 | PRINTF(4)("BSP FILE: NumFaces: %i. \n", size / sizeof(face)); |
---|
181 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(face)); |
---|
182 | PRINTF(4)("BSP FILE: FacesOffset: %i. \n", offset); |
---|
183 | this->numFaces = size/sizeof(face); |
---|
184 | this->faces = new face [this->numFaces]; |
---|
185 | bspFile.seekg(offset); |
---|
186 | bspFile.read((char*)this->faces, size); |
---|
187 | |
---|
188 | //Get the lightmaps |
---|
189 | offset = SDL_SwapLE32(((int *)(header))[30]); |
---|
190 | size = SDL_SwapLE32(((int *)(header))[31]); |
---|
191 | this->numLightMaps = size/ sizeof(lightmap); |
---|
192 | this->lightMaps = new lightmap [this->numLightMaps]; |
---|
193 | bspFile.seekg(offset); |
---|
194 | bspFile.read((char*)this->lightMaps, size); |
---|
195 | |
---|
196 | |
---|
197 | // Get the Visdata |
---|
198 | offset = SDL_SwapLE32(((int *)(header))[34]); |
---|
199 | size = SDL_SwapLE32(((int *)(header))[35]); |
---|
200 | |
---|
201 | this->visData = new char [size]; |
---|
202 | bspFile.seekg(offset); |
---|
203 | bspFile.read(this->visData, size); |
---|
204 | |
---|
205 | PRINTF(4)("BSP FILE: VisDataSize: %i Bytes. \n", size); |
---|
206 | PRINTF(4)("BSP FILE: NumVisData: %i. \n", size /1 - 8); |
---|
207 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 1); |
---|
208 | PRINTF(4)("BSP FILE: VisDataOffset: %i. \n", offset); |
---|
209 | |
---|
210 | // Get the Textures |
---|
211 | offset = SDL_SwapLE32(((int *)(header))[4]); |
---|
212 | size = SDL_SwapLE32(((int *)(header))[5]); |
---|
213 | |
---|
214 | this->textures= new char [size]; |
---|
215 | bspFile.seekg(offset); |
---|
216 | bspFile.read(this->textures, size); |
---|
217 | |
---|
218 | PRINTF(4)("BSP FILE: TextureSize: %i Bytes. \n", size); |
---|
219 | PRINTF(4)("BSP FILE: NumTextures: %i. \n", size /72); |
---|
220 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 72); |
---|
221 | PRINTF(4)("BSP FILE: TextureOffset: %i. \n", offset); |
---|
222 | this->numTextures = size/72; |
---|
223 | |
---|
224 | bspFile.close(); |
---|
225 | |
---|
226 | for(int i = 0 ; i < this->numTextures; i++) |
---|
227 | PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]); |
---|
228 | this->load_textures(); |
---|
229 | |
---|
230 | // Load the lightMaps |
---|
231 | this->glLightMapTextures = new GLuint[this->numLightMaps]; |
---|
232 | for(int i = 0; i < this->numLightMaps; i++) |
---|
233 | this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]); |
---|
234 | |
---|
235 | //Create white texture for if no lightmap specified |
---|
236 | glGenTextures(1, &this->whiteLightMap); |
---|
237 | glBindTexture(GL_TEXTURE_2D, this->whiteLightMap); |
---|
238 | //Create texture |
---|
239 | this->whiteTexture[0]=255; |
---|
240 | this->whiteTexture[1]=255; |
---|
241 | this->whiteTexture[2]=255; |
---|
242 | |
---|
243 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
---|
244 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
---|
245 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
---|
246 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
---|
247 | |
---|
248 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2); |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | /* control the mipmap levels */ |
---|
253 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); |
---|
254 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); |
---|
255 | |
---|
256 | /* build the Texture OpenGL V >= 1.1 */ |
---|
257 | glTexImage2D(GL_TEXTURE_2D, |
---|
258 | 0, |
---|
259 | GL_RGBA8, |
---|
260 | 1, |
---|
261 | 1, |
---|
262 | 0, |
---|
263 | GL_RGB, |
---|
264 | GL_UNSIGNED_BYTE, |
---|
265 | (const GLvoid *)&(this->whiteTexture)); |
---|
266 | |
---|
267 | gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, 1, 1, |
---|
268 | GL_RGB, GL_UNSIGNED_BYTE,(const GLvoid *) &(this->whiteTexture)); |
---|
269 | |
---|
270 | |
---|
271 | |
---|
272 | // Get the number of patches |
---|
273 | this->numPatches = 0; |
---|
274 | this->patchOffset = 0; |
---|
275 | |
---|
276 | for( int i = 0; i < this->numFaces; i++) { |
---|
277 | face& cFace = ((face *)(this->faces))[i]; |
---|
278 | if (SDL_SwapLE32(cFace.type) == 2) |
---|
279 | this->numPatches += (SDL_SwapLE32(cFace.size[0]) -1 ) / 2 * (SDL_SwapLE32(cFace.size[1]) -1) / 2; |
---|
280 | } |
---|
281 | |
---|
282 | // Allocate Memory |
---|
283 | this->patchVertice = new char[8*8*44*(this->numPatches+10)]; |
---|
284 | this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)]; |
---|
285 | this->patchRowIndexes = new int*[7*4*this->numPatches]; |
---|
286 | this->patchTrianglesPerRow = new char[7*4*this->numPatches]; |
---|
287 | this->VertexArrayModels = new VertexArrayModel*[this->numPatches]; |
---|
288 | |
---|
289 | PRINTF(0)("BSP FILE:NumberOfPatches: %i . \n", numPatches); |
---|
290 | // Do tesselation for all Faces of type 2 |
---|
291 | for( int i = 0; i < this->numFaces; i++) { |
---|
292 | if (SDL_SwapLE32((this->faces)[i].type) == 2) |
---|
293 | this->tesselate(i); |
---|
294 | } |
---|
295 | |
---|
296 | PRINTF(0)("BSP FILE:PatchOffset: %i . \n", this->patchOffset); |
---|
297 | |
---|
298 | return 1; |
---|
299 | } else { |
---|
300 | PRINTF(0)("BSP FILE: Datei nicht gefunden. \n"); |
---|
301 | return -1; |
---|
302 | } |
---|
303 | |
---|
304 | } |
---|
305 | |
---|
306 | void BspFile::build_tree() |
---|
307 | { |
---|
308 | |
---|
309 | PRINTF(0)("BSP FILE:\n"); |
---|
310 | PRINTF(0)("BSP FILE: Building Tree...\n"); |
---|
311 | root = this->build_tree_rec(0); |
---|
312 | PRINTF(0)("BSP FILE: ...done. \n"); |
---|
313 | PRINTF(0)("BSP FILE: \n"); |
---|
314 | PRINTF(0)("BSP FILE: Node #0: \n"); |
---|
315 | PRINTF(0)("BSP FILE: x: %f \n",root->plane.x); |
---|
316 | PRINTF(0)("BSP FILE: y: %f\n",root->plane.y); |
---|
317 | PRINTF(0)("BSP FILE: z: %f\n",root->plane.z); |
---|
318 | } |
---|
319 | |
---|
320 | /** |
---|
321 | * Called by BspFile::build_tree() only. |
---|
322 | */ |
---|
323 | BspTreeNode* BspFile::build_tree_rec(int i) |
---|
324 | { |
---|
325 | // PRINTF(0)("BSP FILE: Node #%i\n", i); |
---|
326 | BspTreeNode* thisNode = new BspTreeNode(); |
---|
327 | int left =(((node *) nodes) [i]).left; |
---|
328 | int right =(((node *) nodes) [i]).right; |
---|
329 | int planeIndex = (((node *) nodes) [i]).plane; |
---|
330 | float x1 =(((plane *) this->planes) [planeIndex]).x; |
---|
331 | float y1 =(((plane *) this->planes) [planeIndex]).y; |
---|
332 | float z1 =(((plane *) this->planes) [planeIndex]).z; |
---|
333 | thisNode->leafIndex = 0; |
---|
334 | thisNode->d = (((plane *) this->planes) [planeIndex]).d; |
---|
335 | |
---|
336 | thisNode->plane = Vector(x1,y1,z1); |
---|
337 | thisNode->isLeaf = false; |
---|
338 | |
---|
339 | if(left >= 0) { |
---|
340 | thisNode->left = this->build_tree_rec(left); |
---|
341 | } else { |
---|
342 | //BspTreeLeaf tmp = BspTreeLeaf(); |
---|
343 | //tmp.isLeaf = true; |
---|
344 | //tmp.leafIndex = -left -1; |
---|
345 | //thisNode->left = (BspTreeNode*) (&tmp); |
---|
346 | thisNode->left = new BspTreeNode(); |
---|
347 | thisNode->left->isLeaf = true; |
---|
348 | thisNode->left->leafIndex = - (left +1); |
---|
349 | //PRINTF(0)("BSP FILE: LeafIndex: %i\n",-left); |
---|
350 | } // assign leav |
---|
351 | if(right >= 0) { |
---|
352 | thisNode->right = this->build_tree_rec(right); |
---|
353 | } else { |
---|
354 | //BspTreeLeaf tmp = BspTreeLeaf(); |
---|
355 | //tmp.isLeaf = true; |
---|
356 | //tmp.leafIndex = -right -1; |
---|
357 | //thisNode->right = (BspTreeNode*) (&tmp); |
---|
358 | thisNode->right = new BspTreeNode(); |
---|
359 | thisNode->right->isLeaf = true; |
---|
360 | thisNode->right->leafIndex = -(right +1); |
---|
361 | //PRINTF(0)("BSP FILE: LeafIndex: %i\n",-right); |
---|
362 | } // assign leaf |
---|
363 | return thisNode; |
---|
364 | } |
---|
365 | |
---|
366 | /** |
---|
367 | * returns the root node of the bsp-tree |
---|
368 | */ |
---|
369 | BspTreeNode* BspFile::get_root() |
---|
370 | { |
---|
371 | return root; |
---|
372 | } |
---|
373 | |
---|
374 | void BspFile::load_textures() |
---|
375 | { |
---|
376 | ::std::string absFileName; |
---|
377 | char fileName [228]; |
---|
378 | char ext [100]; |
---|
379 | struct stat results; |
---|
380 | |
---|
381 | |
---|
382 | this->Materials = new AMat[this->numTextures]; |
---|
383 | for(int i = 0 ; i < this->numTextures; i++) { |
---|
384 | PRINTF(0)("BSP FILE: Texture : %s. \n", &this->textures[8+ 72*i]); |
---|
385 | |
---|
386 | |
---|
387 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
388 | if(strlen(fileName) == 0) |
---|
389 | { |
---|
390 | // Default Material |
---|
391 | this->Materials[i].mat = new Material(); |
---|
392 | this->Materials[i].mat->setDiffuse(0.1,0.1,1.0); |
---|
393 | this->Materials[i].mat->setAmbient(0.1,0.1,1.0 ); |
---|
394 | this->Materials[i].mat->setSpecular(0.4,0.4,1.0); |
---|
395 | //this->Materials[i]->setShininess(100.0); |
---|
396 | // this->Materials[i].mat->setTransparency(1.0); |
---|
397 | this->Materials[i].mat->setDiffuseMap("pictures/ground.tga"); |
---|
398 | this->Materials[i].mat->setAmbientMap("pictures/ground.tga"); |
---|
399 | this->Materials[i].mat->setSpecularMap("pictures/ground.tga"); |
---|
400 | this->Materials[i].alpha = false; |
---|
401 | this->Materials[i].animated = false; |
---|
402 | continue; |
---|
403 | } |
---|
404 | |
---|
405 | // Check for mov |
---|
406 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
407 | strcpy(ext, ".mov"); |
---|
408 | strncat (fileName, ext, strlen(fileName)); |
---|
409 | |
---|
410 | absFileName = ResourceManager::getFullName(fileName); |
---|
411 | |
---|
412 | if(ResourceManager::isFile(absFileName)) { |
---|
413 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
414 | this->Materials[i] = this->loadAVI(fileName); |
---|
415 | continue; |
---|
416 | } |
---|
417 | |
---|
418 | // Check for avi |
---|
419 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
420 | strcpy(ext, ".avi"); |
---|
421 | strncat (fileName, ext, strlen(fileName)); |
---|
422 | |
---|
423 | absFileName = ResourceManager::getFullName(fileName); |
---|
424 | |
---|
425 | if(ResourceManager::isFile(absFileName)) { |
---|
426 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
427 | this->Materials[i] = this->loadAVI(fileName); |
---|
428 | continue; |
---|
429 | } |
---|
430 | |
---|
431 | // Check for mpg |
---|
432 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
433 | strcpy(ext, ".mpg"); |
---|
434 | strncat (fileName, ext, strlen(fileName)); |
---|
435 | |
---|
436 | absFileName = ResourceManager::getFullName(fileName); |
---|
437 | |
---|
438 | if(ResourceManager::isFile(absFileName)) { |
---|
439 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
440 | this->Materials[i] = this->loadAVI(fileName); |
---|
441 | continue; |
---|
442 | } |
---|
443 | |
---|
444 | // Check for tga |
---|
445 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
446 | strcpy(ext, ".tga"); |
---|
447 | strncat (fileName, ext, strlen(fileName)); |
---|
448 | |
---|
449 | absFileName = ResourceManager::getFullName(fileName); |
---|
450 | |
---|
451 | if(ResourceManager::isFile(absFileName)) { |
---|
452 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
453 | this->Materials[i] = this->loadMat(fileName); |
---|
454 | continue; |
---|
455 | } |
---|
456 | // Check for TGA |
---|
457 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
458 | strcpy(ext, ".TGA"); |
---|
459 | strncat (fileName, ext, strlen(fileName)); |
---|
460 | absFileName = ResourceManager::getFullName(fileName); |
---|
461 | |
---|
462 | if(ResourceManager::isFile(absFileName)/*stat( absFileName.c_str() , &results) == 0*/) { |
---|
463 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
464 | this->Materials[i] = this->loadMat(fileName); |
---|
465 | continue; |
---|
466 | } |
---|
467 | // Check for jpg |
---|
468 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
469 | strcpy(ext, ".jpg"); |
---|
470 | strncat (fileName, ext, strlen(fileName)); |
---|
471 | absFileName = ResourceManager::getFullName(fileName); |
---|
472 | if(ResourceManager::isFile(absFileName)) { |
---|
473 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
474 | this->Materials[i] =this->loadMat(fileName); |
---|
475 | continue; |
---|
476 | } |
---|
477 | |
---|
478 | |
---|
479 | // Check for JPG |
---|
480 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
481 | strcpy(ext, ".JPG"); |
---|
482 | strncat (fileName, ext, strlen(fileName)); |
---|
483 | absFileName = ResourceManager::getFullName(fileName); |
---|
484 | if(ResourceManager::isFile(absFileName)) { |
---|
485 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
486 | this->Materials[i] =this->loadMat(fileName); |
---|
487 | continue; |
---|
488 | } |
---|
489 | |
---|
490 | |
---|
491 | |
---|
492 | // Check for bmp |
---|
493 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
494 | strcpy(ext, ".bmp"); |
---|
495 | strncat (fileName, ext, strlen(fileName)); |
---|
496 | absFileName = ResourceManager::getFullName(fileName); |
---|
497 | |
---|
498 | if(ResourceManager::isFile(absFileName)) { |
---|
499 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
500 | this->Materials[i] =this->loadMat(fileName); |
---|
501 | continue; |
---|
502 | } |
---|
503 | |
---|
504 | // Check for BMP |
---|
505 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
506 | strcpy(ext, ".BMP"); |
---|
507 | strncat (fileName, ext, strlen(fileName)); |
---|
508 | absFileName = ResourceManager::getFullName(fileName); |
---|
509 | |
---|
510 | if(ResourceManager::isFile(absFileName)) { |
---|
511 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
512 | this->Materials[i] = this->loadMat(fileName); |
---|
513 | continue; |
---|
514 | } |
---|
515 | |
---|
516 | |
---|
517 | // Default Material |
---|
518 | this->Materials[i].mat = new Material(); |
---|
519 | this->Materials[i].mat->setDiffuse(0.1,0.1,0.1); |
---|
520 | this->Materials[i].mat->setAmbient(0.1,0.1,0.1 ); |
---|
521 | this->Materials[i].mat->setSpecular(0.4,0.4,0.4); |
---|
522 | //this->Materials[i]->setShininess(100.0); |
---|
523 | //this->Materials[i].mat->setTransparency(1.0); |
---|
524 | this->Materials[i].mat->setDiffuseMap("pictures/error_texture.png"); |
---|
525 | this->Materials[i].mat->setAmbientMap("pictures/error_texture.png"); |
---|
526 | this->Materials[i].mat->setSpecularMap("pictures/error_texture.png"); |
---|
527 | this->Materials[i].alpha = true; |
---|
528 | this->Materials[i].animated = false; |
---|
529 | |
---|
530 | } |
---|
531 | } |
---|
532 | |
---|
533 | |
---|
534 | AMat BspFile::loadMat(char* mat) |
---|
535 | { |
---|
536 | AMat tmpAMat; |
---|
537 | this->testSurf = NULL; |
---|
538 | |
---|
539 | this->testSurf = IMG_Load(ResourceManager::getFullName(mat).c_str()); |
---|
540 | if(this->testSurf != NULL) { |
---|
541 | if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; |
---|
542 | else tmpAMat.alpha = false; |
---|
543 | } else tmpAMat.alpha = false; |
---|
544 | |
---|
545 | Material* tmp = new Material(); |
---|
546 | tmp->setDiffuse(1.0,1.0,1.0); |
---|
547 | tmp->setAmbient(1.0,1.0,1.0 ); |
---|
548 | tmp->setSpecular(1.0,1.0,1.0); |
---|
549 | // tmp->setShininess(.5); |
---|
550 | // tmp->setTransparency(0.0); |
---|
551 | |
---|
552 | tmp->setDiffuseMap(mat); |
---|
553 | |
---|
554 | tmpAMat.mat = tmp; |
---|
555 | tmpAMat.animated = false; |
---|
556 | return tmpAMat; |
---|
557 | } |
---|
558 | |
---|
559 | AMat BspFile::loadAVI(char* mat) |
---|
560 | { |
---|
561 | AMat tmpAMat; |
---|
562 | |
---|
563 | |
---|
564 | MoviePlayer * testMC = new MoviePlayer(mat); |
---|
565 | testMC->start(0); |
---|
566 | |
---|
567 | //Material* tmp = new Material(); |
---|
568 | // tmp->setDiffuse(1.0,1.0,1.0); |
---|
569 | //tmp->setAmbient(1.0,1.0,1.0 ); |
---|
570 | //tmp->setSpecular(1.0,1.0,1.0); |
---|
571 | // tmp->setShininess(.5);tmpAMat |
---|
572 | // tmp->setTransparency(0.0); |
---|
573 | |
---|
574 | //tmp->setDiffuseMap(mat); |
---|
575 | |
---|
576 | tmpAMat.aviMat = testMC; |
---|
577 | tmpAMat.animated = true; |
---|
578 | tmpAMat.alpha = true; |
---|
579 | return tmpAMat; |
---|
580 | } |
---|
581 | |
---|
582 | unsigned int BspFile::loadLightMapToGL(lightmap& lightMapTexture) |
---|
583 | { |
---|
584 | int errorCode = 0; //!< the error code for the texture loading functions |
---|
585 | unsigned int lightMap; //!< the OpenGL texture handle |
---|
586 | int mipmapLevel = 0; //!< the maximum mipmap level for this texture |
---|
587 | int mipmapWidth = 0; //!< the width of the mipmap |
---|
588 | int mipmapHight = 0; //!< the height of the mipmap |
---|
589 | |
---|
590 | float sc, scale, temp; |
---|
591 | for(int i = 0; i < 128*128*3 ; i++) |
---|
592 | { |
---|
593 | sc = ((unsigned char *)(&lightMapTexture))[i]; |
---|
594 | sc *= 1/255.0; |
---|
595 | scale = 1.0; |
---|
596 | if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp; |
---|
597 | scale*=255.0; |
---|
598 | sc*=scale; |
---|
599 | if(sc <= 180) |
---|
600 | ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc + 75; |
---|
601 | else |
---|
602 | ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc; |
---|
603 | } |
---|
604 | |
---|
605 | glGenTextures(1, &lightMap); |
---|
606 | glBindTexture(GL_TEXTURE_2D, lightMap); |
---|
607 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
---|
608 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
---|
609 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
---|
610 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
---|
611 | |
---|
612 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2); |
---|
613 | |
---|
614 | |
---|
615 | /* control the mipmap levels */ |
---|
616 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); |
---|
617 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); |
---|
618 | |
---|
619 | /* build the Texture OpenGL V >= 1.1 */ |
---|
620 | glTexImage2D(GL_TEXTURE_2D, |
---|
621 | 0, |
---|
622 | GL_RGBA8, |
---|
623 | 128, |
---|
624 | 128, |
---|
625 | 0, |
---|
626 | GL_RGB, |
---|
627 | GL_UNSIGNED_BYTE, |
---|
628 | (const GLvoid *)&lightMapTexture); |
---|
629 | |
---|
630 | |
---|
631 | // build the MipMaps automaticaly |
---|
632 | errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D, |
---|
633 | GL_RGBA8, |
---|
634 | 128, |
---|
635 | 128, |
---|
636 | GL_RGB, |
---|
637 | GL_UNSIGNED_BYTE, |
---|
638 | (const GLvoid *)&lightMapTexture |
---|
639 | ); |
---|
640 | |
---|
641 | |
---|
642 | |
---|
643 | |
---|
644 | return lightMap; |
---|
645 | |
---|
646 | } |
---|
647 | |
---|
648 | /** |
---|
649 | * Generates a vertex-array, a indice-array and a texture-coordinates-array for iface. |
---|
650 | * @param iface integer index of face |
---|
651 | * @todo cleanup this function, let the user choose the level of tesselation |
---|
652 | */ |
---|
653 | |
---|
654 | |
---|
655 | void BspFile::tesselate(int iface) |
---|
656 | { |
---|
657 | face* Face = &((this->faces)[iface]); |
---|
658 | BspVertex * BspVrtx = (BspVertex*)this->vertice; |
---|
659 | int level = 7; |
---|
660 | int level1 = 8; |
---|
661 | int size0 = (Face->size[0]); |
---|
662 | int size1 = (Face->size[1]); |
---|
663 | // For each patch... |
---|
664 | for(int i = 0; i < ( size0 - 1) ; i+=2) { |
---|
665 | for(int j = 0; j < ( size1 -1) ; j+=2) { |
---|
666 | |
---|
667 | |
---|
668 | // Make a patch... |
---|
669 | // Get controls[9]; |
---|
670 | BspVec controls[9]; |
---|
671 | BspVec controlsTmp[9]; |
---|
672 | BspVertex VControls[9]; |
---|
673 | for(int k = 0; k < 3; k++) { |
---|
674 | for(int l = 0; l < 3; l++) { |
---|
675 | controls[k +3*l]. position[0] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[0]); |
---|
676 | controls[k +3*l]. position[1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]); |
---|
677 | controls[k +3*l]. position[2] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/ |
---|
678 | |
---|
679 | controlsTmp[2-k +6-3*l]. position[0] = ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]); |
---|
680 | controlsTmp[2-k +6-3*l]. position[1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]); |
---|
681 | controlsTmp[2-k +6-3*l]. position[2] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/ |
---|
682 | |
---|
683 | VControls[k +3*l]. position[0] = ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]); |
---|
684 | VControls[k +3*l]. position[1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]); |
---|
685 | VControls[k +3*l]. position[2] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); |
---|
686 | |
---|
687 | VControls[k +3*l]. normal[0] = ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].normal[0]); |
---|
688 | VControls[k +3*l]. normal[1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].normal[1]); |
---|
689 | VControls[k +3*l]. normal[2] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].normal[2]); |
---|
690 | |
---|
691 | VControls[k +3*l]. texcoord[0][0]= ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[0][0]); |
---|
692 | VControls[k +3*l]. texcoord[0][1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[0][1]); |
---|
693 | VControls[k +3*l]. texcoord[1][0] = ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[1][0]); |
---|
694 | VControls[k +3*l]. texcoord[1][1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[1][1]); |
---|
695 | |
---|
696 | |
---|
697 | } |
---|
698 | } |
---|
699 | //*********************************************************************************************************************** |
---|
700 | // Compute the vertice |
---|
701 | //*********************************************************************************************************************** |
---|
702 | float px, py; |
---|
703 | BspVertex temp[3]; |
---|
704 | BspVertex* Vertice = &(((BspVertex*)this->patchVertice)[level1*level1*this->patchOffset]); |
---|
705 | |
---|
706 | for(int v=0; v<=level; ++v) { |
---|
707 | px=(float)v/level; |
---|
708 | |
---|
709 | Vertice[v].position[0]=VControls[0].position[0]*((1.0f-px)*(1.0f-px))+VControls[3].position[0]*((1.0f-px)*px*2)+VControls[6].position[0]*(px*px); |
---|
710 | Vertice[v].position[1]=VControls[0].position[1]*((1.0f-px)*(1.0f-px))+VControls[3].position[1]*((1.0f-px)*px*2)+VControls[6].position[1]*(px*px); |
---|
711 | Vertice[v].position[2]=VControls[0].position[2]*((1.0f-px)*(1.0f-px))+VControls[3].position[2]*((1.0f-px)*px*2)+VControls[6].position[2]*(px*px); |
---|
712 | |
---|
713 | Vertice[v].normal[0]=VControls[0].normal[0]*((1.0f-px)*(1.0f-px))+VControls[3].normal[0]*((1.0f-px)*px*2)+VControls[6].normal[0]*(px*px); |
---|
714 | Vertice[v].normal[1]=VControls[0].normal[1]*((1.0f-px)*(1.0f-px))+VControls[3].normal[1]*((1.0f-px)*px*2)+VControls[6].normal[1]*(px*px); |
---|
715 | Vertice[v].normal[2]=VControls[0].normal[2]*((1.0f-px)*(1.0f-px))+VControls[3].normal[2]*((1.0f-px)*px*2)+VControls[6].normal[2]*(px*px); |
---|
716 | |
---|
717 | Vertice[v].texcoord[0][0]=VControls[0].texcoord[0][0]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[0][0]*((1.0f-px)*px*2)+VControls[6].texcoord[0][0]*(px*px); |
---|
718 | Vertice[v].texcoord[0][1]=VControls[0].texcoord[0][1]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[0][1]*((1.0f-px)*px*2)+VControls[6].texcoord[0][1]*(px*px); |
---|
719 | Vertice[v].texcoord[1][0]=VControls[0].texcoord[1][0]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[1][0]*((1.0f-px)*px*2)+VControls[6].texcoord[1][0]*(px*px); |
---|
720 | Vertice[v].texcoord[1][1]=VControls[0].texcoord[1][1]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[1][1]*((1.0f-px)*px*2)+VControls[6].texcoord[1][1]*(px*px); |
---|
721 | |
---|
722 | } |
---|
723 | |
---|
724 | |
---|
725 | for(int u=1; u<=level; ++u) { |
---|
726 | py=(float)u/level; |
---|
727 | |
---|
728 | // temp[0]=controlPoints[0]*((1.0f-py)*(1.0f-py))+ controlPoints[1]*((1.0f-py)*py*2)+ controlPoints[2]*(py*py); |
---|
729 | temp[0].position[0]=VControls[0].position[0]*((1.0f-py)*(1.0f-py))+VControls[1].position[0]*((1.0f-py)*py*2)+VControls[2].position[0]*(py*py); |
---|
730 | temp[0].position[1]=VControls[0].position[1]*((1.0f-py)*(1.0f-py))+VControls[1].position[1]*((1.0f-py)*py*2)+VControls[2].position[1]*(py*py); |
---|
731 | temp[0].position[2]=VControls[0].position[2]*((1.0f-py)*(1.0f-py))+VControls[1].position[2]*((1.0f-py)*py*2)+VControls[2].position[2]*(py*py); |
---|
732 | |
---|
733 | temp[0].normal[0]=VControls[0].normal[0]*((1.0f-py)*(1.0f-py))+VControls[1].normal[0]*((1.0f-py)*py*2)+VControls[2].normal[0]*(py*py); |
---|
734 | temp[0].normal[1]=VControls[0].normal[1]*((1.0f-py)*(1.0f-py))+VControls[1].normal[1]*((1.0f-py)*py*2)+VControls[2].normal[1]*(py*py); |
---|
735 | temp[0].normal[2]=VControls[0].normal[2]*((1.0f-py)*(1.0f-py))+VControls[1].normal[2]*((1.0f-py)*py*2)+VControls[2].normal[2]*(py*py); |
---|
736 | |
---|
737 | temp[0].texcoord[0][0]=VControls[0].texcoord[0][0]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[0][0]*((1.0f-py)*py*2)+VControls[2].texcoord[0][0]*(py*py); |
---|
738 | temp[0].texcoord[0][1]=VControls[0].texcoord[0][1]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[0][1]*((1.0f-py)*py*2)+VControls[2].texcoord[0][1]*(py*py); |
---|
739 | temp[0].texcoord[1][0]=VControls[0].texcoord[1][0]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[1][0]*((1.0f-py)*py*2)+VControls[2].texcoord[1][0]*(py*py); |
---|
740 | temp[0].texcoord[1][1]=VControls[0].texcoord[1][1]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[1][1]*((1.0f-py)*py*2)+VControls[2].texcoord[1][1]*(py*py); |
---|
741 | |
---|
742 | |
---|
743 | |
---|
744 | // temp[1]=controlPoints[3]*((1.0f-py)*(1.0f-py))+ controlPoints[4]*((1.0f-py)*py*2)+ controlPoints[5]*(py*py); |
---|
745 | temp[1].position[0]=VControls[3].position[0]*((1.0f-py)*(1.0f-py))+VControls[4].position[0]*((1.0f-py)*py*2)+VControls[5].position[0]*(py*py); |
---|
746 | temp[1].position[1]=VControls[3].position[1]*((1.0f-py)*(1.0f-py))+VControls[4].position[1]*((1.0f-py)*py*2)+VControls[5].position[1]*(py*py); |
---|
747 | temp[1].position[2]=VControls[3].position[2]*((1.0f-py)*(1.0f-py))+VControls[4].position[2]*((1.0f-py)*py*2)+VControls[5].position[2]*(py*py); |
---|
748 | |
---|
749 | temp[1].normal[0]=VControls[3].normal[0]*((1.0f-py)*(1.0f-py))+VControls[4].normal[0]*((1.0f-py)*py*2)+VControls[5].normal[0]*(py*py); |
---|
750 | temp[1].normal[1]=VControls[3].normal[1]*((1.0f-py)*(1.0f-py))+VControls[4].normal[1]*((1.0f-py)*py*2)+VControls[5].normal[1]*(py*py); |
---|
751 | temp[1].normal[2]=VControls[3].normal[2]*((1.0f-py)*(1.0f-py))+VControls[4].normal[2]*((1.0f-py)*py*2)+VControls[5].normal[2]*(py*py); |
---|
752 | |
---|
753 | temp[1].texcoord[0][0]=VControls[3].texcoord[0][0]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[0][0]*((1.0f-py)*py*2)+VControls[5].texcoord[0][0]*(py*py); |
---|
754 | temp[1].texcoord[0][1]=VControls[3].texcoord[0][1]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[0][1]*((1.0f-py)*py*2)+VControls[5].texcoord[0][1]*(py*py); |
---|
755 | temp[1].texcoord[1][0]=VControls[3].texcoord[1][0]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[1][0]*((1.0f-py)*py*2)+VControls[5].texcoord[1][0]*(py*py); |
---|
756 | temp[1].texcoord[1][1]=VControls[3].texcoord[1][1]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[1][1]*((1.0f-py)*py*2)+VControls[5].texcoord[1][1]*(py*py); |
---|
757 | |
---|
758 | |
---|
759 | // temp[2]=controlPoints[6]*((1.0f-py)*(1.0f-py))+controlPoints[7]*((1.0f-py)*py*2)+controlPoints[8]*(py*py); |
---|
760 | temp[2].position[0]=VControls[6].position[0]*((1.0f-py)*(1.0f-py))+VControls[7].position[0]*((1.0f-py)*py*2)+VControls[8].position[0]*(py*py); |
---|
761 | temp[2].position[1]=VControls[6].position[1]*((1.0f-py)*(1.0f-py))+VControls[7].position[1]*((1.0f-py)*py*2)+VControls[8].position[1]*(py*py); |
---|
762 | temp[2].position[2]=VControls[6].position[2]*((1.0f-py)*(1.0f-py))+VControls[7].position[2]*((1.0f-py)*py*2)+VControls[8].position[2]*(py*py); |
---|
763 | |
---|
764 | temp[2].normal[0]=VControls[6].normal[0]*((1.0f-py)*(1.0f-py))+VControls[7].normal[0]*((1.0f-py)*py*2)+VControls[8].normal[0]*(py*py); |
---|
765 | temp[2].normal[1]=VControls[6].normal[1]*((1.0f-py)*(1.0f-py))+VControls[7].normal[1]*((1.0f-py)*py*2)+VControls[8].normal[1]*(py*py); |
---|
766 | temp[2].normal[2]=VControls[6].normal[2]*((1.0f-py)*(1.0f-py))+VControls[7].normal[2]*((1.0f-py)*py*2)+VControls[8].normal[2]*(py*py); |
---|
767 | |
---|
768 | temp[2].texcoord[0][0]=VControls[6].texcoord[0][0]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[0][0]*((1.0f-py)*py*2)+VControls[8].texcoord[0][0]*(py*py); |
---|
769 | temp[2].texcoord[0][1]=VControls[6].texcoord[0][1]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[0][1]*((1.0f-py)*py*2)+VControls[8].texcoord[0][1]*(py*py); |
---|
770 | temp[2].texcoord[1][0]=VControls[6].texcoord[1][0]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[1][0]*((1.0f-py)*py*2)+VControls[8].texcoord[1][0]*(py*py); |
---|
771 | temp[2].texcoord[1][1]=VControls[6].texcoord[1][1]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[1][1]*((1.0f-py)*py*2)+VControls[8].texcoord[1][1]*(py*py); |
---|
772 | |
---|
773 | |
---|
774 | |
---|
775 | |
---|
776 | for(int v=0; v<=level; ++v) { |
---|
777 | px=(float)v/level; |
---|
778 | |
---|
779 | |
---|
780 | |
---|
781 | |
---|
782 | |
---|
783 | //Vertice[u*(tesselation+1)+v]= temp[0]*((1.0f-px)*(1.0f-px))+ temp[1]*((1.0f-px)*px*2)+ temp[2]*(px*px); |
---|
784 | Vertice[u*(level1)+v].position[0]=temp[0].position[0]*((1.0f-px)*(1.0f-px))+temp[1].position[0]*((1.0f-px)*px*2)+temp[2].position[0]*(px*px); |
---|
785 | Vertice[u*(level1)+v].position[1]=temp[0].position[1]*((1.0f-px)*(1.0f-px))+temp[1].position[1]*((1.0f-px)*px*2)+temp[2].position[1]*(px*px); |
---|
786 | Vertice[u*(level1)+v].position[2]=temp[0].position[2]*((1.0f-px)*(1.0f-px))+temp[1].position[2]*((1.0f-px)*px*2)+temp[2].position[2]*(px*px); |
---|
787 | |
---|
788 | Vertice[u*(level1)+v].normal[0]=temp[0].normal[0]*((1.0f-px)*(1.0f-px))+temp[1].normal[0]*((1.0f-px)*px*2)+temp[2].normal[0]*(px*px); |
---|
789 | Vertice[u*(level1)+v].normal[1]=temp[0].normal[1]*((1.0f-px)*(1.0f-px))+temp[1].normal[1]*((1.0f-px)*px*2)+temp[2].normal[1]*(px*px); |
---|
790 | Vertice[u*(level1)+v].normal[2]=temp[0].normal[2]*((1.0f-px)*(1.0f-px))+temp[1].normal[2]*((1.0f-px)*px*2)+temp[2].normal[2]*(px*px); |
---|
791 | |
---|
792 | Vertice[u*(level1)+v].texcoord[0][0]=temp[0].texcoord[0][0]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[0][0]*((1.0f-px)*px*2)+temp[2].texcoord[0][0]*(px*px); |
---|
793 | Vertice[u*(level1)+v].texcoord[0][1]=temp[0].texcoord[0][1]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[0][1]*((1.0f-px)*px*2)+temp[2].texcoord[0][1]*(px*px); |
---|
794 | Vertice[u*(level1)+v].texcoord[1][0]=temp[0].texcoord[1][0]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[1][0]*((1.0f-px)*px*2)+temp[2].texcoord[1][0]*(px*px); |
---|
795 | Vertice[u*(level1)+v].texcoord[1][1]=temp[0].texcoord[1][1]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[1][1]*((1.0f-px)*px*2)+temp[2].texcoord[1][1]*(px*px); |
---|
796 | |
---|
797 | |
---|
798 | |
---|
799 | } |
---|
800 | } |
---|
801 | |
---|
802 | //Create indices |
---|
803 | GLuint* indices= & ((GLuint*)(this->patchIndexes))[level*level1*2*this->patchOffset]; |
---|
804 | |
---|
805 | for(int row=0; row<level; ++row) { |
---|
806 | for(int point=0; point<=level; ++point) { |
---|
807 | //calculate indices |
---|
808 | //reverse them to reverse winding |
---|
809 | indices[(row*(level1)+point)*2+1]=row*(level1)+point; |
---|
810 | indices[(row*(level1)+point)*2]=(row+1)*(level1)+point; |
---|
811 | } |
---|
812 | } |
---|
813 | |
---|
814 | |
---|
815 | //*********************************************************************************************************************** |
---|
816 | // Debug Model |
---|
817 | //*********************************************************************************************************************** |
---|
818 | |
---|
819 | this->VertexArrayModels[this->patchOffset] = new VertexArrayModel(); |
---|
820 | VertexArrayModel* tmp = this->VertexArrayModels[this->patchOffset]; |
---|
821 | tmp->newStripe(); |
---|
822 | int a = 0; |
---|
823 | int b = -1; |
---|
824 | tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]); |
---|
825 | tmp->addNormal(1,0,0); |
---|
826 | tmp->addTexCoor(0.0,0.0); |
---|
827 | tmp->addColor(0.3,0.0,0.0); |
---|
828 | tmp->addIndice(1+b); |
---|
829 | tmp->addIndice(4+a); |
---|
830 | tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]); |
---|
831 | tmp->addNormal(1,0,0); |
---|
832 | tmp->addTexCoor(0.0,0.4); |
---|
833 | tmp->addColor(0.3,0.0,0.0); |
---|
834 | tmp->addIndice(2+b); |
---|
835 | tmp->addIndice(5+a); |
---|
836 | tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); |
---|
837 | tmp->addNormal(1,0,0); |
---|
838 | tmp->addTexCoor(0.0,1.0); |
---|
839 | tmp->addColor(0.1,0.0,0.0); |
---|
840 | tmp->addIndice(3+b); |
---|
841 | tmp->addIndice(6+a); |
---|
842 | |
---|
843 | tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); |
---|
844 | tmp->addNormal(1,0,0); |
---|
845 | tmp->addTexCoor(0.0,1.0); |
---|
846 | tmp->addColor(0.1,0.0,0.0); |
---|
847 | tmp->addIndice(7+a); |
---|
848 | //tmp->addIndice(6); |
---|
849 | |
---|
850 | tmp->newStripe(); |
---|
851 | |
---|
852 | tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]); |
---|
853 | tmp->addNormal(1,0,0); |
---|
854 | tmp->addTexCoor(0.0,0.0); |
---|
855 | tmp->addColor(0.1,0.1,0.1); |
---|
856 | tmp->addIndice(5+b); |
---|
857 | tmp->addIndice(8+a); |
---|
858 | tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]); |
---|
859 | tmp->addNormal(1,0,0); |
---|
860 | tmp->addTexCoor(0.0,0.4); |
---|
861 | tmp->addColor(0.1,0.1,0.1); |
---|
862 | tmp->addIndice(6+b); |
---|
863 | tmp->addIndice(9+a); |
---|
864 | tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); |
---|
865 | tmp->addNormal(1,0,0); |
---|
866 | tmp->addTexCoor(0.0,1.0); |
---|
867 | tmp->addColor(0.1,0.1,0.1); |
---|
868 | tmp->addIndice(7+b); |
---|
869 | tmp->addIndice(10+a); |
---|
870 | tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]+0.01); |
---|
871 | tmp->addNormal(1,0,0); |
---|
872 | tmp->addTexCoor(0.0,1.0); |
---|
873 | tmp->addColor(0.1,0.1,0.1); |
---|
874 | //tmp->addIndice(5); |
---|
875 | tmp->addIndice(11+a); |
---|
876 | |
---|
877 | tmp->newStripe(); |
---|
878 | |
---|
879 | |
---|
880 | |
---|
881 | tmp->addVertex(controlsTmp[3].position[0],controlsTmp[3].position[1], controlsTmp[3].position[2]); |
---|
882 | tmp->addNormal(0,1,0); |
---|
883 | tmp->addTexCoor(0.5,0.0); |
---|
884 | tmp->addColor(0.1,0.1,0.1); |
---|
885 | tmp->addIndice(9+b); |
---|
886 | tmp->addIndice(12+a); |
---|
887 | tmp->addVertex(controlsTmp[4].position[0],controlsTmp[4].position[1], controlsTmp[4].position[2]); |
---|
888 | tmp->addNormal(1,0,0); |
---|
889 | tmp->addTexCoor(0.5,0.5); |
---|
890 | tmp->addColor(0.1,0.1,0.1); |
---|
891 | tmp->addIndice(10+b); |
---|
892 | tmp->addIndice(13+a); |
---|
893 | tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]); |
---|
894 | tmp->addNormal(1,0,0); |
---|
895 | tmp->addTexCoor(0.5,1.0); |
---|
896 | tmp->addColor(0.1,0.1,0.1); |
---|
897 | tmp->addIndice(11+b); |
---|
898 | tmp->addIndice(14+a); |
---|
899 | tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]+0.01); |
---|
900 | tmp->addNormal(1,0,0); |
---|
901 | tmp->addTexCoor(0.5,1.0); |
---|
902 | tmp->addColor(0.1,0.1,0.1); |
---|
903 | |
---|
904 | tmp->addIndice(15+a); |
---|
905 | //tmp->addIndice(9); |
---|
906 | tmp->newStripe(); |
---|
907 | |
---|
908 | tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]); |
---|
909 | tmp->addNormal(1,0,0); |
---|
910 | tmp->addTexCoor(1.0,0.0); |
---|
911 | tmp->addColor(0.1,0.1,0.1); |
---|
912 | tmp->addIndice(13+b); |
---|
913 | tmp->addIndice(16+a); |
---|
914 | |
---|
915 | tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]); |
---|
916 | tmp->addNormal(0,1,0); |
---|
917 | tmp->addTexCoor(1.0,0.5); |
---|
918 | tmp->addColor(0.1,0.1,0.1); |
---|
919 | tmp->addIndice(14+b); |
---|
920 | tmp->addIndice(17+a); |
---|
921 | tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); |
---|
922 | tmp->addNormal(1,0,0); |
---|
923 | tmp->addTexCoor(1.0,1.0); |
---|
924 | tmp->addColor(0.1,0.1,0.1); |
---|
925 | tmp->addIndice(15+b); |
---|
926 | tmp->addIndice(18+a); |
---|
927 | tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); |
---|
928 | tmp->addNormal(1,0,0); |
---|
929 | tmp->addTexCoor(1.0,1.0); |
---|
930 | tmp->addColor(0.1,0.1,0.1); |
---|
931 | tmp->addIndice(19+a); |
---|
932 | //tmp->addIndice(13); |
---|
933 | |
---|
934 | tmp->newStripe(); |
---|
935 | tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]); |
---|
936 | tmp->addNormal(1,0,0); |
---|
937 | tmp->addTexCoor(1.0,0.0); |
---|
938 | tmp->addColor(0.1,0.1,0.1); |
---|
939 | tmp->addIndice(17+b); |
---|
940 | |
---|
941 | tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]); |
---|
942 | tmp->addNormal(0,1,0); |
---|
943 | tmp->addTexCoor(1.0,0.5); |
---|
944 | tmp->addColor(0.1,0.1,0.1); |
---|
945 | tmp->addIndice(18+b); |
---|
946 | |
---|
947 | tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); |
---|
948 | tmp->addNormal(1,0,0); |
---|
949 | tmp->addTexCoor(1.0,1.0); |
---|
950 | tmp->addColor(0.1,0.1,0.1); |
---|
951 | tmp->addIndice(19+b); |
---|
952 | |
---|
953 | tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); |
---|
954 | tmp->addNormal(1,0,0); |
---|
955 | tmp->addTexCoor(1.0,1.0); |
---|
956 | tmp->addColor(0.1,0.1,0.1); |
---|
957 | |
---|
958 | tmp->newStripe(); |
---|
959 | |
---|
960 | tmp->finalize(); |
---|
961 | // End of DebugModel |
---|
962 | |
---|
963 | this->patchOffset++; |
---|
964 | }// For |
---|
965 | } // For |
---|
966 | |
---|
967 | // Overwrite Face->meshvert; |
---|
968 | // Overwrite Face->n_meshverts; |
---|
969 | int sz = (size0 -1)/2 * (size1 -1)/2; // num patches |
---|
970 | Face->meshvert = patchOffset -sz; //3*(patchOffset-sz)*level1*level1; |
---|
971 | Face->n_meshverts = sz; |
---|
972 | PRINTF(0)("BSP FILE: sz: %i. \n", sz); |
---|
973 | PRINTF(0)("BSP FILE: Face->meshvert %i . \n", Face->meshvert); |
---|
974 | |
---|
975 | //Face->n_meshverts = sz; |
---|
976 | } |
---|
977 | |
---|
978 | void BspFile::swapAllBspCoordinates() |
---|
979 | { |
---|
980 | |
---|
981 | } |
---|
982 | |
---|
983 | void BspFile::swapCoords((int *) array) |
---|
984 | { |
---|
985 | |
---|
986 | } |
---|
987 | |
---|
988 | void BspFile::swapCoords((float *) array) |
---|
989 | { |
---|
990 | |
---|
991 | } |
---|
992 | |
---|