1 #ifndef _COLLISION_CONTACT_H 2 #define _COLLISION_CONTACT_H 3 4 #include "tracksurface.h" 5 class BEZIER; 6 class btCollisionObject; 7 8 class COLLISION_CONTACT 9 { 10 private: 11 MATHVECTOR <float,3> position, normal; 12 float depth; 13 const TRACKSURFACE * surface; 14 const BEZIER * patch; 15 const btCollisionObject * col; 16 public: COLLISION_CONTACT()17 COLLISION_CONTACT() : depth(0), surface(TRACKSURFACE::None()), patch(NULL), col(NULL) 18 { } 19 GetPosition()20 const MATHVECTOR <float,3> & GetPosition() const { return position; } GetNormal()21 const MATHVECTOR <float,3> & GetNormal() const { return normal; } GetDepth()22 float GetDepth() const { return depth; } 23 GetSurfacePtr()24 const TRACKSURFACE * GetSurfacePtr() const { return surface; } GetSurface()25 const TRACKSURFACE & GetSurface() const { return *surface; } 26 GetPatch()27 const BEZIER * GetPatch() const { return patch; } GetColObj()28 const btCollisionObject * GetColObj() const { return col; } 29 30 31 // set contact data (used by ray cast) Set(const MATHVECTOR<float,3> & p,const MATHVECTOR<float,3> & n,float d,const TRACKSURFACE * s,const BEZIER * b,const btCollisionObject * c)32 void Set(const MATHVECTOR <float,3> & p, const MATHVECTOR <float,3> & n, float d, 33 const TRACKSURFACE * s, const BEZIER * b, const btCollisionObject * c) 34 { 35 assert(s != NULL); 36 position = p; normal = n; depth = d; 37 patch = b; surface = s; col = c; 38 } 39 40 // update/interpolate contact CastRay(const MATHVECTOR<float,3> & origin,const MATHVECTOR<float,3> & direction,float length)41 bool CastRay(const MATHVECTOR <float,3> & origin, const MATHVECTOR <float,3> & direction, float length) 42 { 43 // plane-based approximation 44 float nd = normal.dot(direction); 45 if (nd < 0) 46 { 47 depth = normal.dot(position - origin) / nd; 48 position = origin + direction * depth; 49 return true; 50 } 51 position = origin + direction * length; 52 depth = length; 53 return false; 54 } 55 }; 56 57 #endif // _COLLISION_CONTACT_H 58