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
00019
00020
00021
00022 float dot = gmtl::dot(-incomingVector, polygonNormal );
00023
00024
00025 gmtl::Vec3f normalComponent = polygonNormal * dot;
00026
00027
00028
00029 gmtl::Vec3f reflectionVector = (normalComponent * 2.0f) + incomingVector;
00030
00031
00032 gmtl::Vec3f tangentialComponent = reflectionVector - normalComponent;
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 normalForce = normalComponent * (1.0f + elastic_coef) * mass / timeDelta;
00046 frictionForce = -tangentialComponent * friction_coef * mass / timeDelta;
00047 }
00048 }
00049
00050 #endif