Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

I made it, finally!:-) . Larger .bsp-maps, with visibility ebabled run twice as fast now.

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