"L. Spiro Engine"
|
00001 00016 #ifndef __LSM_ORIENTATION_H__ 00017 #define __LSM_ORIENTATION_H__ 00018 00019 #include "../LSMMathLib.h" 00020 #include "../Vector/LSMVector3.h" 00021 #include "../Matrix/LSMMatrix4x4.h" 00022 00023 namespace lsm { 00024 00025 // == Types. 00029 enum LSM_ORIENT_DIRTY_FLAGS { 00030 LSM_ODF_POSITION = (1 << 0), /*< Position is dirty. */ 00031 LSM_ODF_ROTATION = (1 << 1), /*< Rotation is dirty. */ 00032 LSM_ODF_SCALE = (1 << 2), /*< Scale is dirty. */ 00033 LSM_ODF_NORMALIZATION = (1 << 3), /*< Vectors need normalizing. */ 00034 }; 00035 00042 class COrientation { 00043 public : 00044 // == Various constructors. 00045 LSE_INLINE LSE_CALLCTOR COrientation(); 00046 LSE_INLINE LSE_CALLCTOR COrientation( const COrientation &_oSrc ); 00047 00048 00049 // == Operators. 00057 LSE_INLINE COrientation & LSE_FCALL operator = ( const COrientation &_oSrc ); 00058 00059 00060 // == Functions. 00066 LSE_INLINE const CVector3 & LSE_FCALL GetScale() const; 00067 00073 LSE_INLINE const CVector3 & LSE_FCALL GetPos() const; 00074 00080 LSE_INLINE const CVector3 & LSE_FCALL GetForward() const; 00081 00087 LSE_INLINE const CVector3 & LSE_FCALL GetRight() const; 00088 00094 LSE_INLINE const CVector3 & LSE_FCALL GetUp() const; 00095 00099 LSVOID LSE_FCALL SetIdentity(); 00100 00104 LSVOID LSE_FCALL ClearPosition(); 00105 00109 LSVOID LSE_FCALL ClearRotation(); 00110 00114 LSVOID LSE_FCALL ClearScale(); 00115 00121 LSVOID LSE_FCALL SetPos( const CVector3 &_vPos ); 00122 00129 LSVOID LSE_FCALL SetPosU( const CVector3 &_vPos ); 00130 00136 LSVOID LSE_FCALL AddPos( const CVector3 &_vPos ); 00137 00143 LSVOID LSE_FCALL SetRelPos( const CVector3 &_vPos ); 00144 00150 LSVOID LSE_FCALL AddRelPos( const CVector3 &_vPos ); 00151 00157 LSVOID LSE_FCALL SetRotation( const CMatrix4x4 &_mMat ); 00158 00164 LSVOID LSE_FCALL AddRotation( const CMatrix4x4 &_mMat ); 00165 00173 LSVOID LSE_FCALL SetRotation( const CVector3 &_vForward, const CVector3 &_vUp ); 00174 00182 LSVOID LSE_FCALL SetRotationEasy( const CVector3 &_vForward, const CVector3 &_vUp ); 00183 00191 LSVOID LSE_FCALL AddRotation( const CVector3 &_vForward, const CVector3 &_vUp ); 00192 00198 LSVOID LSE_FCALL Yaw( LSREAL _fAmount ); 00199 00205 LSVOID LSE_FCALL SetYaw( LSREAL _fAmount ); 00206 00212 LSVOID LSE_FCALL Pitch( LSREAL _fAmount ); 00213 00219 LSVOID LSE_FCALL Roll( LSREAL _fAmount ); 00220 00228 LSVOID LSE_FCALL SetRotationYawPitchRoll( LSREAL _fYaw, LSREAL _fPitch, LSREAL _fRoll ); 00229 00235 LSVOID LSE_FCALL SetScale( const CVector3 &_vScale ); 00236 00242 LSVOID LSE_FCALL AddScale( const CVector3 &_vScale ); 00243 00249 LSVOID LSE_FCALL SetScale( LSREAL _fScale ); 00250 00256 LSVOID LSE_FCALL AddScale( LSREAL _fScale ); 00257 00263 LSVOID LSE_FCALL BuildMatrix( CMatrix4x4 &_mRet ) const; 00264 00276 LSBOOL LSE_FCALL UpdateMatrix( CMatrix4x4 &_mRet, LSBOOL _bClearDirty = true ) const; 00277 00283 LSE_INLINE LSBOOL LSE_FCALL IsDirty() const; 00284 00288 LSE_INLINE LSVOID LSE_FCALL MakeDirty(); 00289 00293 LSE_INLINE LSVOID LSE_FCALL UndirtyRotations() const; 00294 00295 00296 protected : 00297 // == Members. 00301 mutable CVector3 m_vRight, 00302 m_vUp, 00303 m_vForward; 00304 00308 CVector3 m_vPos; 00309 00313 CVector3 m_vScale; 00314 00318 mutable LSUINT32 m_ui32Dirty; 00319 }; 00320 00321 00322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00323 // DEFINITIONS 00324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00325 // == Various constructors. 00326 LSE_INLINE LSE_CALLCTOR COrientation::COrientation() : 00327 m_vRight( LSM_ONE, LSM_ZERO, LSM_ZERO ), 00328 m_vUp( LSM_ZERO, LSM_ONE, LSM_ZERO ), 00329 m_vForward( LSM_ZERO, LSM_ZERO, LSM_ONE ), 00330 m_vPos( LSM_ZERO, LSM_ZERO, LSM_ZERO ), 00331 m_vScale( LSM_ONE, LSM_ONE, LSM_ONE ), 00332 m_ui32Dirty( LSM_ODF_POSITION | LSM_ODF_ROTATION | LSM_ODF_SCALE ) { 00333 } 00334 LSE_INLINE LSE_CALLCTOR COrientation::COrientation( const COrientation &_oSrc ) : 00335 m_vRight( _oSrc.m_vRight ), 00336 m_vUp( _oSrc.m_vUp ), 00337 m_vForward( _oSrc.m_vForward ), 00338 m_vPos( _oSrc.m_vPos ), 00339 m_vScale( _oSrc.m_vScale ), 00340 m_ui32Dirty( _oSrc.m_ui32Dirty ) { 00341 } 00342 00343 // == Operators. 00351 LSE_INLINE COrientation & LSE_FCALL COrientation::operator = ( const COrientation &_oSrc ) { 00352 m_vRight = _oSrc.m_vRight; 00353 m_vUp = _oSrc.m_vUp; 00354 m_vForward = _oSrc.m_vForward; 00355 m_vPos = _oSrc.m_vPos; 00356 m_vScale = _oSrc.m_vScale; 00357 m_ui32Dirty = LSM_ODF_NORMALIZATION | LSM_ODF_POSITION | LSM_ODF_ROTATION | LSM_ODF_SCALE; 00358 return (*this); 00359 } 00360 00361 // == Functions. 00367 LSE_INLINE const CVector3 & LSE_FCALL COrientation::GetScale() const { return m_vScale; } 00368 00374 LSE_INLINE const CVector3 & LSE_FCALL COrientation::GetPos() const { return m_vPos; } 00375 00381 LSE_INLINE const CVector3 & LSE_FCALL COrientation::GetForward() const { const_cast<COrientation *>(this)->UndirtyRotations(); return m_vForward; } 00382 00388 LSE_INLINE const CVector3 & LSE_FCALL COrientation::GetRight() const { const_cast<COrientation *>(this)->UndirtyRotations(); return m_vRight; } 00389 00395 LSE_INLINE const CVector3 & LSE_FCALL COrientation::GetUp() const { const_cast<COrientation *>(this)->UndirtyRotations(); return m_vUp; } 00396 00402 LSE_INLINE LSBOOL LSE_FCALL COrientation::IsDirty() const { 00403 return m_ui32Dirty != 0; 00404 } 00405 00409 LSE_INLINE LSVOID LSE_FCALL COrientation::MakeDirty() { 00410 m_ui32Dirty = LSM_ODF_NORMALIZATION | LSM_ODF_POSITION | LSM_ODF_ROTATION | LSM_ODF_SCALE; 00411 } 00412 00416 LSE_INLINE LSVOID LSE_FCALL COrientation::UndirtyRotations() const { 00417 if ( m_ui32Dirty & LSM_ODF_NORMALIZATION ) { 00418 m_vRight.Normalize(); 00419 m_vUp.Normalize(); 00420 m_vForward.Normalize(); 00421 m_ui32Dirty &= ~static_cast<LSUINT32>(LSM_ODF_NORMALIZATION); 00422 } 00423 } 00424 00425 } // namespace lsm 00426 00427 #endif // __LSM_ORIENTATION_H__