Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc @ 7596

Last change on this file since 7596 was 7596, checked in by bottac, 18 years ago
File size: 23.2 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
16#include "vector.h"
17#include "bsp_file.h"
18#include "bsp_manager.h"
19#include "bsp_tree_leaf.h"
20#include "p_node.h"
21#include "state.h"
22#include "debug.h"
23#include "material.h"
24#include "camera.h"
25#include "vertex_array_model.h"
26#include "world_entities/player.h"
27#include "world_entities/playable.h"
28#include "util/loading/resource_manager.h"
29// STL Containers
30#include <vector>
31#include <deque>
32
33
34
35
36
37BspManager::BspManager()
38{
39  // open a BSP file
40  this->bspFile = new BspFile();
41  this->bspFile->read(ResourceManager::getFullName("test.bsp").c_str());
42  this->bspFile->build_tree();
43  this->root  = this->bspFile->get_root();
44  this->alreadyVisible = new bool [this->bspFile->numFaces];
45}
46
47void BspManager::draw()
48{
49
50
51
52
53
54  // Draw Debug Terrain
55  /*
56  this->bspFile->Materials[0]->select();
57  for(int i = 0; i <  this->bspFile->numPatches ; i++)
58        {
59                this->bspFile->VertexArrayModels[i]->draw();
60   
61        }
62  */
63
64
65
66  // erase alreadyVisible
67  for(int i = 0; i < this->bspFile->numFaces; i++) this->alreadyVisible[i] = false;
68  float tmp = 0;
69  //this->opal.clear();
70  //this->trasparent.clear();
71  // Find all visible faces...
72
73  this->cam = State::getCamera()->getAbsCoor() ;
74  //this->ship = State::getCameraTargetNode()->getAbsCoor();
75
76
77
78
79 
80 // this->viewDir=    State::getCameraTarget()->getAbsCoor() -  State::getCamera()->getAbsCoor() ;
81  float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z);
82
83  BspTreeNode*  ActLeaf = this->getLeaf(this->bspFile->root, &ship);
84  int viscluster = -1;
85  viscluster =((leaf*)(this->bspFile->leaves))[ ActLeaf->leafIndex].cluster; // get the players cluster (viscluster)
86
87
88
89  this->cam = State::getCameraTargetNode()->getAbsCoor();
90  //this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
91  this->outputStartsOut = true;
92  this->outputAllSolid = false;
93  this->outputFraction = 1.0f;
94 
95  //this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam);
96 
97  if(this->outputFraction != 1.0f || this->outputAllSolid ) this->drawDebugCube(&this->cam);
98
99  if (false || viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0 )  //!< if (sizeof(Visdata) == 0)
100  {
101   
102   
103   
104    // Iterate through all Leafspublic final double readLEDouble()
105    for(int i = 0; i <  this->bspFile->numLeafs   ; i++ )
106    {
107      // cluster =  (this->bspFile->leaves)[i].cluster;
108      leaf& curLeaf = (this->bspFile->leaves)[i];
109      if(curLeaf.cluster<0) continue;
110     
111     
112      /** Do Frustum culling and draw 'em all **/
113      bool inFrustum = true;
114      float dMins;
115      float dMaxs;
116      Vector dir;
117      dir.x = this->cam.x - State::getCameraTargetNode()->getLastAbsCoor().x;
118      dir.y = this->cam.y - State::getCameraTargetNode()->getLastAbsCoor().y;
119      dir.z = this->cam.z - State::getCameraTargetNode()->getLastAbsCoor().z;
120      float dist =  dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z;
121      //if(dist < 0) dist = -dist;
122      dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] ;
123      dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] ;
124     
125      if(dMins < -100.0 && dMaxs < -100.0)
126      {   
127       continue; 
128      }
129   
130       
131      // Iterate through all faces
132      for (int j = 0; j < curLeaf.n_leaffaces ; ++j) {
133        const int g = (j +  curLeaf.leafface);
134        const int f = ((int *)this->bspFile->leafFaces)[g];
135        if (f >=0 && !this->isAlreadyVisible(f)) {
136          this->alreadyVisible[f] = true;
137               
138          addFace(f); // "visibleFaces.append(f)"
139        }
140      }
141
142
143
144
145    } //for
146  } 
147  else {
148
149 
150    unsigned int v;
151    unsigned char  visSet;
152
153    // Iterate through all Leafs
154
155    for(int i = 0; i <  this->bspFile->numLeafs   ; ++i ) {
156      leaf& camLeaf =  (this->bspFile->leaves)[ActLeaf->leafIndex] ;
157      leaf& curLeaf =  (this->bspFile->leaves)[i] ;
158      int& cluster =  curLeaf.cluster;
159
160      if(cluster < 0) continue;
161      v = ((viscluster *  ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8));
162      visSet =((char*) (this->bspFile->visData))[v + 8];
163
164      // gets bit of visSet
165      if( ((visSet) & (1 << (cluster &  7))) != 0 ) {
166       
167        // Frustum culling
168   
169        Vector dir;
170        dir.x = this->cam.x - State::getCameraTargetNode()->getLastAbsCoor().x;
171        dir.y = this->cam.y - State::getCameraTargetNode()->getLastAbsCoor().y;
172        dir.z = this->cam.z - State::getCameraTargetNode()->getLastAbsCoor().z;
173        const float dist =  dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z;
174      //if(dist < 0) dist = -dist;
175        const float dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] - dist;
176        const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist;
177     
178        if(dMins < -100.0 && dMaxs < -100.0)
179        {   
180        continue; 
181        }
182       
183       
184        // Iterate through all faces
185        for (int j = 0; j < curLeaf.n_leaffaces ; ++j) {
186          const int g = (j +  curLeaf.leafface);
187          const int f = ((int *)this->bspFile->leafFaces)[g];
188
189          if (!this->isAlreadyVisible(f) && f>=0) {
190            this->addFace(f);
191            this->alreadyVisible[f] = true;
192          }
193
194        }
195
196      }// if
197
198    }//for
199
200  }//else
201
202  while(!this->opal.empty()) {
203    this->draw_face(this->opal.front());
204    this->opal.pop_front();
205  }
206  while(!this->trasparent.empty()) {
207    this->draw_face(this->trasparent.back());
208    this->trasparent.pop_back();
209  }
210
211
212}//draw
213
214
215
216void BspManager::draw_face(int curface)
217{
218  face& curFace =  (this->bspFile->faces)[curface];
219  const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
220  int stride = sizeof(BspVertex);  // sizeof(Vertex)
221  int offset    = curFace.vertex;
222
223  // PRINTF(0)("BSP Manager: ");
224  // PRINTF(0)("BSP Manager: type: %i  \n", curFace.texture);
225
226  //  if(  curFace.texture < 0 ) return;
227  if(curFace.type == 2) {
228    this->draw_patch( &curFace);
229    return;
230  }
231  if(curFace.type == 3) return;
232  //  if(this->bspFile->Materials[curFace.texture] != NULL)
233
234  if(this->lastTex != curFace.texture) {
235    this->bspFile->Materials[curFace.texture].mat->select();
236    this->lastTex = curFace.texture;
237  }
238
239  if(curFace.lm_index < 0) {
240    glActiveTextureARB(GL_TEXTURE1_ARB);
241    glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap );
242    glEnable(GL_TEXTURE_2D);
243  } else {
244    glActiveTextureARB(GL_TEXTURE1_ARB);
245    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[curFace.lm_index]);
246    glEnable(GL_TEXTURE_2D);
247  }
248
249 // glColor4f(3.0,3.0,3.0,1.0);
250  glEnableClientState(GL_VERTEX_ARRAY );
251  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
252  glEnableClientState(GL_NORMAL_ARRAY );
253  //  glEnableClientState(GL_COLOR_ARRAY);
254
255
256  glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
257
258  glClientActiveTextureARB(GL_TEXTURE0_ARB);
259  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
260  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
261
262  glClientActiveTextureARB(GL_TEXTURE1_ARB);
263  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
264  //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
265
266
267  glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0]));
268  // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0]));
269  glDrawElements(GL_TRIANGLES, curFace.n_meshverts,
270                 GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert]));
271
272  glDisableClientState(GL_TEXTURE0_ARB);
273  glDisableClientState(GL_TEXTURE1_ARB);
274  glDisableClientState(GL_VERTEX_ARRAY );
275  //glDisableClientState(GL_TEXTURE_COORD_ARRAY );
276  glDisableClientState(GL_NORMAL_ARRAY );
277  // glDisableClientState(GL_COLOR_ARRAY);
278
279}
280
281
282void BspManager::draw_debug_face(int curface)
283{
284  face& curFace =  (this->bspFile->faces)[curface];
285  const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
286  int stride = 44;  // sizeof(Vertex)
287  int offset    = curFace.vertex;
288
289  // PRINTF(0)("BSP Manager: ");
290  // PRINTF(0)("BSP Manager: type: %i  \n", curFace.texture);
291
292  //  if(  curFace.texture < 0 ) return;
293  if(curFace.type == 2) {
294    this->draw_patch( &curFace);
295    return;
296  }
297  if(curFace.type == 3) return;
298  // if(this->bspFile->Materials[curFace.texture] != NULL)
299
300  this->bspFile->Materials[2].mat->select();
301  this->lastTex = 2;
302
303  glEnableClientState(GL_VERTEX_ARRAY );
304  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
305  glEnableClientState(GL_NORMAL_ARRAY );
306  //glEnableClientState(GL_COLOR_ARRAY);
307  // glEnableClientState(GL_VERTEX_ARRAY );
308  glClientActiveTextureARB(GL_TEXTURE0_ARB);
309  glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
310  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
311  // glClientActiveTextureARB(GL_TEXTURE0_ARB);
312  glClientActiveTextureARB(GL_TEXTURE1_ARB);
313  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
314  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
315  // glClientActiveTextureARB(GL_TEXTURE1_ARB);
316  // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
317  //glEnableClientState(GL_NORMAL_ARRAY );
318
319  glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0]));
320  //  glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0]));
321  glDrawElements(GL_TRIANGLES, curFace.n_meshverts,
322                 GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert]));
323
324}
325
326void BspManager::draw_patch(face* Face)
327{
328  if(this->lastTex != Face->texture) {
329    this->bspFile->Materials[Face->texture].mat->select();
330    this->lastTex = Face->texture;
331  }
332
333
334
335  if(Face->lm_index < 0) {
336    glActiveTextureARB(GL_TEXTURE1_ARB);
337    glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap);
338    glEnable(GL_TEXTURE_2D);
339  } else {
340    glActiveTextureARB(GL_TEXTURE1_ARB);
341    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[Face->lm_index]);
342    glEnable(GL_TEXTURE_2D);
343  }
344  //glColor4f(3.0,3.0,3.0,1.0);
345
346  //glEnable( GL_AUTO_NORMAL);
347  glEnableClientState(GL_VERTEX_ARRAY );
348  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
349  for(int i = 0; i < Face->n_meshverts  ; i++) {
350    glFrontFace(GL_CW);
351    //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]);
352
353
354    glEnableClientState(GL_NORMAL_ARRAY );
355
356    glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0]));
357
358
359    glClientActiveTextureARB(GL_TEXTURE0_ARB);
360    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0]));
361    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
362
363
364    glClientActiveTextureARB(GL_TEXTURE1_ARB);
365    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[1][0]));
366    //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
367
368
369    glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
370
371
372
373
374    for(int row=0; row<7; ++row) {
375      glDrawElements(GL_TRIANGLE_STRIP, 2*(8), GL_UNSIGNED_INT,
376                     & (     (((GLuint*)  (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8]  ))  );
377    }
378
379    glFrontFace(GL_CCW);
380  }
381  glDisableClientState(GL_TEXTURE0_ARB);
382  glDisableClientState(GL_TEXTURE1_ARB);
383  //glDisable(GL_AUTO_NORMAL);
384  glDisableClientState(GL_VERTEX_ARRAY );
385  glDisableClientState(GL_TEXTURE_COORD_ARRAY );
386
387  glBegin(GL_QUADS);
388
389  glEnd();
390}
391
392bool BspManager::isAlreadyVisible(int Face)
393{
394  return this->alreadyVisible[Face];
395}
396
397
398BspTreeNode*  BspManager::getLeaf(BspTreeNode* node, Vector* cam)
399{
400  float dist = 0;
401  while(!(node->isLeaf)) {
402    dist = (node->plane.x * this->cam.x + node->plane.y*this->cam.y + node->plane.z*this->cam.z) - node->d;
403    if(dist >= 0.0f) {
404      node = node->left;
405    } else {
406      node = node->right;
407    }
408  }
409  return  node;
410}
411
412void BspManager::checkBrushRay(brush* curBrush)
413{
414  float EPSILON = 0.000001;
415  float startDistance;
416  float endDistance;
417 
418  float startFraction = -1.0f;
419  float endFraction = 1.0f;
420  bool startsOut = false;
421  bool endsOut = false;
422 
423  Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
424  Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
425
426  for (int i = 0; i < curBrush->n_brushsides; i++)
427  {
428    brushside& curBrushSide =   this->bspFile->brushSides[curBrush->brushside + i]   ;
429    plane& curPlane  =   this->bspFile->planes[curBrushSide.plane] ;
430
431       startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d;
432     endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d;
433
434    if (startDistance > 0)
435      startsOut = true;
436    if (endDistance > 0)
437      endsOut = true;
438
439        // make sure the trace isn't completely on one side of the brush
440    if (startDistance > 0 && endDistance > 0)
441    {   // both are in front of the plane, its outside of this brush
442      return;
443    }
444    if (startDistance <= 0 && endDistance <= 0)
445    {   // both are behind this plane, it will get clipped by another one
446      continue;
447    }
448
449        // MMM... BEEFY
450    if (startDistance > endDistance)
451    {   // line is entering into the brush
452      float fraction = (startDistance - EPSILON) / (startDistance - endDistance);  // *
453      if (fraction > startFraction)
454        startFraction = fraction;
455    }
456    else
457    {   // line is leaving the brush
458      float fraction = (startDistance + EPSILON) / (startDistance - endDistance);  // *
459      if (fraction < endFraction)
460        endFraction = fraction;
461    }
462   
463  }
464   if (startsOut == false)
465    {
466      this->outputStartsOut = false;
467      if (endsOut == false)
468        this->outputAllSolid = true;
469      return;
470    }
471
472  if (startFraction < endFraction)
473  {
474    if (startFraction > -1.0f && startFraction < outputFraction)
475    {
476      if (startFraction < 0)
477        startFraction = 0;
478      this->outputFraction = startFraction;
479    }
480  }
481 
482}
483
484void BspManager::checkCollisionRay(BspTreeNode* node, float startFraction, float endFraction, Vector* start, Vector* end)
485{
486
487
488  float EPSILON = 0.000001;
489  float  endDistance = (end)->x * (node->plane.x) +(end)->y * (node->plane.y) +(end)->z * (node->plane.z)  - node->d;
490  float  startDistance = (start)->x * (node->plane.x)+ (start)->y * (node->plane.y)+ (start)->z * (node->plane.z)- node->d;
491
492
493  if(node->isLeaf) {
494    leaf& curLeaf = this->bspFile->leaves[node->leafIndex];
495    for (int i = 0; i <  curLeaf.n_leafbrushes ; i++) {
496      brush& curBrush = this->bspFile->brushes[((int*)(this->bspFile->leafBrushes))[curLeaf.leafbrush_first+i]];
497      //object *brush = &BSP.brushes[BSP.leafBrushes[leaf->firstLeafBrush + i]];
498      if (curBrush.n_brushsides > 0   &&
499        ((((BspTexture*)(this->bspFile->textures))[curBrush.texture]).contents & 1)) 
500      // CheckBrush( brush );
501      this->checkBrushRay(&curBrush);
502      if(curBrush.n_brushsides <=0) this->outputAllSolid = true;
503    }
504    return;
505  }
506
507
508  if (startDistance >= 0 && endDistance >= 0)     // A
509  {   // both points are in front of the plane
510    // so check the front child
511    this->checkCollisionRay(node->left,0,0,start,end);
512  } else if (startDistance < 0 && endDistance < 0)  // B
513  {   // both points are behind the plane
514    // so check the back child
515    this->checkCollisionRay(node->right,0,0,start,end);
516  } else                                            // C
517  {   // the line spans the splitting plane
518    int side;
519    float fraction1, fraction2, middleFraction;
520    Vector middle;
521
522    // STEP 1: split the segment into two
523    if (startDistance < endDistance) {
524      side = 1; // back
525      float inverseDistance = 1.0f / (startDistance - endDistance);
526      fraction1 = (startDistance + EPSILON) * inverseDistance;
527      fraction2 = (startDistance + EPSILON) * inverseDistance;
528    } else if (endDistance < startDistance) {
529      side = 0; // front(start)->x * (node->plane.x)+
530      float inverseDistance = 1.0f / (startDistance - endDistance);
531      fraction1 = (startDistance + EPSILON) * inverseDistance;
532      fraction2 = (startDistance - EPSILON) * inverseDistance;
533    } else {
534      side = 0; // front
535      fraction1 = 1.0f;
536      fraction2 = 0.0f;
537    }
538
539    // STEP 2: make sure the numbers are valid
540    if (fraction1 < 0.0f) fraction1 = 0.0f;
541    else if (fraction1 > 1.0f) fraction1 = 1.0f;
542    if (fraction2 < 0.0f) fraction2 = 0.0f;
543    else if (fraction2 > 1.0f) fraction2 = 1.0f;
544
545    // STEP 3: calculate the middle point for the first side
546    middleFraction = startFraction +
547                     (endFraction - startFraction) * fraction1;
548
549    middle.x = start->x + fraction1 * (end->x - start->x);
550    middle.y = start->y + fraction1 * (end->y - start->y);
551    middle.z = start->z + fraction1 * (end->z - start->z);
552
553    // STEP 4: check the first side
554    //CheckNode( node->children[side], startFraction, middleFraction, start, middle );
555    if(side == 0) this->checkCollisionRay(node->left,startFraction, middleFraction, start, &middle );
556
557    else this->checkCollisionRay(node->right,startFraction, middleFraction,
558                                   start, &middle );
559
560    // STEP 5: calculate the middle point for the second side
561    middleFraction = startFraction +
562                     (endFraction - startFraction) * fraction2;
563
564    middle.x = start->x + fraction2 * (end->x - start->x);
565    middle.y = start->y + fraction2 * (end->y - start->y);
566    middle.z = start->z + fraction2 * (end->z - start->z);
567
568    // STEP 6: check the second side
569    if(side == 1)this->checkCollisionRay(node->left,middleFraction, endFraction, &middle, end);
570
571    else this->checkCollisionRay(node->right,middleFraction, endFraction,&middle, end );
572
573
574  }
575
576}
577void  BspManager::checkCollision(BspTreeNode* node, Vector* cam)
578{
579  Vector next = this->cam;
580  next.x =   (State::getCameraTargetNode()->getLastAbsCoor()).x ;
581  next.y =   (State::getCameraTargetNode()->getLastAbsCoor()).y ;
582  next.z =   (State::getCameraTargetNode()->getLastAbsCoor()).z ;
583
584  float dist = 0;
585  if(!(node->isLeaf)) {
586    dist = (node->plane.x * this->cam.x + node->plane.y*this->cam.y + node->plane.z*this->cam.z) - node->d;
587    if(dist > 4.0f) {
588      checkCollision(node->left,cam);
589      return;
590    }
591    if(dist < -4.0f) {
592      checkCollision(node->right,cam);
593      return;
594    }
595    if(dist<=4.0f && dist >= -4.0f) {
596      checkCollision(node->left,cam);
597      checkCollision(node->right,cam);
598      return;
599    }
600    return;
601  } else {
602
603    leaf& camLeaf =  ((leaf *)(this->bspFile->leaves))[(node->leafIndex ) ];
604
605    if (camLeaf.cluster < 0) {
606                              this->drawDebugCube(&this->cam); 
607                              this->drawDebugCube(&next);
608                              State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
609                              State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());
610                              }
611
612
613    /*
614        for(int i = 0; i < camLeaf.n_leafbrushes && i < 10; i++ )
615        {
616                brush& curBrush = ((brush*)(this->bspFile->brushes))[(camLeaf.leafbrush_first +i)%this->bspFile->numLeafBrushes];
617                if(curBrush.n_brushsides < 0) return;
618                for(int j = 0; j < curBrush.n_brushsides; j++)
619                {
620                float dist = -0.1;
621                brushside& curBrushSide = ((brushside*)(this->bspFile->brushSides))[(curBrush.brushside +j)%this->bspFile->numBrushSides];
622                plane&      testPlane = ((plane*)(this->bspFile->planes))[curBrushSide.plane % this->bspFile->numPlanes];
623                dist = testPlane.x * this->cam.x +  testPlane.y * this->cam.y  +  testPlane.z * this->cam.z   -testPlane.d ;
624               
625                if(dist < -0.01f) dist = -1.0f *dist;
626                if(dist < 1.0f){
627                                this->drawDebugCube(&this->cam);
628                                return;
629                              }
630                }
631                       
632        } */
633
634  }
635  return;
636}
637
638void BspManager::drawDebugCube(Vector* cam)
639{
640  glBegin(GL_QUADS);
641
642  // Bottom Face.  Red, 75% opaque, magnified texture
643
644  glNormal3f( 0.0f, -1.0f, 0.0f); // Needed for lighting
645  glColor4f(0.9,0.2,0.2,.75); // Basic polygon color
646
647  glTexCoord2f(0.800f, 0.800f); glVertex3f(cam->x-1.0f, cam->y-1.0f,cam->z -1.0f);
648  glTexCoord2f(0.200f, 0.800f); glVertex3f(cam->x+1.0f, cam->y-1.0f,cam->z -1.0f);
649  glTexCoord2f(0.200f, 0.200f); glVertex3f(cam->x+ 1.0f,cam->y -1.0f,cam->z +  1.0f);
650  glTexCoord2f(0.800f, 0.200f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z + 1.0f);
651
652
653  // Top face; offset.  White, 50% opaque.
654
655  glNormal3f( 0.0f, 1.0f, 0.0f);  glColor4f(0.5,0.5,0.5,.5);
656
657  glTexCoord2f(0.005f, 1.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.0f);
658  glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f,  cam->z +1.0f);
659  glTexCoord2f(1.995f, 0.005f); glVertex3f(cam->x+ 1.0f,  cam->y+1.0f,  cam->z +1.0f);
660  glTexCoord2f(1.995f, 1.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z -1.0f);
661
662
663  // Far face.  Green, 50% opaque, non-uniform texture cooridinates.
664
665  glNormal3f( 0.0f, 0.0f,-1.0f);  glColor4f(0.2,0.9,0.2,.5);
666
667  glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z -1.3f);
668  glTexCoord2f(2.995f, 2.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.3f);
669  glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x+ 1.0f,cam->y+  1.0f, cam->z -1.3f);
670  glTexCoord2f(0.005f, 0.005f); glVertex3f( cam->x+1.0f,cam->y -1.0f, cam->z -1.3f);
671
672
673  // Right face.  Blue; 25% opaque
674
675  glNormal3f( 1.0f, 0.0f, 0.0f);  glColor4f(0.2,0.2,0.9,.25);
676
677  glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y -1.0f, cam->z -1.0f);
678  glTexCoord2f(0.995f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z -1.0f);
679  glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z + 1.0f);
680  glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y-1.0f,  cam->z +1.0f);
681
682
683  // Front face; offset.  Multi-colored, 50% opaque.
684
685  glNormal3f( 0.0f, 0.0f, 1.0f);
686
687  glColor4f( 0.9f, 0.2f, 0.2f, 0.5f);
688  glTexCoord2f( 0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f,  cam->z +1.0f);
689  glColor4f( 0.2f, 0.9f, 0.2f, 0.5f);
690  glTexCoord2f( 0.995f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y-1.0f,  cam->z +1.0f);
691  glColor4f( 0.2f, 0.2f, 0.9f, 0.5f);
692  glTexCoord2f( 0.995f, 0.995f); glVertex3f( cam->x+1.0f,  cam->y+1.0f,  cam->z +1.0f);
693  glColor4f( 0.1f, 0.1f, 0.1f, 0.5f);
694  glTexCoord2f( 0.005f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f,  cam->z +1.0f);
695
696
697  // Left Face; offset.  Yellow, varying levels of opaque.
698
699  glNormal3f(-1.0f, 0.0f, 0.0f);
700
701  glColor4f(0.9,0.9,0.2,0.0);
702  glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z -1.0f);
703  glColor4f(0.9,0.9,0.2,0.66);
704  glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x-1.0f,cam->y -1.0f,  cam->z +1.0f);
705  glColor4f(0.9,0.9,0.2,1.0);
706  glTexCoord2f(0.995f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f,  cam->z +1.0f);
707  glColor4f(0.9,0.9,0.2,0.33);
708  glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.0f);
709
710  glEnd();
711}
712
713void BspManager::addFace(int f)
714{
715  face& curFace =  ((face *)(this->bspFile->faces))[f];
716  if(this->bspFile->Materials[curFace.texture].alpha) this->trasparent.push_back(f);
717  else this->opal.push_back(f);
718}
Note: See TracBrowser for help on using the repository browser.