Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8190 in orxonox.OLD for trunk/src/world_entities/world_entity.cc


Ignore:
Timestamp:
Jun 7, 2006, 3:00:01 PM (18 years ago)
Author:
patrick
Message:

trunk: merged the cr branche to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/world_entity.cc

    r8186 r8190  
    3232#include "camera.h"
    3333
    34 #include "cr_engine.h"
    3534#include "collision_handle.h"
     35#include "collision_event.h"
     36
     37#include <stdarg.h>
    3638
    3739
     
    5961  this->healthMax = 1.0f;
    6062  this->health = 1.0f;
     63  this->damage = 0.0f; // no damage dealt by a default entity
    6164  this->scaling = 1.0f;
    6265
     
    6871  this->objectListIterator = NULL;
    6972
     73  // reset all collision handles to NULL == unsubscribed state
     74  for(int i = 0; i < CREngine::CR_NUMBER; ++i)
     75    this->collisionHandles[i] = NULL;
     76  this->bReactive = false;
     77
     78  // registering default reactions:
     79  this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY);
     80  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND, CL_TERRAIN);
     81
    7082  this->toList(OM_NULL);
    7183
     
    91103  if (this->healthWidget != NULL)
    92104    delete this->healthWidget;
     105
     106  this->unsubscribeReaction();
    93107}
    94108
     
    249263 * subscribes this world entity to a collision reaction
    250264 *  @param type the type of reaction to subscribe to
     265 *  @param target1 a filter target (classID)
     266 */
     267void WorldEntity::subscribeReaction(CREngine::CRType type, long target1)
     268{
     269  this->subscribeReaction(type);
     270
     271  // add the target filter
     272  this->collisionHandles[type]->addTarget(target1);
     273}
     274
     275
     276/**
     277 * subscribes this world entity to a collision reaction
     278 *  @param type the type of reaction to subscribe to
     279 *  @param target1 a filter target (classID)
     280 */
     281void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2)
     282{
     283  this->subscribeReaction(type);
     284
     285  // add the target filter
     286  this->collisionHandles[type]->addTarget(target1);
     287  this->collisionHandles[type]->addTarget(target2);
     288}
     289
     290
     291/**
     292 * subscribes this world entity to a collision reaction
     293 *  @param type the type of reaction to subscribe to
     294 *  @param target1 a filter target (classID)
     295 */
     296void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3)
     297{
     298  this->subscribeReaction(type);
     299
     300  // add the target filter
     301  this->collisionHandles[type]->addTarget(target1);
     302  this->collisionHandles[type]->addTarget(target2);
     303  this->collisionHandles[type]->addTarget(target3);
     304}
     305
     306
     307/**
     308 * subscribes this world entity to a collision reaction
     309 *  @param type the type of reaction to subscribe to
     310 *  @param target1 a filter target (classID)
     311 */
     312void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4)
     313{
     314  this->subscribeReaction(type);
     315
     316  // add the target filter
     317  this->collisionHandles[type]->addTarget(target1);
     318  this->collisionHandles[type]->addTarget(target2);
     319  this->collisionHandles[type]->addTarget(target3);
     320  this->collisionHandles[type]->addTarget(target4);
     321}
     322
     323
     324/**
     325 * subscribes this world entity to a collision reaction
     326 *  @param type the type of reaction to subscribe to
    251327 *  @param nrOfTargets number of target filters
    252328 *  @param ... the targets as classIDs
    253329 */
    254 void WorldEntity::subscribeReaction(CREngine::CRType type, int nrOfTargets, ...)
    255 {}
     330void WorldEntity::subscribeReaction(CREngine::CRType type)
     331{
     332  if( this->collisionHandles[type] != NULL)  {
     333    PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n");
     334    return;
     335  }
     336
     337  this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type);
     338
     339  // now there is at least one collision reaction subscribed
     340  this->bReactive = true;
     341}
     342
     343
     344/**
     345 * unsubscribes a specific reaction from the worldentity
     346 *  @param type the reaction to unsubscribe
     347 */
     348void WorldEntity::unsubscribeReaction(CREngine::CRType type)
     349{
     350  if( this->collisionHandles[type] == NULL)
     351    return;
     352
     353  CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);
     354  this->collisionHandles[type] = NULL;
     355
     356  // check if there is still any handler registered
     357  for(int i = 0; i < CREngine::CR_NUMBER; ++i)
     358  {
     359    if( this->collisionHandles[i] != NULL)
     360    {
     361      this->bReactive = true;
     362      return;
     363    }
     364  }
     365  this->bReactive = false;
     366}
     367
     368
     369/**
     370 * unsubscribes all collision reactions
     371 */
     372void WorldEntity::unsubscribeReaction()
     373{
     374  for( int i = 0; i < CREngine::CR_NUMBER; i++)
     375    this->unsubscribeReaction((CREngine::CRType)i);
     376
     377  // there are no reactions subscribed from now on
     378  this->bReactive = false;
     379}
     380
     381
     382/**
     383 * registers a new collision event to this world entity
     384 *  @param entityA entity of the collision
     385 *  @param entityB entity of the collision
     386 *  @param bvA colliding bounding volume of entityA
     387 *  @param bvB colliding bounding volume of entityA
     388 */
     389bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
     390{
     391  // is there any handler listening?
     392  if( !this->bReactive)
     393    return false;
     394
     395  // get a collision event
     396  CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
     397  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
     398  c->collide(entityA, entityB, bvA, bvB);
     399
     400  for( int i = 0; i < CREngine::CR_NUMBER; ++i)
     401    if( this->collisionHandles[i] != NULL)
     402      this->collisionHandles[i]->registerCollisionEvent(c);
     403}
     404
     405
     406/**
     407 * registers a new collision event to this woeld entity
     408 *  @param entity the entity that collides
     409 *  @param plane it stands on
     410 *  @param position it collides on the plane
     411 */
     412bool WorldEntity::registerCollision(WorldEntity* entity, Plane* plane, Vector position)
     413{
     414  // is there any handler listening?
     415  if( !this->bReactive)
     416    return false;
     417
     418  // get a collision event
     419  CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
     420  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
     421  c->collide(entity, plane, position);
     422
     423  for( int i = 0; i < CREngine::CR_NUMBER; ++i)
     424    if( this->collisionHandles[i] != NULL)
     425      this->collisionHandles[i]->registerCollisionEvent(c);
     426}
    256427
    257428
     
    324495void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2)
    325496{
    326  
     497
    327498  // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassName() );
    328  
     499
    329500  Vector v = this->getAbsDirX();
    330501  v.x *= 10;
     
    332503  v.z *= 10;
    333504  Vector u = this->getAbsDirY();
    334  
     505
    335506  if(feet.x == (u.x+this->getAbsCoor().x) &&  feet.y == u.y +this->getAbsCoor().y && feet.z == this->getAbsCoor().z)
    336507  {
    337    
     508
    338509  this->setAbsCoor(ray_2 - v);
    339510  }
     
    342513    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)
    343514    {
    344       this->setAbsCoor(feet -u ); 
    345     }
    346      
    347     this->setAbsCoor(ray_2 - v); 
    348    
     515      this->setAbsCoor(feet -u );
     516    }
     517
     518    this->setAbsCoor(ray_2 - v);
     519
    349520  }
    350521}
Note: See TracChangeset for help on using the changeset viewer.