Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/collision_reaction/collision_tube.cc @ 10345

Last change on this file since 10345 was 10013, checked in by patrick, 18 years ago

merged the collision reaction branche back to trunk

File size: 4.0 KB
Line 
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#include "debug.h"
30
31
32namespace CoRe
33{
34
35  ObjectListDefinition(CollisionTube);
36
37  CollisionTube* CollisionTube::singletonRef = NULL;
38
39
40  /**
41   * standard constructor
42   * @todo this constructor is not jet implemented - do it
43   */
44  CollisionTube::CollisionTube ()
45  {
46    this->registerObject(this, CollisionTube::_objectList);
47  }
48
49
50  /**
51   * standard deconstructor
52   */
53  CollisionTube::~CollisionTube ()
54  {
55    this->reset();
56  }
57
58
59
60  /**
61   * resets the collision tube after each collision detection cycle
62   */
63  void CollisionTube::reset()
64  {
65    this->_collisionList.clear();
66  }
67
68
69  /**
70   * gets the collision object useable for collision events registarations
71   * @param entityA collision partner 1
72   * @param entityB collision partner 2
73   * @return the collision object to be used
74   */
75  Collision* CollisionTube::registerCollision(WorldEntity* entityA, WorldEntity* entityB)
76  {
77    assert( entityA != NULL && entityB != NULL);
78
79    Collision* collision = NULL;
80    if( !this->_collisionList.empty())
81      collision = this->_collisionList.back();
82
83    // check if there is already a collision defined between these objects or this is the first collision at all
84    if( collision == NULL || !collision->same(*entityA, *entityB))
85    {
86      collision = CREngine::getInstance()->popCollisionObject();
87      collision->collide( entityA, entityB);
88      this->_collisionList.push_back(collision);
89    }
90
91    return collision;
92  }
93
94
95  /**
96   * registers a new CollisionEvent
97   * @param entityA one collision object
98   * @param entityB the other collision objectName
99   * @param bvA bounding volume of object A
100   * @param bvB bounding volume of object B
101   *
102   * this function doesn't check if the entities in question actualy are registered for any collisions
103   */
104  void CollisionTube::registerCollisionEvent(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
105  {
106    // first get a useable collision object
107    Collision* collision = this->registerCollision(entityA, entityB);
108
109    // now register the new collision event
110    CollisionEvent* collisionEvent = CREngine::getInstance()->popCollisionEventObject();
111    collisionEvent->collide( CREngine::CR_COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB);
112    collision->registerCollisionEvent( collisionEvent);
113  }
114
115
116  /**
117   * registers a new CollisionEvent, only used by ground to object collision (eg. bsp model)
118   * @param type type of collision as stated in cr_def.h
119   * @param entity the WorldEntity colliding with the ground
120   * @param groundEntity the WorldEntity representing the ground
121   * @param normal the normal vector for the ground (up) - not always specified
122   * @param position the position of the collision relative to the object center
123   * @param bInWall true if the entity is in the ground material
124   */
125  void CollisionTube::registerCollisionEvent(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity,
126      const Vector& normal, const Vector& position, bool bInWall)
127  {
128    // first get a useable collision object
129    Collision* collision = this->registerCollision(entity, groundEntity);
130
131    // now register the new collision event
132    CollisionEvent* collisionEvent = CREngine::getInstance()->popCollisionEventObject();
133    collisionEvent->collide( type, entity, groundEntity, normal, position, bInWall);
134    collision->registerCollisionEvent( collisionEvent);
135  }
136
137
138
139}// namespace end
140
Note: See TracBrowser for help on using the repository browser.