Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

first element init problem

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