00001 #ifndef __MATH3D_H__
00002 #define __MATH3D_H__
00003
00004 #include "Common/CommonDll.h"
00005 #include "Common/Vector.h"
00006
00007 class KPt;
00008 class KMatrix;
00009
00010
00011 COMMON_API bool IntersectTriangle( KVector& orig, KVector& dir, KVector& v0, KVector& v1, KVector& v2, float* t, float* u, float* v );
00012 COMMON_API bool IntersectTriangleCullNone( KVector& orig, KVector& dir, KVector& v0, KVector& v1, KVector& v2, float* t, float* u, float* v );
00013 COMMON_API bool IntersectTriangle( KVector& center, float radius, KVector& v0, KVector& v1, KVector& v2, KVector* pPoint );
00014 void ComputePickVector( KMatrix& MatProj, KMatrix& MatView, KPt& PickPoint, KPt& ViewportSize, KVector* PickRayOrig, KVector* PickRayDir );
00015
00016
00017
00018 class COMMON_API KCollisionData
00019 {
00020 public:
00021
00022 KVector m_Velocity;
00023 KVector m_Position;
00024
00025
00026 KVector m_Radius;
00027
00028
00029 KVector m_LastSafePosition;
00030 bool m_bStuck;
00031
00032
00033 bool m_bFoundCollision;
00034 float m_NearestDistance;
00035 KVector m_NearestIntersectionPoint;
00036 KVector m_NearestPolygonIntersectionPoint;
00037
00038 KCollisionData()
00039 {
00040 Reset();
00041 }
00042
00043 void Reset()
00044 {
00045 m_bStuck = false;
00046 m_bFoundCollision = false;
00047 m_NearestDistance = -1.0f;
00048 }
00049 };
00050
00051
00052 class COMMON_API KCollisionData2
00053 {
00054 public:
00055
00056 KVector m_eRadius;
00057
00058
00059 KVector m_R3Velocity;
00060 KVector m_R3Position;
00061
00062
00063 KVector m_Velocity;
00064 KVector m_NormalizedVelocity;
00065 KVector m_BasePoint;
00066
00067
00068 bool m_bFoundCollision;
00069 double m_NearestDistance;
00070 KVector m_IntersectionPoint;
00071 KVector m_CollisionNormal;
00072
00073 KCollisionData2()
00074 {
00075 Reset();
00076 }
00077
00078 void Reset()
00079 {
00080 m_bFoundCollision = false;
00081 m_NearestDistance = -1.0f;
00082 }
00083 };
00084
00085
00086 KVector ClosestPointOnLine( KVector& Point, KVector& v0, KVector& v1 );
00087 KVector ClosestPointOnTriangle( KVector& Point, KVector& v0, KVector& v1, KVector& v2 );
00088 bool CheckPointInTriangle( KVector& Point, KVector& v0, KVector& v1, KVector& v2 );
00089 bool CheckPointInSphere( KVector Point, KVector& sO, float sR );
00090
00091 COMMON_API float IntersectRayPlaneDistance( KVector& RayOrigin, KVector& RayVector, KVector& PointOrigin, KVector& PointNormal );
00092 float IntersectRaySphere( KVector& RayOrigin, KVector& RayVector, KVector& SphereOrigin, float SphereRadius );
00093
00094 COMMON_API bool CheckSphereCollision( KCollisionData* pData, KVector v0, KVector v1, KVector v2, float Epsilon = 0.1f );
00095 COMMON_API void CheckSphereCollision2( KCollisionData2* pData, KVector v0, KVector v1, KVector v2 );
00096 COMMON_API float IntersectRayPlaneDistance( KVector& RayOrigin, KVector& RayVector, KVector& PlaneNormal, float PlaneDist );
00097 COMMON_API bool CheckRayEllipse( KVector& vRayOrigin, KVector& vRayDestination, KVector& vEllipseOrigin, KVector& vEllipseRadius, float* pFraction );
00098 COMMON_API bool CheckRaySphere( KVector& vRayOrigin, KVector& vRayDestination, KVector& vSphereCenter, float SphereRadius, float* pFraction );
00099 COMMON_API void GetLocalAngleFromNormal( KVector& Normal, float& AngleX, float& AngleY, float& AngleZ );
00100
00101 #endif __MATH3D_H__