Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7507 was 7507, checked in by bottac, 18 years ago

Added bsp_tree_leaf.

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