Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9892 in orxonox.OLD for branches/coll_rect/src/lib


Ignore:
Timestamp:
Oct 14, 2006, 1:25:47 AM (18 years ago)
Author:
patrick
Message:

new interface to collision registers, more transparent. some more functionality

Location:
branches/coll_rect/src/lib/collision_reaction
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/coll_rect/src/lib/collision_reaction/collision.h

    r9891 r9892  
    5353
    5454
    55     inline bool match(const WorldEntity& entityA, WorldEntity& entityB) const { return (this->entityA == &entityA && this->entityB == &entityB); }
     55    inline bool match(const WorldEntity& entityA, WorldEntity& entityB) const {
     56      return ((this->entityA == &entityA && this->entityB == &entityB) || (this->entityA == &entityB && this->entityB == &entityA)); }
    5657    /** @returns true if this Collision has already been dispatched */
    5758    inline bool isDispatched() { return this->bDispatched; }
  • branches/coll_rect/src/lib/collision_reaction/collision_event.h

    r9889 r9892  
    1414
    1515#include "vector.h"
     16#include "cr_engine.h"
    1617
    1718#include "cr_defs.h"
     
    3334
    3435    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
    35     inline void collide(int type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
     36    inline void collide(CREngine::CollisionType type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
    3637    { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
    3738    /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */
    38     inline void collide(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
     39    inline void collide(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
    3940    {
    4041      this->collisionType = type;
  • branches/coll_rect/src/lib/collision_reaction/collision_handle.cc

    r9890 r9892  
    3838   * @todo this constructor is not jet implemented - do it
    3939  */
    40   CollisionHandle::CollisionHandle (WorldEntity* owner, CREngine::CRType type)
     40  CollisionHandle::CollisionHandle (WorldEntity* owner, CREngine::ReactionType type)
    4141  {
    4242    this->registerObject(this, CollisionHandle::_objectList);
  • branches/coll_rect/src/lib/collision_reaction/collision_handle.h

    r9890 r9892  
    3030
    3131  public:
    32     CollisionHandle(WorldEntity* owner, CREngine::CRType type);
     32    CollisionHandle(WorldEntity* owner, CREngine::ReactionType type);
    3333    virtual ~CollisionHandle();
    3434
     
    4747    inline bool isContinuousPoll() const { return this->bContinuousPoll; }
    4848    /** @returns the type */
    49     inline CREngine::CRType getType() const { return this->type; }
     49    inline CREngine::ReactionType getType() const { return this->type; }
    5050
    5151    void handleCollisions();
     
    6161  private:
    6262    WorldEntity*                  owner;                   //!< the worldenity this reaction will be applied on
    63     CREngine::CRType              type;                    //!< the reaction type
     63    CREngine::ReactionType              type;                    //!< the reaction type
    6464
    6565    bool                          bContinuousPoll;         //!< if this is true
  • branches/coll_rect/src/lib/collision_reaction/collision_tube.cc

    r9891 r9892  
    4040  CollisionTube::CollisionTube ()
    4141  {
    42 
     42    this->registerObject(this, CollisionTube::_objectList);
    4343  }
    4444
     
    6565  {
    6666    Collision* collision = this->_collisionList.back();
     67
     68    // check if there is already a collision defined between these objects
    6769    if( collision->match(*entityA, *entityB))
    68     {}
     70    {
     71      CollisionEvent* collisionEvent = CREngine::getInstance()->popCollisionEventObject();
     72      collisionEvent->collide( CREngine::CR_COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB);
     73      collision->registerCollisionEvent( collisionEvent);
     74    }
    6975  }
    7076
  • branches/coll_rect/src/lib/collision_reaction/collision_tube.h

    r9891 r9892  
    33 *
    44 * collision tube collects all collisions from all entities
     5 *
     6 *  The collision events are saved in the _collisionList vector in a fixed hirarchy: a collision is defined by the world entities
     7 *  that collide. For each collision there is an entry in _collisionList. Each collision itself again contains collision events which are
     8 *  defined as collisions between the boundibg volumes (BV) of the world entities. This could look like this:
     9 *
     10 *  - Collision (WorldEntity_i  <=> WorldEntity_j)
     11 *     +- CollisionEvent( some BV <=> some other BV)
     12 *     +- CollisionEvent( some BV <=> some other BV)
     13 *  - Collision (WorldEntity_k <=> WorldEntity_l)
     14 *     +- CollisionEvent( some BV <=> some other BV)
     15 *     +- CollisionEvent( some BV <=> some other BV)
     16 *     +- CollisionEvent( some BV <=> some other BV)
     17 *     +- CollisionEvent( some BV <=> some other BV)
     18 *  - ... etc ...
     19 *
     20 *
     21 *  When the collisions are processed by the handleCollision() function each collision pair is checked for their reactions (since each
     22 *  WorldEntity can define several reactions to a collision). After all the reactions are calculated and applied the collision object is
     23 *  put back.
    524 */
    625
     
    2443  class CollisionReaction;
    2544
    26   //! A class for defining collision reactions and storing events
     45  //! A class containing all CollisionEvents (structured as defined in the file doxygen tags)
    2746  class CollisionTube : public BaseObject
    2847  {
     
    3251  public:
    3352    CollisionTube();
    34     ~CollisionTube();
     53    virtual ~CollisionTube();
    3554
    3655    /** @returns true if at least one of both WorldEntities are subscribed for a collision check */
  • branches/coll_rect/src/lib/collision_reaction/cr_defs.h

    r9062 r9892  
    3838#define COLLISION_TYPE_AXIS_Z_NEG  6
    3939//!< the collision is a obb collision
    40 #define COLLISION_TYPE_OBB      8
     40#define COLLISION_TYPE_OBB         8
    4141
    4242
  • branches/coll_rect/src/lib/collision_reaction/cr_engine.cc

    r9890 r9892  
    8989
    9090  /**
     91   * @returns an instance to a collision object. instead of creating new object this ones can be resycled
     92   */
     93  Collision* CREngine::popCollisionObject()
     94  {
     95    if( !this->collisionsUnused.empty())
     96    {
     97      this->collisionsUsed.push_back(this->collisionsUnused.back());
     98      this->collisionsUnused.pop_back();
     99      return this->collisionsUsed.back();
     100    }
     101    else return NULL;
     102  }
     103
     104  /**
     105   * @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled
     106   */
     107  CollisionEvent* CREngine::popCollisionEventObject()
     108  {
     109    if( !this->collisionEventsUnused.empty())
     110    {
     111      this->collisionEventsUsed.push_back(this->collisionEventsUnused.back());
     112      this->collisionEventsUnused.pop_back();
     113      return this->collisionEventsUsed.back();
     114    }
     115    else return NULL;
     116  }
     117
     118
     119  /**
    91120   * flushes the CollisionHandles and restores the CREngine to the initial state
    92121   */
     
    112141   *  @return the newly created CollisionHandle
    113142   */
    114   CollisionHandle* CREngine::subscribeReaction(WorldEntity* owner, CRType type)
     143  CollisionHandle* CREngine::subscribeReaction(WorldEntity* owner, ReactionType type)
    115144  {
    116145    CollisionHandle* ch = new CollisionHandle(owner, type);
  • branches/coll_rect/src/lib/collision_reaction/cr_engine.h

    r9889 r9892  
    3131
    3232  public:
    33     typedef enum CRType {
    34       CR_PHYSICS_MOMENTUM   = 0,    //!< physical reaction: conservervation of momentum
    35       CR_PHYSICS_STEP_BACK,         //!< physical reaction: just go to the last position without collisions
    36       CR_PHYSICS_GROUND_WALK,       //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force
    37       CR_PHYSICS_FULL_WALK,         //!< physical reaction: walking on the ground (inkl. hills etc)
    38       CR_PHYSICS_DAMAGE,            //!< physical reaction: daling damage according to the object energy and their structural stability
     33    typedef enum ReactionType {
     34      CR_PHYSICS_MOMENTUM   = 0,           //!< physical reaction: conservervation of momentum
     35      CR_PHYSICS_STEP_BACK,                //!< physical reaction: just go to the last position without collisions
     36      CR_PHYSICS_GROUND_WALK,              //!< physical reaction: stand on the ground, no movement: simple normal force away from the gravity force
     37      CR_PHYSICS_FULL_WALK,                //!< physical reaction: walking on the ground (inkl. hills etc)
     38      CR_PHYSICS_DAMAGE,                   //!< physical reaction: daling damage according to the object energy and their structural stability
    3939
    40       CR_OBJECT_DAMAGE,             //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.)
    41       CR_OBJECT_PICKUP,             //!< object rection: calling the objects pickup functions, let them handle the collision (once!)
     40      CR_OBJECT_DAMAGE,                    //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.)
     41      CR_OBJECT_PICKUP,                    //!< object rection: calling the objects pickup functions, let them handle the collision (once!)
    4242
    43       CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
     43      CR_VERTEX_TRAFO,                     //!< vertex trafo: transforming the vertex according to the damage
    4444
    45       CR_SPECIAL_CALLBACK,          //!< special: call a callback function
     45      CR_SPECIAL_CALLBACK,                 //!< special: call a callback function
    4646
    4747      CR_NUMBER
    4848    };
     49
     50    typedef enum CollisionType {
     51      CR_COLLISION_TYPE_AXIS_X       = 0,  //!< collision on x axis
     52      CR_COLLISION_TYPE_AXIS_X_NEG,        //!< collision on negative x axis
     53      CR_COLLISION_TYPE_AXIS_Y,            //!< collision on y axis
     54      CR_COLLISION_TYPE_AXIS_Y_NEG,        //!< collision on negative y axis
     55      CR_COLLISION_TYPE_AXIS_Z,            //!< collision on z axis
     56      CR_COLLISION_TYPE_AXIS_Z_NEG,        //!< collision on negative z axis
     57      CR_COLLISION_TYPE_OBB,               //!< object aligned bounding box collide
     58
     59      CR_COLLISION_TYPE_NUMBER
     60    };
     61
     62
     63#define COLLISION_TYPE_AXIS_X      1
     64#define COLLISION_TYPE_AXIS_X_NEG  2
     65//!< the collision axis y collision event
     66#define COLLISION_TYPE_AXIS_Y      3
     67#define COLLISION_TYPE_AXIS_Y_NEG  4
     68//!< the collision axis z collision event
     69#define COLLISION_TYPE_AXIS_Z      5
     70#define COLLISION_TYPE_AXIS_Z_NEG  6
     71//!< the collision is a obb collision
     72#define COLLISION_TYPE_OBB         8
    4973
    5074    virtual ~CREngine(void);
     
    5377    inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
    5478
     79    CollisionHandle* subscribeReaction(WorldEntity* worldEntity, ReactionType type);
     80    bool unsubscribeReaction(CollisionHandle* collisionHandle);
     81
     82
     83    Collision* popCollisionObject();
     84    CollisionEvent* popCollisionEventObject();
    5585    void reset();
    5686
    57 
    58     CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
    59 
    60     bool unsubscribeReaction(CollisionHandle* collisionHandle);
    61 
    6287    void handleCollisions();
    63 
    64     /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
    65     inline Collision* popCollisionObject()
    66     {
    67       if( !this->collisionsUnused.empty())
    68       {
    69         this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back();
    70       }
    71       else return NULL;
    72     }
    73 
    74 
    75     /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */
    76     inline CollisionEvent* popCollisionEventObject()
    77     {
    78       if( !this->collisionEventsUnused.empty())
    79       {
    80         this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back();
    81       }
    82       else return NULL;
    83     }
    8488
    8589    void debug();
  • branches/coll_rect/src/lib/collision_reaction/cr_physics_full_walk.cc

    r9889 r9892  
    7272
    7373    float CR_MAX_WALK_HEIGHT = 15.0f;
    74     float CR_THRESHOLD = 0.2f;
     74//    float CR_THRESHOLD = 0.2f;
    7575
    7676    float height = 0.0f;
Note: See TracChangeset for help on using the changeset viewer.