/* 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 co-programmer: ... */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION #include "collision.h" #include "collision_event.h" #include "physics_interface.h" #include "world_entity.h" #include "cr_physics_ground_walk.h" #include "collision_reaction.h" #include #include "debug.h" #include "aabb.h" #include "cr_defs.h" /** * standard constructor */ CRPhysicsGroundWalk::CRPhysicsGroundWalk () : CollisionReaction() { this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk"); } /** * standard deconstructor */ CRPhysicsGroundWalk::~CRPhysicsGroundWalk () {} /** * caluculates and applys the reaction to a specific collision * @param collision the collision */ void CRPhysicsGroundWalk::reactToCollision(Collision* collision) { AABB* box = collision->getEntityB()->getModelAABB(); WorldEntity* entity = collision->getEntityB(); if( box == NULL) { PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n"); return; } float CR_MAX_WALK_HEIGHT = 15.0f; float height = 0.0f; const std::vector* collisionEvents = &(collision->getCollisionEvents()); std::vector::const_iterator it = collisionEvents->begin(); for(; it != collisionEvents->end(); it++) { CollisionEvent* ce = (*it); Vector normal = ce->getGroundNormal(); // calculate the collision position Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition(); // test the 3 axis differently switch( ce->getType()) { /* collision in the Y-AXIS */ case COLLISION_TYPE_AXIS_Y_NEG: // calulate the height above ground height = collPos.len() - box->halfLength[1]; // object is beneath the plane (ground) // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) { entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); entity->setOnGround(true); } // object is already in the wall else if( ce->isInWall()) { entity->setAbsCoor(entity->getLastAbsCoor()); } else { // entity is not on ground entity->setOnGround(false); } break; } } //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side); } /** * use this to do some collision offline calculations, only called for bContinuousPoll == true */ void CRPhysicsGroundWalk::update(WorldEntity* owner) {}