Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8796 in orxonox.OLD for trunk/src/lib/graphics/importer


Ignore:
Timestamp:
Jun 26, 2006, 3:43:40 PM (18 years ago)
Author:
patrick
Message:

merged the bsp model branche back to trunk and some npc code changes :D

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/bsp_manager.cc

    r8724 r8796  
    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/
     
    4444#include "util/loading/factory.h"
    4545
     46#include "aabb.h"
     47
    4648
    4749
     
    6769BspManager::BspManager(const TiXmlElement* root)
    6870{
    69 
    70 
     71 
     72 
    7173  if( root != NULL)
    7274    this->loadParams(root);
    73 
     75 
    7476  CDEngine::getInstance()->setBSPModel(this);
    7577} */
     
    9799  this->root  = this->bspFile->get_root();
    98100  this->alreadyVisible = new bool [this->bspFile->numFaces];
    99 
     101 
    100102  CDEngine::getInstance()->setBSPModel(this);
    101103}
     
    105107{
    106108
    107   if(!this->bspFile->MovieMaterials.empty())
    108   {
    109       ::std::vector<MoviePlayer *>::iterator it = this->bspFile->MovieMaterials.begin() ;
    110       while(it != this->bspFile->MovieMaterials.end())
    111       {
    112          (*it)->tick(time);
    113         it++;
    114       }
    115  //this->bspFile->MovieMaterials.front()->tick(time );
     109  if(!this->bspFile->MovieMaterials.empty()) {
     110    ::std::vector<MoviePlayer *>::iterator it = this->bspFile->MovieMaterials.begin() ;
     111    while(it != this->bspFile->MovieMaterials.end()) {
     112      (*it)->tick(time);
     113      it++;
     114    }
     115    //this->bspFile->MovieMaterials.front()->tick(time );
    116116
    117117
     
    177177
    178178
    179  // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
     179  // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
    180180
    181181
     
    314314    return;
    315315  }
    316  // if(curFace.type != 1) return;
     316  // if(curFace.type != 1) return;
    317317  if((char*)(this->bspFile->textures)[curFace.texture*72]== 0) return;
    318318
    319319  if(this->lastTex != curFace.texture) {
    320320    if(this->bspFile->Materials[curFace.texture].animated) {
    321      // glBlendFunc(GL_ZERO,GL_ONE);
     321      // glBlendFunc(GL_ZERO,GL_ONE);
    322322
    323323
     
    342342    glEnable(GL_TEXTURE_2D);
    343343  } else {
    344    // glEnable(GL_BLEND);
     344    // glEnable(GL_BLEND);
    345345    //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    346346    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    348348    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[curFace.lm_index]);
    349349    glEnable(GL_TEXTURE_2D);
    350   //  glDisable(GL_BLEND);
     350    //  glDisable(GL_BLEND);
    351351  }
    352352
     
    596596  bool  endsOut = false;
    597597
    598  // Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
    599  // Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
     598  // Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
     599  // Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
    600600
    601601  for (int i = 0; i < curBrush->n_brushsides; i++) {
     
    840840        this->checkBrushRayN(&curBrush);
    841841      if(curBrush.n_brushsides <=0) this->outputAllSolid = true;
    842     } 
    843    
     842    }
     843
    844844    return;
    845845  }
     
    912912{
    913913  leaf& curLeaf = this->bspFile->leaves[node->leafIndex];
    914   for(int i = 0; i < curLeaf.n_leaffaces ; i++)
    915   {
    916    
     914  for(int i = 0; i < curLeaf.n_leaffaces ; i++) {
    917915  }
    918916  return 10.0f;
     
    921919void BspManager::checkCollisionBox(void)
    922920{
    923 
    924 };
     921}
     922;
    925923
    926924void BspManager::TraceBox( Vector& inputStart, Vector& inputEnd,
    927                Vector& inputMins, Vector& inputMaxs )
     925                           Vector& inputMins, Vector& inputMaxs )
    928926{
    929927  if (inputMins.x == 0 && inputMins.y == 0 && inputMins.z == 0 &&
    930       inputMaxs.x == 0 && inputMaxs.y == 0 && inputMaxs.z == 0)
    931   {   // the user called TraceBox, but this is actually a ray
    932    //!> FIXME TraceRay( inputStart, inputEnd );
    933   }
    934   else
    935   {   // setup for a box
     928      inputMaxs.x == 0 && inputMaxs.y == 0 && inputMaxs.z == 0) {   // the user called TraceBox, but this is actually a ray
     929    //!> FIXME TraceRay( inputStart, inputEnd );
     930  } else {   // setup for a box
    936931    //traceType = TT_BOX;
    937932    this->traceMins = inputMins;
    938933    this->traceMaxs = inputMaxs;
    939934    this->traceExtents.x = -traceMins.x > traceMaxs.x ?
    940         -traceMins.x : traceMaxs.x;
     935                           -traceMins.x : traceMaxs.x;
    941936    this->traceExtents.y = -traceMins.y > traceMaxs.y ?
    942         -traceMins.y : traceMaxs.y;
     937                           -traceMins.y : traceMaxs.y;
    943938    this->traceExtents.z = -traceMins.z > traceMaxs.z ?
    944         -traceMins.z : traceMaxs.z;
    945    //!> FIXME Trace( inputStart, inputEnd );
     939                           -traceMins.z : traceMaxs.z;
     940    //!> FIXME Trace( inputStart, inputEnd );
    946941  }
    947942}
     
    950945{
    951946
     947  // Init  Collision Detection
    952948  this->outputStartsOut = true;
    953949  this->outputAllSolid = false;
    954950  this->outputFraction = 1.0f;
    955951
    956 
     952  // Retrieve Bounding box
     953  AABB* box = worldEntity->getModelAABB();
    957954
    958955
     
    965962  upDir.z = 0.0;
    966963  Vector dest;
    967   /*
    968   dest.x  += forwardDir.x;
    969   dest.y  += forwardDir.y;
    970   dest.z  += forwardDir.z;
    971   */
    972   Vector position = worldEntity->getAbsCoor() + upDir*10.0f ;
     964   
     965
     966  Vector position = worldEntity->getAbsCoor();       //+ upDir*10.0f ;
    973967  dest = worldEntity->getAbsCoor() - upDir*40.0f; //
    974968  Vector out = dest;
    975969
    976970
    977 
    978 
    979971  bool collision = false;
    980   Vector position1 = position; // + Vector(0.0,0.6,0.0);
     972  Vector position1 = position;
    981973  Vector position2 = position + Vector(0.0,1.0,0.0);
    982974  Vector dest1 = position + forwardDir*4.0f;
     
    986978  Vector out2;
    987979
     980 
    988981
    989982  float height = 40;
    990 
     983 
     984 
     985  if( box != NULL)
     986  {
     987    position = worldEntity->getAbsCoor() +  box->center; // + box->axis[1] * box->halfLength[1];
     988    dest     = worldEntity->getAbsCoor() +  box->center - box->axis[1] * box->halfLength[1] * 40.0;
     989   
     990    position1 = worldEntity->getAbsCoor() +  box->center + box->axis[0] * box->halfLength[0] * 2.0f;
     991    dest1     = worldEntity->getAbsCoor() +  box->center - box->axis[0] * box->halfLength[0] *2.0f;
     992   
     993       
     994    position2 = worldEntity->getAbsCoor() +  box->center + box->axis[2] * box->halfLength[2] * 2.0f;
     995    dest2     = worldEntity->getAbsCoor() +  box->center - box->axis[2] * box->halfLength[2] * 2.0f;
     996   
     997  }
     998  else
     999  {
     1000   
     1001  }
     1002
     1003 
     1004 
     1005  //
    9911006  this->inputStart =  position;
    9921007  this->inputEnd =   dest;
    9931008  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
    994  
    995 
    996 
    997 //   PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction);
    998 //   PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z);
    999 //   PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z);
    1000 
    1001 //   position1.debug();
    1002 
    1003   if(!this->outputStartsOut )
    1004   {
     1009
     1010
     1011  //
     1012  if(!this->outputStartsOut ) {
    10051013    this->collPlane = new plane;
    10061014    this->collPlane->x = 0.0f;
     
    10081016    this->collPlane->z = 0.0f;
    10091017    collision = true;
    1010   }
    1011   else
    1012   {
    1013 
    1014 
    1015 
    1016 
    1017   if( this->outputFraction == 1.0f)
    1018   {
    1019     if(this->outputAllSolid )
    1020     {
    1021       this->collPlane = new plane;
    1022       this->collPlane->x = 0.0f;
    1023       this->collPlane->y = 0.0f;
    1024       this->collPlane->z = 0.0f;
     1018  } else {
     1019
     1020    if( this->outputFraction == 1.0f) {
     1021      if(this->outputAllSolid ) {
     1022        this->collPlane = new plane;
     1023        this->collPlane->x = 0.0f;
     1024        this->collPlane->y = 0.0f;
     1025        this->collPlane->z = 0.0f;
     1026        collision = true;
     1027      } else
     1028        collision = false;
     1029       
     1030       
     1031        out = dest;
     1032     
     1033    } else {
    10251034      collision = true;
    1026     }
    1027     else
    1028       collision = false;
    1029 
    1030 
    1031     out = dest;
    1032   }
    1033   else {
    1034 
    1035     collision = true;
    1036     out.x = position.x + (dest.x -position.x) * this->outputFraction;
    1037     out.y = position.y + (dest.y -position.y) * this->outputFraction;
    1038     out.z = position.z + (dest.z -position.z) * this->outputFraction;
    1039 
    1040     Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z);
    1041     this->out = out;
    1042   }
    1043 
    1044 
    1045   }
     1035      out.x = position.x + (dest.x -position.x) * this->outputFraction;
     1036      out.y = position.y + (dest.y -position.y) * this->outputFraction;
     1037      out.z = position.z + (dest.z -position.z) * this->outputFraction;
     1038
     1039      Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z);
     1040      this->out = out;
     1041    }
     1042
     1043
     1044  }
     1045
     1046  plane* testPlane = this->collPlane;
     1047
    10461048 
    1047   plane* testPlane = this->collPlane;
    1048  
     1049  // 2nd Collision Detection
    10491050  this->outputStartsOut = true;
    10501051  this->outputAllSolid = false;
    10511052  this->outputFraction = 1.0f;
    1052   this->inputStart =  position;
     1053  this->inputStart =  position1;
    10531054  this->inputEnd =   dest1;
    1054   this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest1 );
     1055  this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 );
    10551056  out.x = this->outputFraction;
     1057  //out.z = this->outputFraction;
     1058 
     1059 
     1060    // 3rd Collision Detection
     1061  this->outputStartsOut = true;
     1062  this->outputAllSolid = false;
     1063  this->outputFraction = 1.0f;
     1064  this->inputStart =  position2;
     1065  this->inputEnd =   dest2;
     1066  this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 );
     1067  //out.x = this->outputFraction;
    10561068  out.z = this->outputFraction;
    10571069 
     1070
    10581071  /*
     1072  This is how you would calculate the Coordinates where worldEntity Collided with the BSP world.
    10591073  out.x = position1.x + (dest.x -position1.x) * this->outputFraction;
    1060  
    10611074  out.z = position1.z + (dest.z -position1.z) * this->outputFraction;
    10621075  */
    1063  
    1064  
     1076
     1077
    10651078  // Return the normal here: Normal's stored in this->collPlane;
    1066   if( collision) {
     1079  if( collision)
     1080  {
    10671081    PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction);
    10681082    worldEntity->registerCollision(this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out);
    1069   }
     1083  } 
    10701084  else  worldEntity->registerCollision(this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest);
    10711085
     
    11041118      this->drawDebugCube(&this->cam);
    11051119      this->drawDebugCube(&next);
    1106      // State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
     1120      // State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
    11071121      //State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());
    11081122    }
Note: See TracChangeset for help on using the changeset viewer.