"L. Spiro Engine"
|
00001 00017 #ifndef __LSM_LINE3_H__ 00018 #define __LSM_LINE3_H__ 00019 00020 #include "../LSMMathLib.h" 00021 #include "../Vector/LSMVector3.h" 00022 00023 namespace lsm { 00024 00031 class CLine3 { 00032 // All is public. This class has no secrets. 00033 public : 00034 // == Various constructors. 00035 LSE_INLINE LSE_CALLCTOR CLine3(); 00036 LSE_INLINE LSE_CALLCTOR CLine3( const CVector3 &_vStart, const CVector3 &_vEnd ); 00037 LSE_INLINE LSE_CALLCTOR CLine3( const CLine3 &_lLine ); 00038 00039 00040 // == Functions. 00050 LSE_INLINE CVector3 LSE_FCALL ClosestPointOnLineToPoint( const CVector3 &_vPoint, LSREAL &_fT ) const; 00051 00052 00053 // == Members. 00057 CVector3 p; 00058 00062 CVector3 q; 00063 }; 00064 00065 00066 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00067 // DEFINITIONS 00068 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00069 // == Various constructors. 00070 LSE_INLINE LSE_CALLCTOR CLine3::CLine3() { 00071 } 00072 LSE_INLINE LSE_CALLCTOR CLine3::CLine3( const CVector3 &_vStart, const CVector3 &_vEnd ) { 00073 p = _vStart; 00074 q = _vEnd; 00075 } 00076 LSE_INLINE LSE_CALLCTOR CLine3::CLine3( const CLine3 &_lLine ) { 00077 (*this) = _lLine; 00078 } 00079 00080 // == Functions. 00090 LSE_INLINE CVector3 LSE_FCALL CLine3::ClosestPointOnLineToPoint( const CVector3 &_vPoint, LSREAL &_fT ) const { 00091 CVector3 vAb = q - p; 00092 // Project C onto AB, computing parameterized position d(t) = a + t*(b - a). 00093 _fT = vAb.Dot( _vPoint - p ) / vAb.LenSq(); 00094 return p + (vAb * _fT); 00095 } 00096 00097 } // namespace lsm 00098 00099 #endif // __LSM_LINE3_H__