Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/bsp_model/src/lib/graphics/importer/bsp_file.cc @ 7524

Last change on this file since 7524 was 7524, checked in by stefalie, 18 years ago

branches/bsp_model: setSDLSurfaceDiffuseMap added to Material

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