Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8195 in orxonox.OLD for branches/bsp_model/src/lib/graphics/importer


Ignore:
Timestamp:
Jun 7, 2006, 3:14:46 PM (18 years ago)
Author:
bottac
Message:

merged back from old branch.

Location:
branches/bsp_model/src/lib/graphics/importer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/graphics/importer/bsp_file.cc

    r8186 r8195  
    3737#include <SDL/SDL_image.h>
    3838
     39// STL Containers
     40#include <vector>
     41
    3942using namespace std;
    4043
     
    5053int BspFile::read(const char* name)
    5154{
    52   //this->scale = 0.4;
     55  this->scale = 1.0;
    5356  int offset;
    5457  int size;
     
    605608  sc =  ((unsigned char *)(&lightMapTexture))[i];
    606609  sc *= 1/255.0;
    607   scale = 2.0;
     610  scale = 1.0;
    608611  if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp;
    609612  scale*=255.0;
  • branches/bsp_model/src/lib/graphics/importer/bsp_file.h

    r8186 r8195  
    1818*/
    1919
     20#include <vector>
    2021class SDL_Surface;
    2122class BspTreeNode;
     
    212213
    213214 
    214 
     215  ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials
    215216};
    216217
  • branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc

    r8186 r8195  
    11/*
    22   orxonox - the future of 3D-vertical-scrollers
    3 
     3 
    44   Copyright (C) 2006 orx
    5 
     5 
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 2, or (at your option)
    99   any later version.
    10 
     10 
    1111   ### File Specific:
    1212   main-programmer: bottac@ee.ethz.ch
    13 
     13 
    1414   Inspired by:
    1515   Rendering Q3 Maps by Morgan McGuire                  http://graphics.cs.brown.edu/games/quake/quake3.html
    1616   Unofficial Quake 3 Map Specs by Kekoa Proudfoot      http://graphics.stanford.edu/~kekoa/q3/
    17 
     17 
    1818   Collision detection adapted from:
    1919   Quake 3 Collision Detection by Nathan Ostgard        http://www.devmaster.net/articles/quake3collision/
     
    4747
    4848
     49
    4950//CREATE_FACTORY( BspManager, CL_BSP_MODEL);
    5051
     
    5960  this->alreadyVisible = new bool [this->bspFile->numFaces];
    6061  */
    61   CDEngine::getInstance()->setBSPModel(this);
     62
    6263}
    6364
     
    6667BspManager::BspManager(const TiXmlElement* root)
    6768{
    68 
    69 
     69 
     70 
    7071  if( root != NULL)
    7172    this->loadParams(root);
    72 
     73 
    7374  CDEngine::getInstance()->setBSPModel(this);
    7475} */
     
    7778{
    7879  //this->setClassID(CL_BSP_MODEL, "BspManager");
    79     // open a BSP file
     80  // open a BSP file
    8081  this->bspFile = new BspFile();
    8182  this->bspFile->scale =  scale;
     
    8586  this->alreadyVisible = new bool [this->bspFile->numFaces];
    8687
     88  CDEngine::getInstance()->setBSPModel(this);
    8789
    8890}
     
    9799  this->root  = this->bspFile->get_root();
    98100  this->alreadyVisible = new bool [this->bspFile->numFaces];
    99 
     101 
    100102  CDEngine::getInstance()->setBSPModel(this);
    101103}
    102104*/
    103105
     106const void BspManager::tick(float time)
     107{
     108 
     109}
    104110const void BspManager::draw()
    105111{
     
    109115  this->out1 = this->out;
    110116  this->out2 = this->out;
    111   if(this->collPlane != NULL)
    112   {
    113   this->out1.x += this->collPlane->x*5.0;
    114   this->out1.y += this->collPlane->y*5.0;
    115   this->out1.z += this->collPlane->z*5.0;
    116 
    117   this->out2.x += this->collPlane->x*10.0;
    118   this->out2.y += this->collPlane->y*10.0;
    119   this->out2.z += this->collPlane->z*10.0;
     117  if(this->collPlane != NULL) {
     118    this->out1.x += this->collPlane->x*5.0;
     119    this->out1.y += this->collPlane->y*5.0;
     120    this->out1.z += this->collPlane->z*5.0;
     121
     122    this->out2.x += this->collPlane->x*10.0;
     123    this->out2.y += this->collPlane->y*10.0;
     124    this->out2.z += this->collPlane->z*10.0;
    120125  }
    121126  this->drawDebugCube(&this->out1);
    122127  this->drawDebugCube(&this->out2);
     128 
    123129  */
     130 
     131
    124132  // Draw Debug Terrain
    125133  /*
     
    148156
    149157
    150   // this->viewDir=    State::getCameraTarget()->getAbsCoor() -  State::getCamera()->getAbsCoor() ;
     158  this->viewDir=    State::getCamera()->getAbsDirX();
    151159  float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z);
    152160
     
    157165
    158166
    159   this->cam = State::getCameraTargetNode()->getAbsCoor();
    160   // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
     167 
     168 // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
     169 
     170 
    161171  this->outputStartsOut = true;
    162172  this->outputAllSolid = false;
    163173  this->outputFraction = 1.0f;
    164 
    165   this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam);
    166 
    167   //if(this->outputFraction != 1.0f || this->outputAllSolid ) this->drawDebugCube(&this->cam);
     174  this->checkCollision(State::getPlayer()->getPlayable());
     175 
    168176
    169177  if ( viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0 )  //!< if (sizeof(Visdata) == 0)
     
    172180
    173181
    174     // Iterate through all Leafspublic final double readLEDouble()
     182    // Iterate through all Leafs
    175183    for(int i = 0; i <  this->bspFile->numLeafs   ; i++ )
    176184    {
     
    179187      if(curLeaf.cluster<0) continue;
    180188
    181 
    182189      /** Do Frustum culling and draw 'em all **/
    183       bool inFrustum = true;
    184 
    185       Vector dir;
    186       dir.x = State::getCameraNode()->getAbsDirX().x;
    187       dir.y =  State::getCameraNode()->getAbsDirX().y;
    188       dir.z =  State::getCameraNode()->getAbsDirX().z;
     190     
     191      Vector dir = State::getCameraNode()->getAbsDirX();
     192
    189193      float dist =  dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z;
    190194      //if(dist < 0) dist = -dist;
     
    192196      const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist ;
    193197
    194       if(dMins < -150.0 && dMaxs < -150.0) {
     198      if(dMins < -300.0 && dMaxs < -300.0) {
    195199        continue;
    196200      }
    197       if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 3000  && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 3000) {
     201      if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 2000  && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 2000) {
    198202        continue;
    199203      }
     
    206210        if (f >=0 && !this->isAlreadyVisible(f)) {
    207211          this->alreadyVisible[f] = true;
    208 
    209212          addFace(f); // "visibleFaces.append(f)"
    210213        }
     
    794797    // STEP 3: calculate the middle point for the first side
    795798    middleFraction = startFraction +
    796         (endFraction - startFraction) * fraction1;
     799                     (endFraction - startFraction) * fraction1;
    797800
    798801    middle.x = start->x + fraction1 * (end->x - start->x);
     
    805808
    806809    else this->checkCollisionRayN(node->right,startFraction, middleFraction,
    807                                  start, &middle );
     810                                    start, &middle );
    808811
    809812    // STEP 5: calculate the middle point for the second side
    810813    middleFraction = startFraction +
    811         (endFraction - startFraction) * fraction2;
     814                     (endFraction - startFraction) * fraction2;
    812815
    813816    middle.x = start->x + fraction2 * (end->x - start->x);
     
    824827
    825828}
     829void BspManager::checkCollisionBox(void)
     830{
     831 
     832};
     833
     834void BspManager::TraceBox( Vector& inputStart, Vector& inputEnd,
     835               Vector& inputMins, Vector& inputMaxs )
     836{
     837  if (inputMins.x == 0 && inputMins.y == 0 && inputMins.z == 0 &&
     838      inputMaxs.x == 0 && inputMaxs.y == 0 && inputMaxs.z == 0)
     839  {   // the user called TraceBox, but this is actually a ray
     840   //!> FIXME TraceRay( inputStart, inputEnd );
     841  }
     842  else
     843  {   // setup for a box
     844    //traceType = TT_BOX;
     845    this->traceMins = inputMins;
     846    this->traceMaxs = inputMaxs;
     847    this->traceExtents.x = -traceMins.x > traceMaxs.x ?
     848        -traceMins.x : traceMaxs.x;
     849    this->traceExtents.y = -traceMins.y > traceMaxs.y ?
     850        -traceMins.y : traceMaxs.y;
     851    this->traceExtents.z = -traceMins.z > traceMaxs.z ?
     852        -traceMins.z : traceMaxs.z;
     853   //!> FIXME Trace( inputStart, inputEnd );
     854  }
     855}
    826856
    827857void BspManager::checkCollision(WorldEntity* worldEntity)
    828858{
    829   return;
     859
    830860
    831861  Vector position = worldEntity->getAbsCoor();
     
    833863
    834864  Vector forwardDir = worldEntity->getAbsDirX();
    835   forwardDir.x =2.0*forwardDir.x;
    836   forwardDir.y =2.0*forwardDir.y;
    837   forwardDir.z =2.0*forwardDir.z;
     865  forwardDir.x =8.0*forwardDir.x;
     866  forwardDir.y =8.0*forwardDir.y;
     867  forwardDir.z =8.0*forwardDir.z;
    838868
    839869  Vector upDir = worldEntity->getAbsDirY();
     
    842872  dest.y  += forwardDir.y;
    843873  dest.z  += forwardDir.z;
    844   Vector out = Vector(-1875.0,-1875.0,-1875.0);
     874  Vector out = dest;
    845875  if(!worldEntity->isA(CL_PLAYABLE)) {
    846 
    847876
    848877
     
    855884    Vector dest1 = position1 + forwardDir;
    856885    Vector dest2 = position2 + forwardDir;
    857     dest = position - upDir;
     886    dest = position - Vector(0.0, 20.0,0.0);
    858887    Vector out1;
    859888    Vector out2;
     
    871900    this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 );
    872901    if(this->outputFraction == 1.0f) out2= dest;
    873     else
    874     {
     902    else {
    875903      collision = true;
    876     out2.x = position2.x + (dest2.x -position2.x) * this->outputFraction;
    877     out2.y = position2.y + (dest2.y -position2.y) * this->outputFraction;
    878     out2.z = position2.z + (dest2.z - position2.z) * this->outputFraction;
     904      out2.x = position2.x + (dest2.x -position2.x) * this->outputFraction;
     905      out2.y = position2.y + (dest2.y -position2.y) * this->outputFraction;
     906      out2.z = position2.z + (dest2.z - position2.z) * this->outputFraction;
    879907
    880908    }
     
    882910    this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
    883911    if(this->outputFraction == 1.0f) out = dest;
    884     else
    885     {
    886     collision = true;
    887     out.x = position.x + (dest.x -position.x) * this->outputFraction;
    888     out.y = position.y + (dest.y -position.y) * this->outputFraction;
    889     out.z = position.z + (dest.z -position.z) * this->outputFraction;
    890 
    891     //Vector out3 = out + Vector(3*this->collPlane->x,3*this->collPlane->y,3*this->collPlane->z);
    892     //this->out = out;
    893     //this->out1 = out1;
    894     //this->out2 = out2;
    895     //this->drawDebugCube(&out1);
    896     //this->drawDebugCube(&out2);
    897 
    898     //this->drawDebugCube(&out3);
     912    else {
     913      collision = true;
     914      out.x = position.x + (dest.x -position.x) * this->outputFraction;
     915      out.y = position.y + (dest.y -position.y) * this->outputFraction;
     916      out.z = position.z + (dest.z -position.z) * this->outputFraction;
     917
     918      Vector out3 = out + Vector(3*this->collPlane->x,3*this->collPlane->y,3*this->collPlane->z);
     919      this->out = out;
     920      this->out1 = out1;
     921      this->out2 = out2;
     922      //this->drawDebugCube(&out1);
     923      //this->drawDebugCube(&out2);
     924
     925      //this->drawDebugCube(&out3);
    899926
    900927    }
    901928
    902929    // Return the normal here: Normal's stored in this->collPlane;
    903 //    if(collision) worldEntity->collidesWithGround(out,out1,out2);
     930   
     931    if(collision) worldEntity->collidesWithGround(out,out1,out2);
    904932
    905933  }
     
    938966      this->drawDebugCube(&this->cam);
    939967      this->drawDebugCube(&next);
    940       State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
    941       State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());
     968     // State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
     969      //State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());
    942970    }
    943971
  • branches/bsp_model/src/lib/graphics/importer/bsp_manager.h

    r8186 r8195  
    5252  // Functions
    5353  const void draw();
     54  const void tick(float time);
    5455  void draw_debug_face(int Face);
    5556  void draw_face(int Face);
     
    5758 
    5859
    59   void checkCollision(WorldEntity* worldEntity);
     60  void checkCollision(WorldEntity* worldEntity); /*!< WorldEntities use this function to check wheter they collided with the BSPEntity.
     61                                                      If a collision has been detected, the collides-function of worldEntity will be called.*/
    6062
    6163private:
    6264  // Functions
    6365  BspTreeNode* getLeaf(BspTreeNode*  node,   Vector* cam) ;  //!< Traverses the tree
    64   void  checkCollision(BspTreeNode* node, Vector* cam);
     66  void  checkCollision(BspTreeNode* node, Vector* cam); //!< Obsolete. Use this function for debugging only!
    6567  void  checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
    66   void  checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
     68  void  checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
     69  void TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
     70  void  checkCollisionBox(void);
    6771  void  checkBrushRay(brush* curBrush);
    6872  void  checkBrushRayN(brush* curBrush);
     
    8084  int lastTex;
    8185 
    82   //obsolete
     86  //obsolete: global variables for collision detection
    8387  bool  outputStartsOut;
    8488  bool  outputAllSolid;
    8589  float outputFraction;
     90  Vector traceMins; //!< Mins of current bbox
     91  Vector traceMaxs; //!< Maxs of current bbox
     92  Vector traceExtents; /*!< Stores the maximum of the absolute value of each axis in the box.
     93                            For example, if traceMins was (-100,-3,-15) and traceMaxs was (55,22,7), traceExtents */
    8694 
     95 
    8796  bool * alreadyVisible;
    8897  // Deques to store the visible faces
     
    9099  ::std::deque<int> opal; //!< the others here.
    91100
    92   Vector out;
    93   Vector out1;
    94   Vector out2;
     101  Vector out;  //!< For debugging only
     102  Vector out1; //!< For debugging only
     103  Vector out2; //!< For debugging only
    95104};
    96105
Note: See TracChangeset for help on using the changeset viewer.