"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSMathLib/Src/Triangle/LSMTriangle3.h

00001 
00017 #ifndef __LSM_TRIANGLE3_H__
00018 #define __LSM_TRIANGLE3_H__
00019 
00020 #include "../LSMMathLib.h"
00021 #include "../Vector/LSMVector3.h"
00022 
00023 namespace lsm {
00024 
00030         class CTriangle3 {
00031                 // All is public.  This class has no secrets.
00032         public :
00033                 // == Various constructors.
00034                 LSE_INLINE LSE_CALLCTOR                                         CTriangle3();
00035                 LSE_INLINE LSE_CALLCTOR                                         CTriangle3( const CTriangle3 &_tTri );
00036                 LSE_INLINE LSE_CALLCTOR                                         CTriangle3( const CVector3 &_vA, const CVector3 &_vB, const CVector3 &_vC );
00037 
00038 
00039                 // == Operators.
00046                 LSE_INLINE CVector3 & LSE_FCALL                         operator [] ( LSUINT32 _ui32I );
00047 
00054                 LSE_INLINE const CVector3 & LSE_FCALL           operator [] ( LSUINT32 _ui32I ) const;
00055 
00062                 LSE_INLINE bool LSE_FCALL                                       operator == ( const CTriangle3 &_tTri ) const;
00063 
00070                 LSE_INLINE bool LSE_FCALL                                       operator != ( const CTriangle3 &_tTri ) const;
00071 
00072 
00073                 // == Functions.
00077                 LSE_INLINE LSVOID LSE_FCALL                                     ReverseOrder();
00078 
00084                 LSE_INLINE const CVector3 & LSE_FCALL           A() const;
00085 
00091                 LSE_INLINE const CVector3 & LSE_FCALL           B() const;
00092 
00098                 LSE_INLINE const CVector3 & LSE_FCALL           C() const;
00099 
00109                 LSVOID LSE_FCALL                                                        Barycentric( const CVector3 &_vPoint,
00110                         LSREAL &_fU, LSREAL &_fV, LSREAL &_fW ) const;
00111 
00112 
00113 
00114                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00115                 // DISTANCE TESTS
00116                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00117                 // == Points.
00124                 CVector3 LSE_FCALL                                                      ClosestPointToPoint( const CVector3 &_vPoint ) const;
00125                 
00133                 LSREAL LSE_FCALL                                                        GetSqDistFromPoint( const CVector3 &_vPoint ) const;
00134 
00141                 LSBOOL LSE_FCALL                                                        PointIsInTriangle( const CVector3 &_vPoint ) const;
00142 
00143 
00144                 // == Members.
00145 #pragma pack( push, 1 )
00146                 CVector3                                                                        a;
00147                 CVector3                                                                        b;
00148                 CVector3                                                                        c;
00149 #pragma pack( pop )
00150 
00151 
00152         protected :
00153                 // == Functions.
00165                 LSE_INLINE static LSREAL LSE_FCALL                      TriArea2D( LSREAL _fX1, LSREAL _fY1,
00166                         LSREAL _fX2, LSREAL _fY2,
00167                         LSREAL _fX3, LSREAL _fY3 );
00168         };
00169 
00170 
00171         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00172         // DEFINITIONS
00173         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00174         // == Various constructors.
00175         LSE_INLINE LSE_CALLCTOR CTriangle3::CTriangle3() {}
00176         LSE_INLINE LSE_CALLCTOR CTriangle3::CTriangle3( const CTriangle3 &_tTri ) :
00177                 a( _tTri.a ),
00178                 b( _tTri.b ),
00179                 c( _tTri.c ) {
00180         }
00181                 LSE_INLINE LSE_CALLCTOR CTriangle3::CTriangle3( const CVector3 &_vA, const CVector3 &_vB, const CVector3 &_vC ) :
00182                 a( _vA ),
00183                 b( _vB ),
00184                 c( _vC ) {
00185         }
00186 
00187         // == Operators.
00194         LSE_INLINE CVector3 & LSE_FCALL CTriangle3::operator [] ( LSUINT32 _ui32I ) { return reinterpret_cast<CVector3 *>(this)[_ui32I]; }
00195 
00202         LSE_INLINE const CVector3 & LSE_FCALL CTriangle3::operator [] ( LSUINT32 _ui32I ) const { return reinterpret_cast<const CVector3 *>(this)[_ui32I]; }
00203 
00210         LSE_INLINE bool LSE_FCALL CTriangle3::operator == ( const CTriangle3 &_tTri ) const {
00211                 return a == _tTri.a && b == _tTri.b && c == _tTri.c;
00212         }
00213 
00220         LSE_INLINE bool LSE_FCALL CTriangle3::operator != ( const CTriangle3 &_tTri ) const {
00221                 return a != _tTri.a || b != _tTri.b || c != _tTri.c;
00222         }
00223 
00224         // == Functions.
00228         LSE_INLINE LSVOID LSE_FCALL CTriangle3::ReverseOrder() {
00229                 CMathLib::Swap( a, c );
00230         }
00231 
00237         LSE_INLINE const CVector3 & LSE_FCALL CTriangle3::A() const { return a; }
00238 
00244         LSE_INLINE const CVector3 & LSE_FCALL CTriangle3::B() const { return b; }
00245 
00251         LSE_INLINE const CVector3 & LSE_FCALL CTriangle3::C() const { return c; }
00252 
00264         LSE_INLINE LSREAL LSE_FCALL CTriangle3::TriArea2D( LSREAL _fX1, LSREAL _fY1,
00265                 LSREAL _fX2, LSREAL _fY2,
00266                 LSREAL _fX3, LSREAL _fY3 ) {
00267                 return (_fX1 - _fX2) * (_fY2 - _fY3) - (_fX2 - _fX3) * (_fY1 - _fY2);
00268         }
00269 
00270 }       // namespace lsm
00271 
00272 #endif  // __LSM_TRIANGLE3_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator