00001 #ifndef COLLISION_
00002 #define COLLISION_
00003
00004 #include <gmtl/Vec.h>
00005 #include <gmtl/VecOps.h>
00006
00007 namespace gator
00008 {
00009 inline void computeCollisionForces( const gmtl::Vec3f& polygonNormal,
00010 const gmtl::Vec3f& incomingVector,
00011 float elastic_coef,
00012 float friction_coef,
00013 float mass,
00014 float timeDelta,
00015 gmtl::Vec3f& frictionForce,
00016 gmtl::Vec3f& normalForce )
00017 {
00018 //: split the reflected vector into normal and tangential
00019 // vectors to the plane
00020
00021 // project the (reverse of the) incoming vector onto the normal (just distance scalar)
00022 float dot = gmtl::dot(-incomingVector, polygonNormal );
00023
00024 // project the (reverse of the) incoming vector onto the normal (now the coordinate)
00025 gmtl::Vec3f normalComponent = polygonNormal * dot;
00026
00027 // compute perfect reflection using available vectors...
00028 // (perfect == don't consider friction/elasticity)
00029 gmtl::Vec3f reflectionVector = (normalComponent * 2.0f) + incomingVector;
00030
00031 // compute the tangential component using the available vectors.
00032 gmtl::Vec3f tangentialComponent = reflectionVector - normalComponent;
00033
00034 // compute the normal and friction forces
00035 //
00036 // normal: calc the amount of instantaneous force pushing up
00037 // from the ground.
00038 // friction: calc the amount of force against the tangential
00039 // direction of motion
00040 //
00041 // NOTE: instantaneous implies we need to calc
00042 // the amount of force required to halt motion over the
00043 // current timestep if the coef is 1 for elastic or 0 for friction
00044 // (so this is why consider time in the eq)
00045 normalForce = normalComponent * (1.0f + elastic_coef) * mass / timeDelta;
00046 frictionForce = -tangentialComponent * friction_coef * mass / timeDelta;
00047 }
00048 } // end namespace gator
00049
00050 #endif
1.2.15