/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION #include "collision_tube.h" #include "world_entity.h" #include "collision.h" #include "collision_event.h" #include "collision_reaction.h" #include "cr_object_damage.h" #include "cr_physics_ground_walk.h" #include "cr_physics_full_walk.h" namespace CoRe { ObjectListDefinition(CollisionTube); CollisionTube* CollisionTube::instance = NULL; /** * standard constructor * @todo this constructor is not jet implemented - do it */ CollisionTube::CollisionTube () { this->registerObject(this, CollisionTube::_objectList); // push the collision reaction object on the list in the right order // WARNING: do not mess with the order, it should be the same as in // physical reactions this->_reactionList[CREngine::CR_PHYSICS_MOMENTUM] = NULL; this->_reactionList[CREngine::CR_PHYSICS_STEP_BACK] = NULL; this->_reactionList[CREngine::CR_PHYSICS_GROUND_WALK] = new CRPhysicsGroundWalk(); this->_reactionList[CREngine::CR_PHYSICS_FULL_WALK] = new CRPhysicsFullWalk(); this->_reactionList[CREngine::CR_PHYSICS_DAMAGE] = NULL; // object based reactions this->_reactionList[CREngine::CR_OBJECT_DAMAGE] = new CRObjectDamage(); this->_reactionList[CREngine::CR_OBJECT_PICKUP] = NULL; // misc reactions this->_reactionList[CREngine::CR_VERTEX_TRAFO] = NULL; this->_reactionList[CREngine::CR_SPECIAL_CALLBACK] = NULL; } /** * standard deconstructor */ CollisionTube::~CollisionTube () { this->_collisionList.clear(); } /** * registers a new CollisionEvent * @param entityA one collision object * @param entityB the other collision objectName * @param bvA bounding volume of object A * @param bvB bounding volume of object B * * this function doesn't check if the entities in question actualy are registered for any collisions */ void CollisionTube::registerCollisionEvent(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) { Collision* collision = this->_collisionList.back(); // check if there is already a collision defined between these objects if( !collision->match(*entityA, *entityB)) { collision = CREngine::getInstance()->popCollisionObject(); collision->collide( entityA, entityB); } // now register the new collision event CollisionEvent* collisionEvent = CREngine::getInstance()->popCollisionEventObject(); collisionEvent->collide( CREngine::CR_COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB); collision->registerCollisionEvent( collisionEvent); } /** * registers a new CollisionEvent, only used by ground to object collision (eg. bsp model) * @param type type of collision as stated in cr_def.h * @param entity the WorldEntity colliding with the ground * @param groundEntity the WorldEntity representing the ground * @param normal the normal vector for the ground (up) - not always specified * @param position the position of the collision relative to the object center * @param bInWall true if the entity is in the ground material */ void CollisionTube::registerCollisionEvent(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity, const Vector& normal, const Vector& position, bool bInWall) { // get last collision Collision* collision = this->_collisionList.back(); // check if there is already a collision defined between these objects if( collision != NULL && !collision->match(*entity, *groundEntity)) { // get a new collision object collision = CREngine::getInstance()->popCollisionObject(); collision->collide( entity, groundEntity); } // now register the new collision event CollisionEvent* collisionEvent = CREngine::getInstance()->popCollisionEventObject(); collisionEvent->collide( type, entity, groundEntity, normal, position, bInWall); collision->registerCollisionEvent( collisionEvent); } /** * handles all collisions in registered in this tube */ void CollisionTube::handleCollisions() { // for all collisions: CollisionIterator ci = this->_collisionList.begin(); for(; ci < this->_collisionList.end(); ++ci) { for( int i = CREngine::CR_PHYSICS_MOMENTUM; i < CREngine::CR_NUBER; i++) { // check if entity A or B is subscibed for this event if( (*ci)->getEntityA()->bReactibe((*it)->getEnityB(), i) || (*ci)->getEntityB()->bReactibe((*it)->getEnityA(), i)) (*ci)->reactToCollision(*ci); (*ci)->flushCollisionEvents(); } } } }// namespace end