Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8490 in orxonox.OLD


Ignore:
Timestamp:
Jun 15, 2006, 9:34:48 PM (18 years ago)
Author:
patrick
Message:

merged the bsp branche back to trunk

Location:
trunk/src
Files:
2 deleted
36 edited
24 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/class_id.h

    r8271 r8490  
    119119  CL_STATE                      =    0x00000013,
    120120  CL_FRAMEWORK                  =    0x00000014,
    121   CL_CR_ENGINE                  =    0x00000015,                ///FIXME bensch i just added this id, verify if this is ok :D
     121  CL_CR_ENGINE                  =    0x00000015,
    122122  CL_RENDER_2D                  =    0x00000021,
    123123  CL_NULL_ELEMENT_2D            =    0x00000022,
     
    191191  CL_TURBINE_HOVER              =    0x0000035f,
    192192  CL_SPECTATOR                  =    0x00000360,
     193  CL_COLLISION_PROBE            =    0x00000361,
    193194
    194195  // Powerups
     
    258259
    259260  /// Collision
    260   CL_COLLISION                  =    0x00000711,
     261  CL_COLLISION                  =    0x00780000,
    261262  CL_COLLISION_HANDLE           =    0x00000712,
    262263  CL_COLLISION_REACTION         =    0X00000713,
     
    264265  CL_CR_PHYSICS_GROUND          =    0X00000715,
    265266  CL_CR_PHYSICS_GROUND_WALK     =    0X00000716,
    266   CL_CR_OBJECT_DAMAGE          =    0X00000717,
     267  CL_CR_OBJECT_DAMAGE           =    0X00000717,
    267268  CL_CR_OBJECT_PICKUP           =    0X00000718,
    268269  CL_CR_VERTEX_TRAFO            =    0X00000719,
     
    277278  CL_OBB                        =    0x00720000,
    278279  CL_BOUNDING_SPHERE            =    0x00740000,
    279  
     280
    280281
    281282
     
    296297  CL_STATIC_MODEL               =    0x00902000,
    297298  CL_VERTEX_ARRAY_MODEL         =    0x00904000,
     299  CL_INTERACTIVE_MODEL          =    0x00908000,        ///FIXME: is this ok bensch?
    298300
    299301  // Models
     
    304306  CL_HEIGHT_MAP                 =    0x0000090a,
    305307  CL_GRID                       =    0x0000090b,
    306   CL_BSP_MODEL                  =    0x0000090c, //!FIXME 
    307  
     308  CL_BSP_MODEL                  =    0x0000090c, //!FIXME
     309
    308310  CL_MATERIAL                   =    0x00000810,
    309311  CL_SHADER                     =    0x00000811,
  • trunk/src/defs/include_paths.am

    r8271 r8490  
    77AM_CXXFLAGS+=-I$(MAINSRCDIR)/lib/event
    88AM_CXXFLAGS+=-I$(MAINSRCDIR)/lib/graphics
     9AM_CXXFLAGS+=-I$(MAINSRCDIR)/lib/graphics/md2
     10AM_CXXFLAGS+=-I$(MAINSRCDIR)/lib/graphics/md3
    911AM_CXXFLAGS+=-I$(MAINSRCDIR)/lib/graphics/text_engine
    1012AM_CXXFLAGS+=-I$(MAINSRCDIR)/lib/graphics/importer
  • trunk/src/lib/collision_detection/cd_engine.cc

    r8316 r8490  
    2020#include "debug.h"
    2121
     22#include "class_list.h"
     23
    2224#include "model.h"
    2325#include "world_entity.h"
     
    3032
    3133#include "bsp_manager.h"
     34#include "bsp_entity.h"
    3235
    3336using namespace std;
     
    97100void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
    98101{
    99   if( likely( this->terrain != NULL))
    100   {
    101 //    Quadtree* q = dynamic_cast<Terrain*>(this->terrain)->ssp->getQuadtree();
    102 //    QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
    103   }
    104102
    105   if( likely( this->bspManager != NULL))
    106   {
    107     std::list<WorldEntity*>::iterator iterator;
    108     PRINTF(3)("checking for collisions\n");
     103  std::list<BaseObject*>::const_iterator bspIterator;
     104  std::list<WorldEntity*>::iterator entityIterator;
     105  const std::list<BaseObject*>* bspList = ClassList::getList(CL_BSP_ENTITY);
     106  if( bspList == NULL)
     107    return;
    109108
    110     iterator = list1.begin();
    111     while (iterator != list1.end())
    112     {
    113       bspManager->checkCollision(*iterator);
    114       iterator++;
    115     }
     109  // for all bsp managers check all entities
     110  for( bspIterator = bspList->begin(); bspIterator != bspList->end(); bspIterator++) {
     111      for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++)
     112      {
     113//         PRINTF(0)("Checking: %s a %s\n", (*entityIterator)->getName(), (*entityIterator)->getClassName());
     114        (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollision(*entityIterator);
     115      }
    116116  }
    117117}
     
    128128  PRINT(0)("=  CDEngine: Spawning Tree: Finished\n");
    129129  PRINT(0)("=======================================================\n");
    130 
    131130}
    132131
     
    149148}
    150149
     150
    151151/**
    152152 * this draws the debug spawn tree
  • trunk/src/lib/collision_reaction/Makefile.am

    r8190 r8490  
    99                     collision_handle.cc \
    1010                     collision_reaction.cc \
    11                      cr_object_damage.cc
     11                     cr_object_damage.cc \
     12                     cr_physics_ground_walk.cc
    1213
    1314
     
    1920                     cr_defs.h \
    2021                     collision_reaction.h \
    21                      cr_object_damage.h
     22                     cr_object_damage.h \
     23                     cr_physics_ground_walk.h
    2224
  • trunk/src/lib/collision_reaction/collision.h

    r8190 r8490  
    2727
    2828    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
    29     inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; }
     29    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; this->bDispatched = false; }
    3030
    3131
     
    4242    /** sets the flag if it reacts @param flag true if it should react on entityB*/
    4343    inline void setEntityBCollide(bool flag) { this->entityACollide = flag; }
     44
    4445
    4546    /** @returns true if this Collision has already been dispatched */
  • trunk/src/lib/collision_reaction/collision_event.h

    r8190 r8490  
    2525  { this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
    2626  /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */
    27   inline void collide(WorldEntity* entity, Plane* ground, Vector position)
    28   { this->entityA = entity; this->ground = ground; this->position = position; }
     27  inline void collide(WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position)
     28  { this->entityA = entity; this->entityB = groundEntity, this->groundNormal = normal; this->position = position; }
    2929
    3030
     
    3838  inline BoundingVolume* getBVB() const { return this->bvB; }
    3939
     40  /** @return ground plane if collided with bsp model */
     41  inline Vector getGroundNormal() { return this->groundNormal; }
    4042
    41   inline void operator()(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) { this->collide(entityA, entityB, bvA, bvB); }
    42   inline void operator()(WorldEntity* entity, Plane* ground, Vector position) { this->collide(entity, ground, position); }
    43 
     43  /** @return position of the position, only accurate if this is a collision with the ground!!! */
     44  inline Vector getCollisionPosition() { return this->position; }
    4445
    4546 private:
     
    5051  BoundingVolume*   bvB;                           //!< reference to the bounding volume B
    5152
    52   Plane*            ground;                        //!< the ground plane with which it collides (only for bsp-model collisions
     53  Vector            groundNormal;                  //!< the ground plane with which it collides (only for bsp-model collisions
    5354  Vector            position;                      //!< position of the collision on the ground plane
    5455};
  • trunk/src/lib/collision_reaction/collision_handle.cc

    r8362 r8490  
    2424
    2525#include "cr_object_damage.h"
     26#include "cr_physics_ground_walk.h"
    2627
    2728#include "debug.h"
     
    4243
    4344  this->bCollided = false;
    44   this->bDispatched = false;
    45 
    46   if( this->type == CREngine::CR_PHYSICS_STEP_BACK)
    47     this->bContinuousPoll = false;
    48   else
    49     this->bContinuousPoll = true;
    50 
    51   if( this->type == CREngine::CR_OBJECT_DAMAGE)
    52     this->bStopOnFirstCollision = true;
    53   else
    54    this->bStopOnFirstCollision = false;
     45  this->bDispatched = true;
     46
     47  this->collisionReaction = NULL;
     48  this->bContinuousPoll = false;
     49  this->bStopOnFirstCollision = false;
     50
    5551
    5652  switch( type)
    5753  {
     54    case CREngine::CR_PHYSICS_STEP_BACK:
     55//       this->collisionReaction = new CRPhysicsGroundWalk();
     56      this->bContinuousPoll = true;
     57      break;
     58    case CREngine::CR_PHYSICS_GROUND_WALK:
     59      this->collisionReaction = new CRPhysicsGroundWalk();
     60      this->bContinuousPoll = true;
     61      break;
    5862    case CREngine::CR_OBJECT_DAMAGE:
    5963      this->collisionReaction = new CRObjectDamage();
     64      this->bStopOnFirstCollision = true;
    6065      break;
    6166    default:
     
    7176{
    7277  // delete what has to be deleted here
     78  if( this->collisionReaction != NULL)
     79    delete this->collisionReaction;
    7380}
    7481
     
    169176
    170177 c->registerCollisionEvent(collisionEvent);
     178 PRINTF(0)("Registering Collision Event: %s, %s\n", collisionEvent->getEntityA()->getClassName(), collisionEvent->getEntityB()->getClassName());
    171179}
    172180
     
    186194void CollisionHandle::handleCollisions()
    187195{
     196  // if continuous poll poll the reaction
     197  if( this->bContinuousPoll && !this->bCollided)
     198  {
     199    this->collisionReaction->update(this->owner);
     200    return;
     201  }
     202
    188203  // collision reaction calculations (for every collision there will be a reaction)
    189204  vector<Collision*>::iterator it = this->collisionList.begin();
     
    214229  {
    215230    if( collisionEvent->getEntityA() == this->owner) {
    216       if( collisionEvent->getEntityA()->isA((ClassID)(*it)))
     231      if( collisionEvent->getEntityB()->isA((ClassID)(*it))) {
     232        PRINTF(0)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(),
     233                  collisionEvent->getEntityB()->getClassName(), *it);
    217234        return true; }
     235    }
    218236    else {
    219       if( collisionEvent->getEntityB()->isA((ClassID)(*it)))
    220         return true; }
     237      if( collisionEvent->getEntityA()->isA((ClassID)(*it))) {
     238        PRINTF(0)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(),
     239                  collisionEvent->getEntityA()->getClassName(), *it);
     240      return true; }
     241    }
    221242  }
    222243
  • trunk/src/lib/collision_reaction/collision_handle.h

    r8190 r8490  
    4141    /** @returns true if this handle should be pulled also if there are no collisions */
    4242    inline bool isContinuousPoll() const { return this->bContinuousPoll; }
     43    /** @returns the type */
     44    inline CREngine::CRType getType() const { return this->type; }
    4345
    4446    void handleCollisions();
  • trunk/src/lib/collision_reaction/collision_reaction.h

    r8190 r8490  
    1212
    1313class Collision;
     14class WorldEntity;
     15
    1416
    1517//! A class representing a simple collision
     
    2325    virtual void reactToCollision(Collision* collision) = 0;
    2426
     27    virtual void update(WorldEntity* owner) {}
     28
     29    /** use this to do some collision offline calculations, only called for bContinuousPoll == true */
    2530    inline bool isContinuousPoll() const { return this->bContinuousPoll; }
    2631
  • trunk/src/lib/collision_reaction/cr_engine.cc

    r8362 r8490  
    126126{
    127127  std::vector<CollisionHandle*>::iterator it;
    128   for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
    129   {
    130     if( *it == collisionHandle)
    131     {
     128  for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)  {
     129    if( *it == collisionHandle) {
    132130      this->collisionHandles.erase(it);
    133131      delete collisionHandle;
     
    147145  for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
    148146  {
    149     if( (*it)->isCollided() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
     147    if( !(*it)->isDispatched() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
    150148    {
    151149      (*it)->handleCollisions();
  • trunk/src/lib/collision_reaction/cr_object_damage.cc

    r8362 r8490  
    5454void CRObjectDamage::reactToCollision(Collision* collision)
    5555{
    56   float damage;
     56  float damage = 0.0f;
    5757
    58   PRINTF(0)("Dealing damage - Handling collision: %s vs %s\n",
     58  PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n",
    5959            collision->getEntityA()->getClassName(),
    6060            collision->getEntityB()->getClassName());
     
    6565    collision->getEntityA()->decreaseHealth(damage);
    6666  }
    67   PRINTF(0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName());
     67  PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName());
    6868
    6969  if( collision->isEntityBCollide()) {
     
    7171    collision->getEntityB()->decreaseHealth(damage);
    7272  }
    73   PRINTF(0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName());
     73  PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName());
    7474
    7575  collision->flushCollisionEvents();
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r8489 r8490  
    2323#include "world_entity.h"
    2424#include "cr_physics_ground_walk.h"
     25
     26#include "debug.h"
    2527
    2628#include <vector>
  • trunk/src/lib/coord/p_node.h

    r8186 r8490  
    103103  /** @returns the absolute position */
    104104  inline const Vector& getAbsCoor () const { return this->absCoordinate; };
     105  /** @returns the absolute position */
     106  inline const Vector& getLastAbsCoor () const { return this->lastAbsCoordinate; };
    105107  void shiftCoor (const Vector& shift);
    106108  void shiftCoor (float x, float y, float z) { this->shiftCoor(Vector(x, y, z)); };
     
    238240    float roty;
    239241    float rotz;
    240    
     242
    241243  private:
    242244    int relCoordinate_handle;
     
    244246    Vector relCoordinate_write;
    245247    Quaternion relDirection_write;
    246    
     248
    247249  public:
    248250    virtual void varChangeHandler( std::list<int> & id );
  • trunk/src/lib/event/event_handler.cc

    r8448 r8490  
    355355  else
    356356  {
    357 //    SDL_WM_GrabInput(SDL_GRAB_ON);
     357    SDL_WM_GrabInput(SDL_GRAB_ON);
    358358    SDL_ShowCursor(SDL_DISABLE);
    359359  }
  • trunk/src/lib/graphics/graphics_engine.cc

    r8316 r8490  
    6666
    6767  this->bDisplayFPS = false;
     68  this->bAntialiasing = false;
    6869  this->minFPS = 9999;
    6970  this->maxFPS = 0;
     
    283284  SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
    284285
    285   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);      //Use at least 5 bits of Red
    286   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);    //Use at least 5 bits of Green
    287   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);     //Use at least 5 bits of Blue
    288   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);   //Use at least 16 bits for the depth buffer
     286  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);      //Use at least 5 bits of Red
     287  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);    //Use at least 5 bits of Green
     288  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);     //Use at least 5 bits of Blue
     289  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);   //Use at least 16 bits for the depth buffer
    289290  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);  //Enable double buffering
     291
     292  // enable antialiasing?
     293  if( this->bAntialiasing)
     294  {
     295    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,4);
     296    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
     297  }
    290298
    291299  glEnable(GL_CULL_FACE);
  • trunk/src/lib/graphics/graphics_engine.h

    r8316 r8490  
    4646    static void setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha = 1.0);
    4747
     48    inline void setAntialiasing(bool flag) { this->bAntialiasing = flag; }
     49    inline bool getAntialiasing() { return this->bAntialiasing; }
    4850
    4951    /** @returns the x resolution */
     
    109111    bool                       shadowsEnabled;     //!< If Shadows should be enabled.
    110112    bool                       particlesEnabled;   //!< If particles should be enabled.
     113    bool                       bAntialiasing;      //!< true if antialiasing enabled
     114
    111115    int                        particlesValue;     //!< How many particles
    112116    int                        textureQuality;     //!< the quality of Textures
  • trunk/src/lib/graphics/importer/Makefile.am

    r8363 r8490  
    55
    66libORXimporter_a_SOURCES = model.cc \
     7                           interactive_model.cc \
     8                           md_model_structure.cc \
    79                           vertex_array_model.cc \
    810                           grid.cc \
     
    1012                           objModel.cc \
    1113                           primitive_model.cc \
    12                            md2Model.cc \
    1314                           height_map.cc \
    1415                           bsp_manager.cc \
     
    2223                           texture_sequence.cc \
    2324                           media_container.cc \
    24                            movie_player.cc
     25                           movie_player.cc \
     26                           \
     27                           bsp_manager.cc \
     28                           bsp_file.cc \
     29                           bsp_tree_node.cc \
     30                           bsp_tree_leaf.cc \
     31                           \
     32                           md2/md2Model.cc \
     33                           \
     34                           md3/md3_model.cc \
     35                           md3/md3_animation.cc \
     36                           md3/md3_bone_frame.cc \
     37                           md3/md3_mesh.cc \
     38                           md3/md3_data.cc \
     39                           md3/md3_tag.cc
    2540
    2641
     
    3247noinst_HEADERS = \
    3348                model.h \
     49                interactive_model.h \
     50                md_model_structure.cc \
    3451                tc.h \
    3552                vertex_array_model.h \
     
    3855                objModel.h \
    3956                primitive_model.h \
    40                 md2Model.h \
    4157                anorms.h \
    4258                anormtab.h \
     
    5470                bsp_file.h \
    5571                bsp_tree_node.h \
    56                 bsp_tree_leaf.h
     72                bsp_tree_leaf.h \
     73                \
     74                md2/md2Model.h \
     75                \
     76                md3/md3_model.h \
     77                md3/md3_animation.h \
     78                md3/md3_bone_frame.h \
     79                md3/md3_mesh.h \
     80                md3/md3_data.h \
     81                md3/md3_tag.h
     82
  • trunk/src/lib/graphics/importer/bsp_file.cc

    r8330 r8490  
    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;
     
    211214    bspFile.read(this->visData, size);
    212215
    213     PRINTF(4)("BSP FILE: VisDataSize: %i Bytes. \n", size);
    214     PRINTF(4)("BSP FILE: NumVisData: %i. \n", size /1 - 8);
    215     PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 1);
    216     PRINTF(4)("BSP FILE: VisDataOffset: %i. \n", offset);
     216    PRINTF(0)("BSP FILE: VisDataSize: %i Bytes. \n", size);
     217    PRINTF(0)("BSP FILE: NumVisData: %i. \n", size /1 - 8);
     218    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 1);
     219    PRINTF(0)("BSP FILE: VisDataOffset: %i. \n", offset);
    217220
    218221    // Get the Textures
     
    388391{
    389392  ::std::string absFileName;
    390   char fileName [228];
    391   char ext [100];
     393  char* baseName = "/worlds/bsp/";
     394
     395  char fileName [500];
     396  char ext [500];
    392397  struct stat results;
    393398
     
    401406    if(strlen(fileName) == 0)
    402407    {
     408
    403409     //         Default Material
    404       this->Materials[i].mat = new Material();
     410    this->Materials[i].mat = new Material();
    405411    this->Materials[i].mat->setDiffuse(0.1,0.1,1.0);
    406412    this->Materials[i].mat->setAmbient(0.1,0.1,1.0 );
     
    417423
    418424      // Check for mov
    419     strcpy(fileName, &this->textures[8+ 72*i]);
     425    strcpy(fileName, baseName);
     426    strcpy(ext, &this->textures[8+ 72*i]);
     427    strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) );
    420428    strcpy(ext, ".mov");
    421     strncat (fileName, ext, strlen(fileName));
     429    strncat (fileName, ext, strlen(fileName) );
     430
     431    PRINTF(0)("BSP FILE: Name %s . \n", fileName);
    422432
    423433    absFileName = ResourceManager::getFullName(fileName);
     
    430440
    431441    // Check for avi
    432     strcpy(fileName, &this->textures[8+ 72*i]);
     442    strcpy(fileName, baseName);
     443    strcpy(ext, &this->textures[8+ 72*i]);
     444    strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) );
    433445    strcpy(ext, ".avi");
    434446    strncat (fileName, ext, strlen(fileName));
     
    443455
    444456       // Check for mpg
    445     strcpy(fileName, &this->textures[8+ 72*i]);
     457    strcpy(fileName, baseName);
     458    strcpy(ext, &this->textures[8+ 72*i]);
     459    strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) );
    446460    strcpy(ext, ".mpg");
    447461    strncat (fileName, ext, strlen(fileName));
     
    456470
    457471    // Check for tga
    458     strcpy(fileName, &this->textures[8+ 72*i]);
     472    strcpy(fileName, baseName);
     473    strcpy(ext, &this->textures[8+ 72*i]);
     474    strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) );
    459475    strcpy(ext, ".tga");
    460476    strncat (fileName, ext, strlen(fileName));
     
    468484    }
    469485    // Check for TGA
    470     strcpy(fileName, &this->textures[8+ 72*i]);
     486    strcpy(fileName, baseName);
     487    strcpy(ext, &this->textures[8+ 72*i]);
     488    strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) );
    471489    strcpy(ext, ".TGA");
    472490    strncat (fileName, ext, strlen(fileName));
     
    479497    }
    480498    // Check for jpg
    481     strcpy(fileName, &this->textures[8+ 72*i]);
     499    strcpy(fileName, baseName);
     500    strcpy(ext, &this->textures[8+ 72*i]);
     501    strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) );
    482502    strcpy(ext, ".jpg");
    483503    strncat (fileName, ext, strlen(fileName));
     
    491511
    492512    // Check for JPG
    493     strcpy(fileName, &this->textures[8+ 72*i]);
     513    strcpy(fileName, baseName);
     514    strcpy(ext, &this->textures[8+ 72*i]);
     515    strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) );
    494516    strcpy(ext, ".JPG");
    495517    strncat (fileName, ext, strlen(fileName));
     
    504526
    505527    // Check for bmp
    506     strcpy(fileName, &this->textures[8+ 72*i]);
     528    strcpy(fileName, baseName);
     529    strcpy(ext, &this->textures[8+ 72*i]);
     530    strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) );
    507531    strcpy(ext, ".bmp");
    508532    strncat (fileName, ext, strlen(fileName));
     
    516540
    517541    // Check for BMP
    518     strcpy(fileName, &this->textures[8+ 72*i]);
     542    strcpy(fileName, baseName);
     543    strcpy(ext, &this->textures[8+ 72*i]);
     544    strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) );
    519545    strcpy(ext, ".BMP");
    520546    strncat (fileName, ext, strlen(fileName));
     
    577603  MoviePlayer * testMC = new MoviePlayer(mat);
    578604  testMC->start(0);
     605 
     606  this->MovieMaterials.push_back(testMC);
    579607
    580608  //Material* tmp = new Material();
     
    605633  sc =  ((unsigned char *)(&lightMapTexture))[i];
    606634  sc *= 1/255.0;
    607   scale = 2.0;
     635
     636  scale = 1.0f; // Adjust brightness here
     637
    608638  if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp;
    609639  scale*=255.0;
  • trunk/src/lib/graphics/importer/bsp_file.h

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

    r8186 r8490  
    3939#include "movie_player.h"
    4040
    41 #include "cd_engine.h"
    42 
    4341#include "world_entity.h"
    4442
     
    4745
    4846
     47
    4948//CREATE_FACTORY( BspManager, CL_BSP_MODEL);
    5049
    51 BspManager::BspManager()
    52 {
     50BspManager::BspManager(WorldEntity* parent)
     51{
     52 
     53  this->parent = parent;
    5354  /*// open a BSP file
    5455  this->bspFile = new BspFile();
     
    5960  this->alreadyVisible = new bool [this->bspFile->numFaces];
    6061  */
    61   CDEngine::getInstance()->setBSPModel(this);
     62
    6263}
    6364
     
    7677void BspManager::load(const char* fileName, float scale)
    7778{
    78   //this->setClassID(CL_BSP_MODEL, "BspManager");
    79     // open a BSP file
     79  // open a BSP file
    8080  this->bspFile = new BspFile();
    8181  this->bspFile->scale =  scale;
     
    8585  this->alreadyVisible = new bool [this->bspFile->numFaces];
    8686
    87 
     87  this->outputFraction = 1.0f;
    8888}
    8989/*
     
    102102*/
    103103
     104const void BspManager::tick(float time)
     105{
     106
     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 );
     116
     117
     118  }
     119
     120}
    104121const void BspManager::draw()
    105122{
     
    109126  this->out1 = this->out;
    110127  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;
     128  if(this->collPlane != NULL) {
     129    this->out1.x += this->collPlane->x*5.0;
     130    this->out1.y += this->collPlane->y*5.0;
     131    this->out1.z += this->collPlane->z*5.0;
     132
     133    this->out2.x += this->collPlane->x*10.0;
     134    this->out2.y += this->collPlane->y*10.0;
     135    this->out2.z += this->collPlane->z*10.0;
    120136  }
    121137  this->drawDebugCube(&this->out1);
    122138  this->drawDebugCube(&this->out2);
     139
    123140  */
     141
     142
    124143  // Draw Debug Terrain
    125144  /*
     
    148167
    149168
    150   // this->viewDir=    State::getCameraTarget()->getAbsCoor() -  State::getCamera()->getAbsCoor() ;
     169  this->viewDir=    State::getCamera()->getAbsDirX();
    151170  float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z);
    152171
     
    157176
    158177
    159   this->cam = State::getCameraTargetNode()->getAbsCoor();
    160   // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
     178
     179 // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
     180
     181
    161182  this->outputStartsOut = true;
    162183  this->outputAllSolid = false;
    163184  this->outputFraction = 1.0f;
    164185
    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);
    168 
    169186  if ( viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0 )  //!< if (sizeof(Visdata) == 0)
    170187  {
     
    172189
    173190
    174     // Iterate through all Leafspublic final double readLEDouble()
     191    // Iterate through all Leafs
    175192    for(int i = 0; i <  this->bspFile->numLeafs   ; i++ )
    176193    {
     
    179196      if(curLeaf.cluster<0) continue;
    180197
    181 
    182198      /** 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;
     199
     200      Vector dir = State::getCameraNode()->getAbsDirX();
     201
    189202      float dist =  dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z;
    190203      //if(dist < 0) dist = -dist;
     
    192205      const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist ;
    193206
    194       if(dMins < -150.0 && dMaxs < -150.0) {
     207      if(dMins < -300.0 && dMaxs < -300.0) {
    195208        continue;
    196209      }
    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) {
     210      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) {
    198211        continue;
    199212      }
     
    206219        if (f >=0 && !this->isAlreadyVisible(f)) {
    207220          this->alreadyVisible[f] = true;
    208 
    209221          addFace(f); // "visibleFaces.append(f)"
    210222        }
     
    302314    return;
    303315  }
    304   if(curFace.type != 1) return;
     316 // if(curFace.type != 1) return;
    305317  if((char*)(this->bspFile->textures)[curFace.texture*72]== 0) return;
    306318
    307319  if(this->lastTex != curFace.texture) {
    308320    if(this->bspFile->Materials[curFace.texture].animated) {
    309       glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);
    310       glEnable(GL_BLEND);
     321     // glBlendFunc(GL_ZERO,GL_ONE);
     322
     323
     324
    311325      if(this->bspFile->Materials[curFace.texture].aviMat->getStatus() == 2) this->bspFile->Materials[curFace.texture].aviMat->start(0);
    312       this->bspFile->Materials[curFace.texture].aviMat->tick(0.005);
     326      //this->bspFile->Materials[curFace.texture].aviMat->tick(0.005);
    313327      int n =  this->bspFile->Materials[curFace.texture].aviMat->getTexture();
    314328      glActiveTextureARB(GL_TEXTURE0_ARB);
    315329      glBindTexture(GL_TEXTURE_2D, n );
    316       glDisable(GL_BLEND);
     330      this->lastTex = curFace.texture;
     331
    317332    } else {
    318333      this->bspFile->Materials[curFace.texture].mat->select();
     
    322337
    323338  if(curFace.lm_index < 0) {
     339    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    324340    glActiveTextureARB(GL_TEXTURE1_ARB);
    325341    glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap );
    326342    glEnable(GL_TEXTURE_2D);
    327343  } else {
     344   // glEnable(GL_BLEND);
     345    //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
     346    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    328347    glActiveTextureARB(GL_TEXTURE1_ARB);
    329348    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[curFace.lm_index]);
    330349    glEnable(GL_TEXTURE_2D);
     350  //  glDisable(GL_BLEND);
    331351  }
    332352
     
    573593  float startFraction = -1.0f;
    574594  float endFraction = 1.0f;
    575   bool startsOut = false;
    576   bool endsOut = false;
    577 
    578   Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
    579   Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
     595  bool  startsOut = false;
     596  bool  endsOut = false;
     597
     598 // Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
     599 // Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
     600
     601  for (int i = 0; i < curBrush->n_brushsides; i++) {
     602    brushside& curBrushSide =   this->bspFile->brushSides[curBrush->brushside + i]   ;
     603    plane& curPlane  =   this->bspFile->planes[curBrushSide.plane] ;
     604
     605    startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d;
     606    endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d;
     607
     608    if (startDistance > 0)
     609      startsOut = true;
     610    if (endDistance > 0)
     611      endsOut = true;
     612
     613    // make sure the trace isn't completely on one side of the brush
     614    if (startDistance > 0 && endDistance > 0) {   // both are in front of the plane, its outside of this brush
     615      return;
     616    }
     617    if (startDistance <= 0 && endDistance <= 0) {   // both are behind this plane, it will get clipped by another one
     618      continue;
     619    }
     620
     621    // MMM... BEEFY
     622    if (startDistance > endDistance) {   // line is entering into the brush
     623      float fraction = (startDistance - EPSILON) / (startDistance - endDistance);  // *
     624      if (fraction > startFraction)
     625        startFraction = fraction;
     626      // store plane
     627      this->collPlane = &curPlane;
     628
     629    } else {   // line is leaving the brush
     630      float fraction = (startDistance + EPSILON) / (startDistance - endDistance);  // *
     631      if (fraction < endFraction)
     632        endFraction = fraction;
     633      // store plane
     634      this->collPlane = & curPlane;
     635
     636    }
     637
     638  }
     639  if (startsOut == false) {
     640    this->outputStartsOut = false;
     641    if (endsOut == false)
     642      this->outputAllSolid = true;
     643    return;
     644  }
     645
     646  if (startFraction < endFraction) {
     647    if (startFraction > -1.0f && startFraction < outputFraction) {
     648      if (startFraction < 0)
     649        startFraction = 0;
     650      this->outputFraction = startFraction;
     651    }
     652  }
     653
     654}
     655
     656void BspManager::checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd)
     657{
     658  float EPSILON = 0.000001;
     659  float startDistance;
     660  float endDistance;
     661
     662  float startFraction = -1.0f;
     663  float endFraction = 1.0f;
     664  bool  startsOut = false;
     665  bool  endsOut = false;
     666
     667  //Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
     668  //Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
    580669
    581670  for (int i = 0; i < curBrush->n_brushsides; i++) {
     
    736825
    737826  float EPSILON = 0.000001;
    738   float  endDistance = (end)->x * (node->plane.x) +(end)->y * (node->plane.y) +(end)->z * (node->plane.z)  - node->d;
    739   float  startDistance = (start)->x * (node->plane.x)+ (start)->y * (node->plane.y)+ (start)->z * (node->plane.z)- node->d;
    740 
    741 
    742   if(node->isLeaf) {
     827
     828  float endDistance = end->dot(node->plane) - node->d;
     829  float startDistance = start->dot(node->plane) - node->d;
     830
     831
     832  if( node->isLeaf) {
    743833    leaf& curLeaf = this->bspFile->leaves[node->leafIndex];
    744834    for (int i = 0; i <  curLeaf.n_leafbrushes ; i++) {
     
    793883
    794884    // STEP 3: calculate the middle point for the first side
    795     middleFraction = startFraction +
    796         (endFraction - startFraction) * fraction1;
    797 
    798     middle.x = start->x + fraction1 * (end->x - start->x);
    799     middle.y = start->y + fraction1 * (end->y - start->y);
    800     middle.z = start->z + fraction1 * (end->z - start->z);
     885    middleFraction = startFraction + (endFraction - startFraction) * fraction1;
     886    middle = (*start) + ((*end) - (*start)) * fraction1;
     887
    801888
    802889    // STEP 4: check the first side
     
    805892
    806893    else this->checkCollisionRayN(node->right,startFraction, middleFraction,
    807                                  start, &middle );
     894                                    start, &middle );
    808895
    809896    // STEP 5: calculate the middle point for the second side
    810     middleFraction = startFraction +
    811         (endFraction - startFraction) * fraction2;
    812 
    813     middle.x = start->x + fraction2 * (end->x - start->x);
    814     middle.y = start->y + fraction2 * (end->y - start->y);
    815     middle.z = start->z + fraction2 * (end->z - start->z);
     897    middleFraction = startFraction + (endFraction - startFraction) * fraction2;
     898    middle = (*start) + ((*end) - (*start)) * fraction2;
    816899
    817900    // STEP 6: check the second side
     
    824907
    825908}
     909void BspManager::checkCollisionBox(void)
     910{
     911
     912};
     913
     914void BspManager::TraceBox( Vector& inputStart, Vector& inputEnd,
     915               Vector& inputMins, Vector& inputMaxs )
     916{
     917  if (inputMins.x == 0 && inputMins.y == 0 && inputMins.z == 0 &&
     918      inputMaxs.x == 0 && inputMaxs.y == 0 && inputMaxs.z == 0)
     919  {   // the user called TraceBox, but this is actually a ray
     920   //!> FIXME TraceRay( inputStart, inputEnd );
     921  }
     922  else
     923  {   // setup for a box
     924    //traceType = TT_BOX;
     925    this->traceMins = inputMins;
     926    this->traceMaxs = inputMaxs;
     927    this->traceExtents.x = -traceMins.x > traceMaxs.x ?
     928        -traceMins.x : traceMaxs.x;
     929    this->traceExtents.y = -traceMins.y > traceMaxs.y ?
     930        -traceMins.y : traceMaxs.y;
     931    this->traceExtents.z = -traceMins.z > traceMaxs.z ?
     932        -traceMins.z : traceMaxs.z;
     933   //!> FIXME Trace( inputStart, inputEnd );
     934  }
     935}
    826936
    827937void BspManager::checkCollision(WorldEntity* worldEntity)
    828938{
    829   return;
    830 
     939 
     940  this->outputStartsOut = true;
     941  this->outputAllSolid = false;
     942  this->outputFraction = 1.0f;
     943 
    831944  Vector position = worldEntity->getAbsCoor();
    832945
    833946
    834947  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;
     948  forwardDir = forwardDir * 8.0f;
    838949
    839950  Vector upDir = worldEntity->getAbsDirY();
    840   Vector dest = position;
     951  upDir.x = 0.0;
     952  upDir.y = 1.0;
     953  upDir.z = 0.0;
     954  Vector dest;
     955  /*
    841956  dest.x  += forwardDir.x;
    842957  dest.y  += forwardDir.y;
    843958  dest.z  += forwardDir.z;
    844   Vector out = Vector(-1875.0,-1875.0,-1875.0);
    845   if(!worldEntity->isA(CL_PLAYABLE)) {
    846 
    847 
    848 
    849 
     959  */
     960
     961  dest = worldEntity->getAbsCoor() - upDir*40.0;
     962  Vector out = dest;
     963
     964
     965
     966
     967  bool collision = false;
     968  Vector position1 = position + Vector(0.0,0.1,0.0);
     969  Vector position2 = position + Vector(0.0,0.2,0.0);
     970  Vector dest1 = position1 + forwardDir;
     971  Vector dest2 = position2 + forwardDir;
     972  dest = position - Vector(0.0, 40.0,0.0);
     973  Vector out1;
     974  Vector out2;
     975
     976
     977  float height = 40;
     978 
     979  this->inputStart =  position;
     980  this->inputEnd =   dest;
     981  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
     982
     983  PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction);
     984  PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z);
     985  PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z); 
     986//   position1.debug();
     987
     988  if( this->outputFraction == 1.0f)
     989  {
     990    if(this->outputAllSolid)
     991    {
     992      this->collPlane = new plane;
     993      this->collPlane->x = 1.0f;
     994      this->collPlane->y = 0.0f;
     995      this->collPlane->z = 0.0f;
     996      collision = true;
     997    }
     998    else
     999      collision = false;
     1000
     1001
     1002    out = dest;
    8501003  }
    8511004  else {
    852     bool collision = false;
    853     Vector position1 = position + Vector(0.0,0.1,0.0);
    854     Vector position2 = position + Vector(0.0,0.2,0.0);
    855     Vector dest1 = position1 + forwardDir;
    856     Vector dest2 = position2 + forwardDir;
    857     dest = position - upDir;
    858     Vector out1;
    859     Vector out2;
    860 
    861     this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 );
    862     if(this->outputFraction == 1.0f)  out1 = dest;
    863     else {
    864       collision = true;
    865       out1.x = position1.x + (dest1.x -position1.x) * this->outputFraction;
    866       out1.y = position1.y + (dest1.y -position1.y) * this->outputFraction;
    867       out1.z = position1.z + (dest1.z - position1.z) * this->outputFraction;
    868 
    869     }
    870 
    871     this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 );
    872     if(this->outputFraction == 1.0f) out2= dest;
    873     else
    874     {
    875       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;
    879 
    880     }
    881 
    882     this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
    883     if(this->outputFraction == 1.0f) out = dest;
    884     else
    885     {
     1005
    8861006    collision = true;
    8871007    out.x = position.x + (dest.x -position.x) * this->outputFraction;
     
    8891009    out.z = position.z + (dest.z -position.z) * this->outputFraction;
    8901010
    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);
    899 
    900     }
    901 
    902     // Return the normal here: Normal's stored in this->collPlane;
    903 //    if(collision) worldEntity->collidesWithGround(out,out1,out2);
    904 
    905   }
    906 
    907 }
     1011    Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z);
     1012    this->out = out;
     1013  }
     1014
     1015  // Return the normal here: Normal's stored in this->collPlane;
     1016  if( collision) {
     1017    PRINTF(0)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction);
     1018    worldEntity->registerCollision(this->parent, worldEntity, Vector(this->collPlane->x, this->collPlane->y, this->collPlane->z), out);
     1019  }
     1020
     1021}
     1022
    9081023
    9091024void  BspManager::checkCollision(BspTreeNode* node, Vector* cam)
     
    9381053      this->drawDebugCube(&this->cam);
    9391054      this->drawDebugCube(&next);
    940       State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
    941       State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());
     1055     // State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
     1056      //State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());
    9421057    }
    9431058
  • trunk/src/lib/graphics/importer/bsp_manager.h

    r8186 r8490  
    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/
    2020*/
    2121
     22#ifndef _BSP_MANAGER_H
     23#define _BSP_MANAGER_H
     24
     25
    2226#include <vector>
    2327#include <deque>
     28
     29
    2430
    2531// FORWARD DECLARATIONS
     
    4551public:
    4652  // Constructors
    47   BspManager();
    48  
     53  BspManager(WorldEntity* parent);
     54
    4955  BspManager(const char* fileName, float scale = 0.4f);
    5056  void load(const char* fileName, float scale);
     
    5258  // Functions
    5359  const void draw();
    54   void draw_debug_face(int Face);
     60  const void tick(float time);
     61  void draw_debug_face(int Face);
    5562  void draw_face(int Face);
    5663  void draw_patch(face* Face);
    57  
    5864
    59   void checkCollision(WorldEntity* worldEntity);
     65
     66  void checkCollision(WorldEntity* worldEntity); /*!< WorldEntities use this function to check wheter they collided with the BspEntity.
     67                                                      If a collision has been detected, the collides-function of worldEntity will be called.*/
    6068
    6169private:
    6270  // Functions
    6371  BspTreeNode* getLeaf(BspTreeNode*  node,   Vector* cam) ;  //!< Traverses the tree
    64   void  checkCollision(BspTreeNode* node, Vector* cam);
    65   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);
     72  void  checkCollision(BspTreeNode* node, Vector* cam); //!< Obsolete. Use this function for debugging only!
     73  void  checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
     74  void  checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
     75  void TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
     76  void  checkCollisionBox(void);
    6777  void  checkBrushRay(brush* curBrush);
    6878  void  checkBrushRayN(brush* curBrush);
     79  void   checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd);
     80
    6981  void drawDebugCube(Vector* cam);
    7082  bool isAlreadyVisible(int Face);
    7183  void addFace(int Face);
    72  
     84
    7385  // Data
    7486  BspFile*  bspFile;
     
    7991  plane* collPlane;
    8092  int lastTex;
    81  
    82   //obsolete
     93
     94  //obsolete: global variables for collision detection
    8395  bool  outputStartsOut;
    8496  bool  outputAllSolid;
    8597  float outputFraction;
     98  Vector inputStart;
     99  Vector inputEnd;
    86100 
     101  Vector traceMins; //!< Mins of current bbox
     102  Vector traceMaxs; //!< Maxs of current bbox
     103  Vector traceExtents; /*!< Stores the maximum of the absolute value of each axis in the box.
     104                            For example, if traceMins was (-100,-3,-15) and traceMaxs was (55,22,7), traceExtents */
     105
     106  WorldEntity* parent;          //!< the parent entity of the bspManager: interface to this
     107
    87108  bool * alreadyVisible;
    88109  // Deques to store the visible faces
     
    90111  ::std::deque<int> opal; //!< the others here.
    91112
    92   Vector out;
    93   Vector out1;
    94   Vector out2;
     113  Vector out;  //!< For debugging only
     114  Vector out1; //!< For debugging only
     115  Vector out2; //!< For debugging only
     116                       
     117  int tgl;
    95118};
    96119
     120#endif /* _BSP_MANAGER_H */
  • trunk/src/lib/graphics/importer/md3/md3_data.cc

    r8489 r8490  
    2323#include "material.h"
    2424
     25#include "debug.h"
    2526
    2627namespace md3
  • trunk/src/lib/math/vector.h

    r8293 r8490  
    4646  /** @param v: the Vecor to compare with this one @returns true, if the Vecors are the same, false otherwise */
    4747  inline bool operator== (const Vector& v) const { return (this->x==v.x&&this->y==v.y&&this->z==v.z)?true:false; };
     48  /** @param v: the Vecor to compare with this one @returns true, if the Vecors are different, false otherwise */
     49  inline bool operator!= (const Vector& v) const { return (this->x!=v.x&&this->y!=v.y&&this->z!=v.z)?true:false; };
    4850  /** @param index The index of the "array" @returns the x/y/z coordinate */
    4951  inline float operator[] (float index) const {if( index == 0) return this->x; if( index == 1) return this->y; if( index == 2) return this->z; }
  • trunk/src/lib/util/loading/resource_manager.cc

    r8330 r8490  
    2727#include "objModel.h"
    2828#include "primitive_model.h"
    29 #include "md2Model.h"
     29#include "md2/md2Model.h"
    3030#endif /* NO_MODEL */
    3131#ifndef NO_TEXTURES
  • trunk/src/story_entities/game_world.cc

    r8408 r8490  
    299299    /* process time */
    300300    this->tick ();
     301
    301302    /* collision detection */
    302303    this->collisionDetection ();
    303304    /* collision reaction */
    304305    this->collisionReaction ();
     306
    305307    /* update the state */
    306308    this->update ();
     309
    307310    /* check the game rules */
    308311    this->checkGameRules();
     
    434437void GameWorld::collisionDetection()
    435438{
     439  // object-object collision detection
    436440  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00),
    437441      this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ));
     
    446450      this->dataTank->objectManager->getObjectList(OM_COMMON));
    447451
     452  // ground collision detection: BSP Model
     453  CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_00));
     454  CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_01));
    448455}
    449456
  • trunk/src/story_entities/game_world_data.cc

    r7810 r8490  
    3333#include "terrain.h"
    3434#include "skybox.h"
    35 #include "md2Model.h"
     35#include "md2/md2Model.h"
    3636#include "world_entities/projectiles/projectile.h"
    3737#include "npcs/npc_test1.h"
  • trunk/src/story_entities/multi_player_world_data.cc

    r8068 r8490  
    3434#include "test_entity.h"
    3535#include "terrain.h"
    36 #include "md2Model.h"
     36#include "md2/md2Model.h"
    3737#include "world_entities/projectiles/projectile.h"
    3838#include "npcs/npc_test1.h"
  • trunk/src/subprojects/collision_detection/collision_detection.cc

    r7841 r8490  
    2525#include "bv_tree.h"
    2626
    27 #include "md2Model.h"
     27#include "md2/md2Model.h"
    2828#include "model.h"
    2929#include "collision_test_entity.h"
  • trunk/src/subprojects/importer/importer.cc

    r7193 r8490  
    2121
    2222#include "objModel.h"
    23 #include "md2Model.h"
     23#include "md2/md2Model.h"
    2424#include "primitive_model.h"
    2525#include <stdlib.h>
  • trunk/src/world_entities/WorldEntities.am

    r8271 r8490  
    1515                world_entities/test_entity.cc \
    1616                world_entities/planet.cc \
    17                 world_entities/bsp_entity.cc \
     17                world_entities/bsp_entity.cc \
    1818                \
    1919                world_entities/weapons/test_gun.cc \
     
    3939                world_entities/space_ships/hover.cc \
    4040                world_entities/space_ships/turbine_hover.cc \
     41                world_entities/space_ships/collision_probe.cc \
    4142                world_entities/creatures/md2_creature.cc \
    4243                world_entities/spectator.cc \
     
    7071                test_entity.h \
    7172                planet.h \
    72                 bsp_entity.h \
     73                bsp_entity.h \
    7374                \
    7475                weapons/test_gun.h \
     
    9495                space_ships/hover.h \
    9596                space_ships/turbine_hover.h \
     97                space_ships/collision_probe.cc \
    9698                creatures/md2_creature.h \
    9799                spectator.h \
  • trunk/src/world_entities/bsp_entity.cc

    r8186 r8490  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Claudio Botta
    1313   co-programmer: ...
    1414*/
     
    1717#include "util/loading/resource_manager.h"
    1818
    19 CREATE_FACTORY(BSPEntity, CL_BSP_ENTITY);
     19CREATE_FACTORY(BspEntity, CL_BSP_ENTITY);
    2020
    2121
    2222/**
    23  * constructs and loads a BSPEntity from a XML-element
     23 * constructs and loads a BspEntity from a XML-element
    2424 * @param root the XML-element to load from
    2525 */
    26 BSPEntity::BSPEntity(const TiXmlElement* root)
     26BspEntity::BspEntity(const TiXmlElement* root)
    2727{
    2828  this->init();
     29
    2930  if (root != NULL)
    3031    this->loadParams(root);
     
    3536 * standard deconstructor
    3637 */
    37 BSPEntity::~BSPEntity ()
     38BspEntity::~BspEntity ()
    3839{
    39 
     40  if( this->bspManager)
     41    delete this->bspManager;
    4042}
    4143
    42 void BSPEntity::setName(const std::string& name)
     44
     45/**
     46 * initializes the BspEntity
     47 * @todo change this to what you wish
     48 */
     49void BspEntity::init()
    4350{
    44   printf("+++++++++++ LOADING NAME %s\n", name.c_str());
     51  this->setClassID(CL_BSP_ENTITY, "BspEntity");
     52
     53  this->bspManager = new BspManager(this);
     54  this->toList(OM_ENVIRON);
     55
     56  /**
     57   * @todo: Write CL_BSP_ENTITY INTO THE src/defs/class_id.h (your own definition)
     58   */
     59}
     60
     61
     62void BspEntity::setName(const std::string& name)
     63{
     64  PRINTF(0)("+++++++++++ LOADING NAME %s\n", name.c_str());
    4565
    4666  this->bspManager->load(name.c_str(), 0.1f);
     
    4868
    4969
    50 
    5170/**
    52  * initializes the BSPEntity
    53  * @todo change this to what you wish
    54  */
    55 void BSPEntity::init()
    56 {
    57   this->bspManager = new BspManager();
    58   this->setClassID(CL_BSP_ENTITY, "BSPEntity");
    59 
    60   this->toList(OM_ENVIRON);
    61 
    62   /**
    63    * @todo: Write CL_BSP_ENTITY INTO THE src/defs/class_id.h (your own definition)
    64    */
    65 
    66 }
    67 
    68 
    69 /**
    70  * loads a BSPEntity from a XML-element
     71 * loads a BspEntity from a XML-element
    7172 * @param root the XML-element to load from
    7273 * @todo make the class Loadable
    7374 */
    74 void BSPEntity::loadParams(const TiXmlElement* root)
     75void BspEntity::loadParams(const TiXmlElement* root)
    7576{
    7677  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
    7778 // WorldEntity::loadParam(root);
    7879
    79   LoadParam(root, "Name", this, BSPEntity, setName)
     80  LoadParam(root, "Name", this, BspEntity, setName)
    8081      .describe("Sets the of the BSP file.");
    8182
     
    9192
    9293/**
    93  * advances the BSPEntity about time seconds
     94 * advances the BspEntity about time seconds
    9495 * @param time the Time to step
    9596 */
    96 void BSPEntity::tick(float time)
     97void BspEntity::tick(float time)
    9798{
    98 
     99  this->bspManager->tick(time);
    99100}
    100101
     
    103104 * draws this worldEntity
    104105 */
    105 void BSPEntity::draw () const
     106void BspEntity::draw () const
    106107{
    107108  this->bspManager->draw();
     
    113114 *
    114115 */
    115 void BSPEntity::collidesWith (WorldEntity* entity, const Vector& location)
     116void BspEntity::collidesWith (WorldEntity* entity, const Vector& location)
    116117{
    117118
  • trunk/src/world_entities/bsp_entity.h

    r8186 r8490  
    1616
    1717//! A Class to ...
    18 class BSPEntity : public WorldEntity
     18class BspEntity : public WorldEntity
    1919{
    20  
     20
    2121 public:
    22   BSPEntity(const TiXmlElement* root = NULL);
    23   virtual ~BSPEntity();
     22  BspEntity(const TiXmlElement* root = NULL);
     23  virtual ~BspEntity();
    2424
    2525  virtual void loadParams(const TiXmlElement* root);
    26  
     26
    2727  void setName(const std::string& name);
    2828
     
    3333  virtual void collidesWith (WorldEntity* entity, const Vector& location);
    3434
     35  /** @returns the BspManager of this entity */
     36  inline BspManager* getBspManager() { return this->bspManager; }
     37
    3538 private:
    3639   BspManager* bspManager;
  • trunk/src/world_entities/creatures/md2_creature.cc

    r8362 r8490  
    2121
    2222#include "objModel.h"
    23 #include "md2Model.h"
     23#include "md2/md2Model.h"
    2424#include "util/loading/resource_manager.h"
    2525#include "state.h"
     
    256256  if( this->bJump && likely(this->getModel(0) != NULL))
    257257  {
    258     ((MD2Model*)this->getModel(0))->setAnim(JUMP);
     258    ((MD2Model*)this->getModel(0))->setAnimation(JUMP);
    259259  }
    260260  else if( this->bFire && likely(this->getModel(0) != NULL))
    261261  {
    262     if( ((MD2Model*)this->getModel(0))->getAnim() != ATTACK) ((MD2Model*)this->getModel(0))->setAnim(ATTACK);
     262    if( ((MD2Model*)this->getModel(0))->getAnim() != ATTACK) ((MD2Model*)this->getModel(0))->setAnimation(ATTACK);
    263263  }
    264264  else if( fabs(move.len()) > 0.0f && likely(this->getModel(0) != NULL))
    265265  {
    266     if( ((MD2Model*)this->getModel(0))->getAnim() != RUN) ((MD2Model*)this->getModel(0))->setAnim(RUN);
     266    if( ((MD2Model*)this->getModel(0))->getAnim() != RUN) ((MD2Model*)this->getModel(0))->setAnimation(RUN);
    267267  }
    268268  else if (likely(this->getModel(0) != NULL))
    269269  {
    270     if( ((MD2Model*)this->getModel(0))->getAnim() != STAND) ((MD2Model*)this->getModel(0))->setAnim(STAND);
     270    if( ((MD2Model*)this->getModel(0))->getAnim() != STAND) ((MD2Model*)this->getModel(0))->setAnimation(STAND);
    271271  }
    272272
  • trunk/src/world_entities/playable.cc

    r8316 r8490  
    6565
    6666  this->bDead = false;
     67
     68  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
    6769
    6870  registerVar( new SynchronizeableInt( &score, &score, "score" ) );
  • trunk/src/world_entities/space_ships/turbine_hover.h

    r7348 r8490  
    5959    float                 rotation;
    6060
    61     Vector                velocity;           //!< the velocity of the TurbineHover.
     61   // Vector                velocity;           //!< the velocity of the TurbineHover.
    6262    Quaternion            direction;          //!< the direction of the TurbineHover.
    6363    float                 travelSpeed;        //!< the current speed of the Hove (to make soft movement)
  • trunk/src/world_entities/test_entity.cc

    r8316 r8490  
    2626
    2727#include "test_entity.h"
    28 #include "stdincl.h"
    29 #include "model.h"
    30 #include "md2Model.h"
    31 #include "obb_tree.h"
     28
     29
     30#include "interactive_model.h"
     31#include "md2/md2Model.h"
     32
    3233#include "state.h"
    3334
     
    9091{
    9192  if( likely(this->getModel(0) != NULL))
    92     ((MD2Model*)this->getModel(0))->setAnim(animationIndex, animPlaybackMode);
     93    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
    9394}
    9495
     
    9798{
    9899  if( likely(this->getModel(0) != NULL))
    99     ((MD2Model*)this->getModel(0))->tick(time);
     100    ((InteractiveModel*)this->getModel(0))->tick(time);
    100101
    101102}
  • trunk/src/world_entities/world_entity.cc

    r8316 r8490  
    2121
    2222#include "model.h"
    23 #include "md2Model.h"
     23#include "md2/md2Model.h"
     24#include "md3/md3_model.h"
     25
    2426#include "util/loading/resource_manager.h"
    2527#include "util/loading/load_param.h"
     
    7779
    7880  // registering default reactions:
    79   this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY);
    80   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND, CL_TERRAIN);
     81//   this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY);
    8182
    8283  this->toList(OM_NULL);
     
    200201        this->buildObbTree(obbTreeDepth);
    201202    }
     203    else if(fileName.find(".md3") != std::string::npos)
     204    {
     205      PRINTF(4)("fetching MD3 file: %s\n", fileName.c_str());
     206      Model* m = new md3::MD3Model(fileName, this->scaling);
     207      this->setModel(m, 0);
     208
     209//       if( m != NULL)
     210//         this->buildObbTree(obbTreeDepth);
     211    }
    202212  }
    203213  else
     
    411421 *  @param position it collides on the plane
    412422 */
    413 bool WorldEntity::registerCollision(WorldEntity* entity, Plane* plane, Vector position)
     423bool WorldEntity::registerCollision(WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position)
    414424{
    415425  // is there any handler listening?
     
    420430  CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
    421431  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
    422   c->collide(entity, plane, position);
     432  c->collide(entity, groundEntity, normal, position);
    423433
    424434  for( int i = 0; i < CREngine::CR_NUMBER; ++i)
     
    501511
    502512  Vector v = this->getAbsDirX();
    503   v.x *= 10;
    504   v.y *= 10;
    505   v.z *= 10;
    506   Vector u = this->getAbsDirY();
    507 
    508   if(feet.x == (u.x+this->getAbsCoor().x) &&  feet.y == u.y +this->getAbsCoor().y && feet.z == this->getAbsCoor().z)
     513  v.x *= 10.1;
     514  v.y *= 10.1;
     515  v.z *= 10.1;
     516  Vector u = Vector(0.0,-20.0,0.0);
     517
     518
     519  if(!(this->getAbsCoor().x == ray_2.x && this->getAbsCoor().y == ray_2.y && this->getAbsCoor().z == ray_2.z) )
    509520  {
    510521
    511522  this->setAbsCoor(ray_2 - v);
    512   }
    513   else
     523
     524  }
     525    else
    514526  {
    515527    if(ray_1.x == this->getAbsCoor().x + v.x && ray_1.y == this->getAbsCoor().y + v.y + 0.1 && ray_1.z ==this->getAbsCoor().z + v.z)
     
    521533
    522534  }
     535
     536
    523537}
    524538
  • trunk/src/world_entities/world_entity.h

    r8190 r8490  
    2929class CollisionHandle;
    3030class Collision;
    31 class Plane;
    3231
    3332
     
    8685
    8786  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
    88   bool registerCollision(WorldEntity* entity, Plane* plane, Vector position);
     87  bool registerCollision(WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position);
    8988  /** @return true if there is at least on collision reaction subscribed */
    9089  inline bool isReactive() const { return this->bReactive; }
     
    138137  inline float getMass() const { return this->physicsInterface.getMass(); }
    139138  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
     139  inline void setVelocity(const Vector& vel) { this->velocity = vel; }
    140140
    141141
     
    187187  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
    188188
     189
     190  protected:
     191  Vector                  velocity;                        //!< speed of the entity
     192
    189193};
    190194
Note: See TracChangeset for help on using the changeset viewer.