Changeset 9110 in orxonox.OLD for trunk/src/lib/collision_reaction
- Timestamp:
- Jul 4, 2006, 11:18:41 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc
r9061 r9110 70 70 71 71 72 float CR_MAX_WALK_HEIGHT = 2.0f;72 float CR_MAX_WALK_HEIGHT = 15.0f; 73 73 float CR_THRESHOLD = 0.2f; 74 74 75 float height = 0; 76 float front = 0; 77 float side = 0; 78 79 //PRINTF(0)("collision raction======================================\n"); 75 float height = 0.0f; 76 float front = 0.0f; 77 float back = 0.0f; 78 float right = 0.0f; 79 float left = 0.0f; 80 80 81 81 82 const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); … … 93 94 switch( ce->getType()) 94 95 { 95 / / collision in the x-axis96 /* collision in the X-AXIS */ 96 97 case COLLISION_TYPE_AXIS_X: 97 front = collPos.len() - box->halfLength[0]; // should be [0]98 front = collPos.len() - box->halfLength[0]; 98 99 99 100 // object is beneath the plane (ground) 100 101 if( front <= 0.0f ) 101 102 { 102 Vector dirX = entity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize(); 103 Vector dirX = entity->getAbsDirX(); 104 dirX.y = 0.0f; 105 dirX.normalize(); 103 106 Vector backoff = dirX * front; 104 105 entity->setAbsCoor(entity->getLastAbsCoor()); 106 // entity->shiftCoor(backoff); 107 } 108 // object is already in the wall 109 else if( ce->isInWall()) 110 { 111 entity->setAbsCoor(entity->getLastAbsCoor()); 112 } 113 break; 114 107 108 entity->shiftCoor(backoff); 109 } 110 else if( ce->isInWall()) 111 { 112 // object is already in the wall 113 entity->setAbsCoor(entity->getLastAbsCoor()); 114 } 115 break; 116 115 117 case COLLISION_TYPE_AXIS_X_NEG: 116 front = collPos.len() - box->halfLength[0]; // should be [0] 117 118 // object is beneath the plane (ground) 119 if( front <= 0.0f ) 120 { 121 Vector dirX = entity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize(); 122 Vector backoff = dirX * front * -1.0f; 123 124 entity->setAbsCoor(entity->getLastAbsCoor()); 125 // entity->shiftCoor(backoff); 126 } 127 // object is already in the wall 128 else if( ce->isInWall()) 129 { 130 entity->setAbsCoor(entity->getLastAbsCoor()); 131 } 132 break; 133 134 135 // collision in the y-axis 118 back = collPos.len() - box->halfLength[0]; 119 120 // object is beneath the plane (ground) 121 if( back <= 0.0f) 122 { 123 Vector dirX = entity->getAbsDirX(); 124 dirX.y = 0.0f; 125 dirX.normalize(); 126 Vector backoff = dirX * back * -1.0f; 127 128 entity->shiftCoor(backoff); 129 } 130 else if( ce->isInWall()) 131 { 132 // object is already in the wall 133 entity->setAbsCoor(entity->getLastAbsCoor()); 134 } 135 break; 136 137 138 /* collision in the Y-AXIS */ 136 139 case COLLISION_TYPE_AXIS_Y_NEG: 137 140 // calulate the height above ground 138 height = collPos. y- box->halfLength[1];139 140 141 // object is beneath the plane (ground) 142 if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing143 else if( height < 0.0f)141 height = collPos.len() - box->halfLength[1]; 142 143 144 // object is beneath the plane (ground) 145 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing 146 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) 144 147 { 145 148 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); … … 160 163 161 164 165 /* collision in the Z-AXIS */ 166 case COLLISION_TYPE_AXIS_Z: 167 168 right = collPos.len() - box->halfLength[2]; 169 170 // object is beneath the plane (ground) 171 if( right <= 0.0f ) 172 { 173 Vector dirZ = entity->getAbsDirZ(); 174 dirZ.y = 0.0f; 175 dirZ.normalize(); 176 Vector backoff = dirZ * right; 177 entity->shiftCoor(backoff); 178 } 179 else if( ce->isInWall()) 180 { 181 // object is already in the wall 182 entity->setAbsCoor(entity->getLastAbsCoor()); 183 } 184 break; 185 186 162 187 // collision in the z-axis 163 case COLLISION_TYPE_AXIS_Z:164 165 side = collPos.len() - box->halfLength[2]; // should be [2]166 167 // object is beneath the plane (ground)168 if( side <= 0.0f )169 {170 entity->setAbsCoor(entity->getAbsCoor());171 Vector dirZ = entity->getAbsDirZ(); dirZ.y = 0.0f; dirZ.normalize();172 Vector backoff = dirZ * side;173 entity->shiftCoor(backoff);174 }175 // object is already in the wall176 else if( ce->isInWall())177 {178 entity->setAbsCoor(entity->getLastAbsCoor());179 }180 break;181 182 183 // collision in the z-axis184 188 case COLLISION_TYPE_AXIS_Z_NEG: 185 189 186 side = collPos.len() - box->halfLength[2]; // should be [2] 187 188 // object is beneath the plane (ground) 189 if( side <= 0.0f ) 190 { 191 192 Vector dirZ = entity->getAbsDirZ(); dirZ.y = 0.0f; dirZ.normalize(); 193 Vector backoff = dirZ * side*-1.0f; 190 left = collPos.len() - box->halfLength[2]; 191 192 // object is beneath the plane (ground) 193 if( left <= 0.0f ) 194 { 195 Vector dirZ = entity->getAbsDirZ(); 196 dirZ.y = 0.0f; 197 dirZ.normalize(); 198 Vector backoff = dirZ * left*-1.0f; 194 199 entity->shiftCoor(backoff); 195 200 } … … 209 214 210 215 211 #if 0212 if( box != NULL)213 height = ( ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() )*(-1.0f) ;214 else215 height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() ;216 217 218 if( box != NULL)219 {220 221 222 if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f)223 {224 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());225 return;226 }227 if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f)228 {229 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());230 return;231 }232 233 if(ce->getGroundNormal().len() <= 0.1f)234 {235 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());236 return;237 }238 239 240 if(ce->getGroundNormal().len() >= 1.4f)241 {242 downspeed++;243 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));244 return;245 }246 247 248 if(height.y > box->halfLength[1] + 0.0f ) // Above ground249 {250 if(height.y < box->halfLength[1] + 2.3f) // Snap in251 {252 downspeed = 0;253 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() - Vector(0.0,height.y - box->halfLength[1] - 0.0f,0.0));254 } else255 {256 downspeed++;257 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));258 }259 260 }261 else262 {263 if(height.y < box->halfLength[1] + 0.0f /* && height.y > - 55.0f*/) // below ground264 {265 //if(downspeed <= 0) downspeed =1;266 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, -height.y + box->halfLength[1] + 2.0f,0.0));267 //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0));268 downspeed = 0;269 }270 271 }272 273 }// if(box!= NULL)274 #endif275 /*276 PRINTF(0)("Collision with Ground: \n");277 collision->getEntityB()->getAbsCoor().debug();278 collision->getEntityB()->setVelocity(Vector());279 collision->getEntityB()->setAbsCoor(this->lastPositions[1]);280 281 */282 216 283 217 }
Note: See TracChangeset
for help on using the changeset viewer.