"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSPhysicsLib/Src/Intersections/LSPIntersect.h

00001 
00016 #ifndef __LSP_INTERSECT_H__
00017 #define __LSP_INTERSECT_H__
00018 
00019 #include "../LSPPhysicsLib.h"
00020 #include "Plane/LSMPlane3.h"
00021 
00022 namespace lsp {
00023 
00030         class CIntersect {
00031                 // All is public.  This class has no secrets.
00032         public :
00033                 // == Functions.
00043                 template <typename _tType, typename _tPlaneType, typename _tVecType>
00044                 static LSE_INLINE LSBOOL LSE_CALL                                               ThreePlanes( const _tPlaneType &_pP0, const _tPlaneType &_pP1, const _tPlaneType &_pP2, _tVecType &_vRet ) {
00045                         _tVecType vU = _pP1.n % _pP2.n;
00046 
00047                         _tType fDenom = _pP0.n * vU;
00048                         if ( CMathLib::AbsT( fDenom ) <= static_cast<_tType>(LSM_REAL_EPSILON) ) { return false; }
00049 
00050                         _vRet = (vU * _pP0.dist + _pP0.n.Cross( _pP1.n * _pP2.dist - _pP2.n * _pP1.dist )) / fDenom;
00051 
00052                         return true;
00053                 }
00054 
00063                 template <typename _tType, typename _tPlaneType, typename _tRayType>
00064                 static LSE_INLINE LSBOOL LSE_CALL                                               TwoPlanes( const _tPlaneType &_pP0, const _tPlaneType &_pP1, _tRayType &_rRay ) {
00065                         // Direction of the intersection.
00066                         _rRay.dir = _pP0.n % _pP1.n;
00067 
00068                         // If it is (near) 0, the planes are parallel (and separated) or coincident and not considered
00069                         //      intersecting.
00070                         if ( _rRay.dir.Dot( _rRay.dir ) < static_cast<_tType>(LSM_REAL_EPSILON) ) { return false; }
00071 
00072                         // Finish the ray by computing a point on the intersection line.
00073                         _rRay.p = ((_pP1.n * _pP0.dist) - (_pP0.n * _pP1.dist)) % _rRay.dir;
00074                         return true;
00075                 }
00076 
00088                 template <typename _tType, typename _tVecType, typename _tPlaneType>
00089                 static LSE_INLINE LSBOOL LSE_CALL                                               LineSegPlane( const _tVecType &_vStart, const _tVecType &_vEnd, const _tPlaneType &_pPlane, _tType &_fT, _tVecType &_vRet ) {
00090                         _tVecType vAb = _vEnd - _vStart;
00091                         _tType fDenom = _pPlane.n.Dot( vAb );
00092                         if ( fDenom == static_cast<_tType>(0.0) ) {
00093                                 // Coplanar.
00094                                 return false;
00095                         }
00096                         _fT = (_pPlane.dist - _pPlane.n.Dot( _vStart )) / fDenom;
00097                         if ( _fT >= static_cast<_tType>(0.0) && _fT <= static_cast<_tType>(1.0) ) {
00098                                 _vRet = _vStart + vAb * _fT;
00099                                 return true;
00100                         }
00101                         return false;
00102                 }
00103 
00112                 template <typename _tType, typename _tVecType, typename _tPlaneType>
00113                 static LSE_INLINE LSVOID LSE_CALL                                               LineSegPlaneFast( const _tVecType &_vStart, const _tVecType &_vEnd, const _tPlaneType &_pPlane, _tVecType &_vRet ) {
00114                         _tVecType vAb = _vEnd - _vStart;
00115                         _tType fT = (_pPlane.dist - _pPlane.n.Dot( _vStart )) / _pPlane.n.Dot( vAb );
00116                         _vRet = _vStart + vAb * fT;
00117                 }
00118 
00119         };
00120 
00121 
00122         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00123         // DEFINITIONS
00124         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00125         // == Functions.
00126 
00127 }       // namespace lsp
00128 
00129 #endif  // __LSP_INTERSECT_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator