Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/lib/collision_reaction/collision_tube.cc @ 9983

Last change on this file since 9983 was 9983, checked in by patrick, 17 years ago

collision object adjustements

File size: 5.0 KB
RevLine 
[9890]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Patrick Boenzli
13*/
14
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION
16
17#include "collision_tube.h"
18
19#include "world_entity.h"
20
21#include "collision.h"
22#include "collision_event.h"
23#include "collision_reaction.h"
24
25#include "cr_object_damage.h"
26#include "cr_physics_ground_walk.h"
27#include "cr_physics_full_walk.h"
28
29
30
31namespace CoRe
32{
33
34  ObjectListDefinition(CollisionTube);
35
[9896]36  CollisionTube* CollisionTube::instance = NULL;
37
38
[9890]39  /**
40   * standard constructor
41   * @todo this constructor is not jet implemented - do it
42   */
43  CollisionTube::CollisionTube ()
44  {
[9892]45    this->registerObject(this, CollisionTube::_objectList);
[9981]46
47
48    // push the collision reaction object on the list in the right order
49    // WARNING: do not mess with the order, it should be the same as in
50
51    // physical reactions
52    this->_reactionList[CREngine::CR_PHYSICS_MOMENTUM]      = NULL;
53    this->_reactionList[CREngine::CR_PHYSICS_STEP_BACK]     = NULL;
54    this->_reactionList[CREngine::CR_PHYSICS_GROUND_WALK]   = new CRPhysicsGroundWalk();
55    this->_reactionList[CREngine::CR_PHYSICS_FULL_WALK]     = new CRPhysicsFullWalk();
56    this->_reactionList[CREngine::CR_PHYSICS_DAMAGE]        = NULL;
57    // object based reactions
58    this->_reactionList[CREngine::CR_OBJECT_DAMAGE]         = new CRObjectDamage();
59    this->_reactionList[CREngine::CR_OBJECT_PICKUP]         = NULL;
60    // misc reactions
61    this->_reactionList[CREngine::CR_VERTEX_TRAFO]          = NULL;
62    this->_reactionList[CREngine::CR_SPECIAL_CALLBACK]      = NULL;
[9890]63  }
64
65
66  /**
67   * standard deconstructor
68   */
69  CollisionTube::~CollisionTube ()
70  {
71    this->_collisionList.clear();
72  }
73
[9891]74
75  /**
76   * registers a new CollisionEvent
77   * @param entityA one collision object
78   * @param entityB the other collision objectName
79   * @param bvA bounding volume of object A
80   * @param bvB bounding volume of object B
81   *
82   * this function doesn't check if the entities in question actualy are registered for any collisions
83   */
84  void CollisionTube::registerCollisionEvent(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
85  {
86    Collision* collision = this->_collisionList.back();
[9892]87
88    // check if there is already a collision defined between these objects
[9893]89    if( !collision->match(*entityA, *entityB))
[9892]90    {
[9893]91      collision = CREngine::getInstance()->popCollisionObject();
92      collision->collide( entityA, entityB);
[9892]93    }
[9893]94
95    // now register the new collision event
96    CollisionEvent* collisionEvent = CREngine::getInstance()->popCollisionEventObject();
97    collisionEvent->collide( CREngine::CR_COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB);
98    collision->registerCollisionEvent( collisionEvent);
[9891]99  }
100
101
102  /**
103   * registers a new CollisionEvent, only used by ground to object collision (eg. bsp model)
104   * @param type type of collision as stated in cr_def.h
105   * @param entity the WorldEntity colliding with the ground
106   * @param groundEntity the WorldEntity representing the ground
107   * @param normal the normal vector for the ground (up) - not always specified
108   * @param position the position of the collision relative to the object center
109   * @param bInWall true if the entity is in the ground material
110   */
[9893]111  void CollisionTube::registerCollisionEvent(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity,
[9891]112                              const Vector& normal, const Vector& position, bool bInWall)
113  {
[9939]114    // get last collision
[9893]115    Collision* collision = this->_collisionList.back();
116
117    // check if there is already a collision defined between these objects
[9939]118    if( collision != NULL && !collision->match(*entity, *groundEntity))
[9893]119    {
[9939]120      // get a new collision object
[9893]121      collision = CREngine::getInstance()->popCollisionObject();
122      collision->collide( entity, groundEntity);
123    }
124
125    // now register the new collision event
126    CollisionEvent* collisionEvent = CREngine::getInstance()->popCollisionEventObject();
127    collisionEvent->collide( type, entity, groundEntity, normal, position, bInWall);
128    collision->registerCollisionEvent( collisionEvent);
[9891]129  }
130
[9893]131
[9898]132
[9891]133  /**
[9898]134   * handles all collisions in registered in this tube
135   */
136  void CollisionTube::handleCollisions()
137  {
[9939]138    // for all collisions:
[9980]139    CollisionIterator ci = this->_collisionList.begin();
140    for(; ci < this->_collisionList.end(); ++ci)
[9939]141    {
[9981]142      for( int i = CREngine::CR_PHYSICS_MOMENTUM; i < CREngine::CR_NUBER; i++)
143      {
144        // check if entity A or B is subscibed for this event
145        if( (*ci)->getEntityA()->bReactibe((*it)->getEnityB(), i) || (*ci)->getEntityB()->bReactibe((*it)->getEnityA(), i))
146          (*ci)->reactToCollision(*ci);
[9983]147
148        (*ci)->flushCollisionEvents();
[9981]149      }
[9939]150    }
[9898]151  }
152
153
[9893]154
155
156
157
[9891]158
[9898]159}// namespace end
[9890]160
Note: See TracBrowser for help on using the repository browser.