Changeset 9003 in orxonox.OLD for trunk/src/lib/collision_reaction
- Timestamp:
- Jul 2, 2006, 1:36:13 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc
r8894 r9003 23 23 #include "world_entity.h" 24 24 #include "cr_physics_ground_walk.h" 25 #include "collision_reaction.h" 25 26 26 27 #include <vector> … … 58 59 void CRPhysicsGroundWalk::reactToCollision(Collision* collision) 59 60 { 60 CollisionEvent* ce = collision->getCollisionEvents().front(); 61 Vector normal = ce->getGroundNormal(); 62 // normal.normalize(); 63 64 // put it back 65 // PRINTF(0)("putting it back to lastPos: \n"); 66 // this->lastPositions[0].debug(); 67 // PRINTF(0)("current pos:\n"); 68 // collision->getEntityB()->getAbsCoor().debug(); 69 70 float height; 61 71 62 AABB* box = collision->getEntityB()->getModelAABB(); 72 63 WorldEntity* entity = collision->getEntityB(); 73 74 // collision position maths75 Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition();76 77 float CR_MAX_WALK_HEIGHT = 2.0f;78 float CR_THRESHOLD = 0.2f;79 64 80 65 if( box == NULL) … … 85 70 86 71 87 switch( ce->getType()) 72 float CR_MAX_WALK_HEIGHT = 2.0f; 73 float CR_THRESHOLD = 0.2f; 74 75 float height = 0; 76 float front = 0; 77 float side = 0; 78 79 //PRINTF(0)("collision raction======================================\n"); 80 81 const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); 82 std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); 83 for(; it != collisionEvents->end(); it++) 88 84 { 89 case COLLISION_TYPE_AXIS_Y: 90 91 height = collPos.y - box->halfLength[1]; 92 // PRINTF(0)("height: %f , model height: %f\n", height, box->halfLength[1]); 93 // PRINTF(0)(" ground normal: %f, %f, %f\n", normal.x, normal.y, normal.z); 94 95 // object is beneath the plane (ground) 96 if( height <= 0.0f ) 97 { 98 entity->shiftCoor(Vector(0, -height, 0)); 99 } 100 // object is already in the wall 101 else if( ce->isInWall()) 102 { 103 entity->setAbsCoor(entity->getLastAbsCoor()); 104 } 105 break; 106 107 108 case COLLISION_TYPE_AXIS_X: 109 case COLLISION_TYPE_AXIS_Z: 110 break; 111 112 } 113 114 85 86 CollisionEvent* ce = (*it); 87 Vector normal = ce->getGroundNormal(); 88 89 // calculate the collision position 90 Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition(); 91 92 // test the 3 axis differently 93 switch( ce->getType()) 94 { 95 // collision in the x-axis 96 case COLLISION_TYPE_AXIS_X: 97 front = collPos.x - box->halfLength[0]; // should be [0] 98 99 // object is beneath the plane (ground) 100 if( front <= 0.0f ) 101 { 102 Vector backoff = entity->getAbsDirX() * front; 103 // entity->shiftCoor(backoff); 104 } 105 // object is already in the wall 106 else if( ce->isInWall()) 107 { 108 // entity->setAbsCoor(entity->getLastAbsCoor()); 109 } 110 break; 111 112 113 // collision in the y-axis 114 case COLLISION_TYPE_AXIS_Y: 115 // calulate the height above ground 116 height = collPos.y - box->halfLength[1]; 117 118 119 // object is beneath the plane (ground) 120 if( height <= 0.0f ) 121 { 122 entity->shiftCoor(Vector(0.0f, -height, 0.0f)); 123 entity->setOnGround(true); 124 } 125 // object is already in the wall 126 else if( ce->isInWall()) 127 { 128 entity->setAbsCoor(entity->getLastAbsCoor()); 129 } 130 else 131 { 132 // entity is not on ground 133 entity->setOnGround(false); 134 } 135 break; 136 137 138 // collision in the z-axis 139 case COLLISION_TYPE_AXIS_Z: 140 141 side = collPos.z - box->halfLength[2]; // should be [2] 142 143 // object is beneath the plane (ground) 144 if( side <= 0.0f ) 145 { 146 Vector backoff = entity->getAbsDirX() * side; 147 // entity->shiftCoor(backoff); 148 } 149 // object is already in the wall 150 else if( ce->isInWall()) 151 { 152 // entity->setAbsCoor(entity->getLastAbsCoor()); 153 } 154 break; 155 } 156 } 157 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side); 115 158 116 159 … … 126 169 127 170 128 if( box != NULL) { 129 130 131 if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) { 171 if( box != NULL) 172 { 173 174 175 if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) 176 { 132 177 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 133 178 return; 134 179 } 135 if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f) { 180 if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f) 181 { 136 182 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 137 183 return; 138 184 } 139 185 140 if(ce->getGroundNormal().len() <= 0.1f) { 186 if(ce->getGroundNormal().len() <= 0.1f) 187 { 141 188 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 142 189 return; … … 144 191 145 192 146 if(ce->getGroundNormal().len() >= 1.4f) { 193 if(ce->getGroundNormal().len() >= 1.4f) 194 { 147 195 downspeed++; 148 196 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0)); … … 164 212 165 213 } 166 else { 214 else 215 { 167 216 if(height.y < box->halfLength[1] + 0.0f /* && height.y > - 55.0f*/) // below ground 168 217 { … … 194 243 */ 195 244 void CRPhysicsGroundWalk::update(WorldEntity* owner) 196 { 197 198 } 199 200 245 {} 246 247
Note: See TracChangeset
for help on using the changeset viewer.