Changeset 10010 in orxonox.OLD for branches/coll_rect.merge/src/lib/collision_reaction/cr_physics_ground_walk.cc
- Timestamp:
- Dec 4, 2006, 4:39:45 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/coll_rect.merge/src/lib/collision_reaction/cr_physics_ground_walk.cc
r9869 r10010 34 34 35 35 36 namespace CoRe 37 { 36 38 37 ObjectListDefinition(CRPhysicsGroundWalk); 38 /** 39 * standard constructor 40 */ 41 CRPhysicsGroundWalk::CRPhysicsGroundWalk () 42 : CollisionReaction() 43 { 44 this->registerObject(this, CRPhysicsGroundWalk::_objectList); 45 } 39 ObjectListDefinition(CRPhysicsGroundWalk); 46 40 47 41 48 /** 49 * standard deconstructor 50 */ 51 CRPhysicsGroundWalk::~CRPhysicsGroundWalk () 52 {} 53 54 55 /** 56 * caluculates and applys the reaction to a specific collision 57 * @param collision the collision 58 */ 59 void CRPhysicsGroundWalk::reactToCollision(Collision* collision) 60 { 61 62 AABB* box = collision->getEntityB()->getModelAABB(); 63 WorldEntity* entity = collision->getEntityB(); 64 65 if( box == NULL) 42 /** 43 * standard constructor 44 */ 45 CRPhysicsGroundWalk::CRPhysicsGroundWalk () 46 : CollisionReaction() 66 47 { 67 PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n"); 68 return; 48 this->registerObject(this, CRPhysicsGroundWalk::_objectList); 69 49 } 70 50 71 51 72 float CR_MAX_WALK_HEIGHT = 15.0f; 73 74 float height = 0.0f; 52 /** 53 * standard deconstructor 54 */ 55 CRPhysicsGroundWalk::~CRPhysicsGroundWalk () 56 {} 75 57 76 58 77 const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); 78 std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); 79 for(; it != collisionEvents->end(); it++) 59 /** 60 * caluculates and applys the reaction to a specific collision 61 * @param collision the collision 62 */ 63 void CRPhysicsGroundWalk::reactToCollision(Collision* collision) 80 64 { 81 65 82 CollisionEvent* ce = (*it);83 Vector normal = ce->getGroundNormal();66 AABB* box = collision->getEntityA()->getModelAABB(); 67 WorldEntity* entity = collision->getEntityA(); 84 68 85 // calculate the collision position 86 Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition(); 87 88 // test the 3 axis differently 89 switch( ce->getType()) 69 if( box == NULL) 90 70 { 91 /* collision in the Y-AXIS */ 92 case COLLISION_TYPE_AXIS_Y_NEG: 93 // calulate the height above ground 94 height = collPos.len() - box->halfLength[1]; 71 PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n"); 72 return; 73 } 95 74 96 75 97 // object is beneath the plane (ground) 98 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing 99 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) 100 { 101 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); 102 entity->setOnGround(true); 103 } 104 // object is already in the wall 105 else if( ce->isInWall()) 106 { 107 entity->setAbsCoor(entity->getLastAbsCoor()); 108 } 109 else 110 { 111 // entity is not on ground 112 entity->setOnGround(false); 113 } 114 break; 76 float CR_MAX_WALK_HEIGHT = 15.0f; 77 78 float height = 0.0f; 115 79 116 80 81 std::vector<CollisionEvent*>::const_iterator it = collision->begin(); 82 for(; it != collision->end(); it++) 83 { 84 85 CollisionEvent* ce = (*it); 86 Vector normal = ce->getGroundNormal(); 87 88 // calculate the collision position 89 Vector collPos = collision->getEntityA()->getAbsCoor() + box->center - ce->getCollisionPosition(); 90 91 // test the 3 axis differently 92 switch( ce->getType()) 93 { 94 /* collision in the Y-AXIS */ 95 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG: 96 // calulate the height above ground 97 height = collPos.len() - box->halfLength[1]; 98 99 100 // object is beneath the plane (ground) 101 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing 102 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) 103 { 104 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); 105 entity->setOnGround(true); 106 } 107 // object is already in the wall 108 else if( ce->isInWall()) 109 { 110 entity->setAbsCoor(entity->getLastAbsCoor()); 111 } 112 else 113 { 114 // entity is not on ground 115 entity->setOnGround(false); 116 } 117 break; 118 119 120 } 117 121 } 122 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side); 123 118 124 } 119 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);120 121 }122 125 123 126 124 127 125 126 /** 127 * use this to do some collision offline calculations, only called for bContinuousPoll == true 128 */ 129 void CRPhysicsGroundWalk::update(WorldEntity* owner) 130 {} 131 132 128 }
Note: See TracChangeset
for help on using the changeset viewer.