00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #pragma once
00034
00035 #include "K3dVector3.h"
00036 #include "../Geometry/K3dRay.h"
00037 #include "../Geometry/K3dPlane.h"
00038 #include "../System/GameData/K3dGameData.h"
00039 #include "../System/Worker/K3dVector3Work.h"
00040
00041 class K3dDistance
00042 {
00043 K3dGameData *m_pGameData;
00044 public:
00045 K3dDistance ( K3dGameData *_pGameData );
00046 ~K3dDistance();
00047
00049 float Points ( const K3dVector3Obj &_rkV0, const K3dVector3Obj &_rkV1 )
00050 {
00051
00052 K3dVector3Obj kV;
00053 kV = m_pGameData->GetVector3Work()->VectorBetween ( _rkV0, _rkV1 );
00054
00055 return m_pGameData->GetVector3Work()->Length ( kV );
00056 }
00057
00059 float SqrPointRay ( const K3dVector3Obj &_rkPoint,const K3dRay &_rkRay, float* _pfParam=NULL )
00060 {
00061 float fDotMM;
00062 float fT = ( float ) 0;
00063 K3dVector3Obj kDiff;
00064
00065
00066 kDiff = _rkPoint - *_rkRay.GetOrigin();
00067 fT = m_pGameData->GetVector3Work()->Dot ( kDiff, *_rkRay.GetDirection() );
00068
00069
00070 if ( fT <= ( float ) 0.0 )
00071 {
00072 fT = ( float ) 0.0;
00073 }
00074 else
00075 {
00076 fDotMM = m_pGameData->GetVector3Work()->SquaredLength ( *_rkRay.GetDirection() );
00077 if ( fDotMM )
00078 {
00079 fT = fT / fDotMM;
00080 kDiff -= *_rkRay.GetDirection() *fT;
00081 }
00082 }
00083
00084 if ( _pfParam )
00085 *_pfParam = fT;
00086
00087 return m_pGameData->GetVector3Work()->SquaredLength ( kDiff );
00088
00089 }
00090
00099 int PointPlane ( const K3dPlane &_rkPlane,const K3dVector3 &_rkPoint )
00100 {
00101 float fD;
00102 K3dVector3 kNormal = *_rkPlane.GetNormal();
00103
00104 fD = kNormal[0] * _rkPoint[0] +
00105 kNormal[1] * _rkPoint[1] +
00106 kNormal[2] * _rkPoint[2] - _rkPlane.GetDistance();
00107
00108 return ( int ) fD;
00109 }
00110
00115 int DistLinePlane ( const K3dPlane &_rkPlane, const K3dVector3 &_rkLineOrigin, const K3dVector3 &_rkLineDirection )
00116 {
00117
00118 float fDistOrigin = PointPlane ( _rkPlane, _rkLineOrigin );
00119
00120 float fDistDirection = PointPlane ( _rkPlane, _rkLineDirection );
00121
00122
00123 int iSignOrigin = ( int ) K3dMath::Sign ( fDistOrigin );
00124 int iSignDirection = ( int ) K3dMath::Sign ( fDistDirection );
00125
00126
00127 if ( iSignOrigin == iSignDirection )
00128 {
00129 return iSignOrigin;
00130 }
00131 else
00132 {
00133
00134 return 0;
00135 }
00136 }
00137
00138 };
00139