Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/collision_reaction/collision_tube.cc @ 10767

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

merged the collision reaction branche back to trunk

File size: 4.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
[10006]29#include "debug.h"
[9890]30
31
32namespace CoRe
33{
34
35  ObjectListDefinition(CollisionTube);
36
[9994]37  CollisionTube* CollisionTube::singletonRef = NULL;
[9896]38
39
[9890]40  /**
41   * standard constructor
42   * @todo this constructor is not jet implemented - do it
43   */
44  CollisionTube::CollisionTube ()
45  {
[9892]46    this->registerObject(this, CollisionTube::_objectList);
[9890]47  }
48
49
50  /**
51   * standard deconstructor
52   */
53  CollisionTube::~CollisionTube ()
54  {
[10006]55    this->reset();
56  }
57
58
59
60  /**
61   * resets the collision tube after each collision detection cycle
62   */
63  void CollisionTube::reset()
64  {
[9890]65    this->_collisionList.clear();
66  }
67
[9891]68
69  /**
[10006]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
[9891]74   */
[10006]75  Collision* CollisionTube::registerCollision(WorldEntity* entityA, WorldEntity* entityB)
[9891]76  {
[10006]77    assert( entityA != NULL && entityB != NULL);
78
[9994]79    Collision* collision = NULL;
80    if( !this->_collisionList.empty())
81      collision = this->_collisionList.back();
[9892]82
[9994]83    // check if there is already a collision defined between these objects or this is the first collision at all
[10006]84    if( collision == NULL || !collision->same(*entityA, *entityB))
[9892]85    {
[9893]86      collision = CREngine::getInstance()->popCollisionObject();
87      collision->collide( entityA, entityB);
[10006]88      this->_collisionList.push_back(collision);
[9892]89    }
[9893]90
[10006]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
[9893]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);
[9891]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   */
[9893]125  void CollisionTube::registerCollisionEvent(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity,
[10006]126      const Vector& normal, const Vector& position, bool bInWall)
[9891]127  {
[10006]128    // first get a useable collision object
129    Collision* collision = this->registerCollision(entity, groundEntity);
[9893]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);
[9891]135  }
136
[9893]137
[9898]138
139}// namespace end
[9890]140
Note: See TracBrowser for help on using the repository browser.