OpenBarnyard
 
Loading...
Searching...
No Matches
TTransformObject Class Reference

#include <TTransformObject.h>

Public Types

enum class  Mode { Quat = 0 , Euler , Matrix }
 

Public Member Functions

 TTransformObject ()
 
 ~TTransformObject ()
 
void Push ()
 
void Pop ()
 
TVector3GetTranslation ()
 
void GetLocalMatrixImp (TMatrix44 &a_rOutMatrix)
 
void SetEuler (const TVector3 &a_rEuler)
 
void SetEulerOrder (TUINT8 a_uiX, TUINT8 a_uiy, TUINT8 a_uiz)
 
void SetTranslate (const TVector3 &a_rRranslation)
 
void SetQuat (const TQuaternion &a_rQuaternion)
 
void SetMatrix (const TMatrix44 &a_rMatrix)
 
void ResetChangedState ()
 
TBOOL HasChanged () const
 
Mode GetMode () const
 
const TVector3GetScale () const
 

Detailed Description

Definition at line 8 of file TTransformObject.h.

Member Enumeration Documentation

◆ Mode

enum class TTransformObject::Mode
strong
Enumerator
Quat 
Euler 
Matrix 

Definition at line 11 of file TTransformObject.h.

12 {
13 Quat = 0,
14 Euler,
15 Matrix
16 };

Constructor & Destructor Documentation

◆ TTransformObject()

TTransformObject::TTransformObject ( )

Definition at line 13 of file TTransformObject.cpp.

14 : m_eMode( Mode::Quat ), m_Quat( TQuaternion::IDENTITY ), m_Translation( TVector3::VEC_ZERO ), m_Scale( 1.0f, 1.0f, 1.0f )
15{
16 m_EulerOrder[ 0 ] = 2;
17 m_EulerOrder[ 1 ] = 1;
18 m_EulerOrder[ 2 ] = 0;
19}
static const TQuaternion IDENTITY
Definition TQuaternion.h:7
static constinit const TVector3 VEC_ZERO
Definition TVector3.h:150

◆ ~TTransformObject()

TTransformObject::~TTransformObject ( )

Definition at line 21 of file TTransformObject.cpp.

22{
23}

Member Function Documentation

◆ GetLocalMatrixImp()

void TTransformObject::GetLocalMatrixImp ( TMatrix44 & a_rOutMatrix)

Definition at line 84 of file TTransformObject.cpp.

85{
86 if ( m_eMode == Mode::Quat )
87 {
88 outMatrix.SetFromQuaternion( m_Quat );
89 outMatrix.SetTranslation( m_Translation );
90 outMatrix.Scale( m_Scale.x, m_Scale.y, m_Scale.z );
91 }
92 else if ( m_eMode == Mode::Euler )
93 {
94 outMatrix.Identity();
95 outMatrix.SetTranslation( GetTranslation() );
96
97 for ( TINT i = 0; i < 3; i++ )
98 {
99 switch ( m_EulerOrder[ i ] )
100 {
101 case 0:
102 outMatrix.RotateX( m_Euler.x );
103 break;
104 case 1:
105 outMatrix.RotateY( m_Euler.y );
106 break;
107 case 2:
108 outMatrix.RotateZ( m_Euler.z );
109 break;
110 }
111 }
112
113 outMatrix.Scale( m_Scale.x, m_Scale.y, m_Scale.z );
114 }
115 else
116 {
117 TASSERT( m_eMode == Mode::Matrix );
118 outMatrix = m_Matrix;
119 }
120}
#define TASSERT(X,...)
Definition Defines.h:138
int TINT
Definition Typedefs.h:7
TVector3 & GetTranslation()

◆ GetMode()

Mode TTransformObject::GetMode ( ) const
inline

Definition at line 44 of file TTransformObject.h.

45 {
46 return m_eMode;
47 }

◆ GetScale()

const TVector3 & TTransformObject::GetScale ( ) const
inline

Definition at line 49 of file TTransformObject.h.

50 {
51 return m_Scale;
52 }

◆ GetTranslation()

Toshi::TVector3 & TTransformObject::GetTranslation ( )

Definition at line 79 of file TTransformObject.cpp.

80{
81 return ( m_eMode != Mode::Matrix ) ? m_Translation : m_Matrix.GetTranslation().AsVector3();
82}

◆ HasChanged()

TBOOL TTransformObject::HasChanged ( ) const
inline

Definition at line 39 of file TTransformObject.h.

40 {
41 return m_bChanged;
42 }

◆ Pop()

void TTransformObject::Pop ( )

Definition at line 71 of file TTransformObject.cpp.

72{
73 auto pRender = TRenderInterface::GetSingleton();
74
75 pRender->GetTransforms().Pop();
76 pRender->GetCurrentContext()->SetModelViewMatrix( pRender->GetTransforms().Top() );
77}
static TFORCEINLINE TRenderInterface * GetSingleton()
Definition TSingleton.h:49

◆ Push()

void TTransformObject::Push ( )

Definition at line 25 of file TTransformObject.cpp.

26{
27 auto pRender = TRenderInterface::GetSingleton();
28
29 auto pPrevTransform = &pRender->GetTransforms().Top();
30
31 pRender->GetTransforms().PushNull();
32 auto pPushTransform = &pRender->GetTransforms().Top();
33
34 if ( m_eMode == Mode::Quat )
35 {
36 pPushTransform->PushQuaternion( m_Quat, *pPrevTransform, m_Translation );
37 pPushTransform->Scale( m_Scale.x, m_Scale.y, m_Scale.z );
38 }
39 else if ( m_eMode == Mode::Euler )
40 {
41 *pPushTransform = *pPrevTransform;
42 TMatrix44::TransformVector( pPushTransform->GetTranslation().AsVector3(), *pPushTransform, GetTranslation() );
43
44 for ( TINT i = 0; i < 3; i++ )
45 {
46 switch ( m_EulerOrder[ i ] )
47 {
48 case 0:
49 pPushTransform->RotateX( m_Euler.x );
50 break;
51 case 1:
52 pPushTransform->RotateY( m_Euler.y );
53 break;
54 case 2:
55 pPushTransform->RotateZ( m_Euler.z );
56 break;
57 }
58 }
59
60 pPushTransform->Scale( m_Scale.x, m_Scale.y, m_Scale.z );
61 }
62 else
63 {
64 TASSERT( m_eMode == Mode::Matrix );
65 pPushTransform->Multiply( *pPrevTransform, m_Matrix );
66 }
67
68 pRender->GetCurrentContext()->SetModelViewMatrix( pRender->GetTransforms().Top() );
69}
static constexpr void TransformVector(TVector3 &a_rOutVector, const TMatrix44 &a_rMatrix, const TVector3 &a_rVector)
Definition TMatrix44.h:280

◆ ResetChangedState()

void TTransformObject::ResetChangedState ( )
inline

Definition at line 34 of file TTransformObject.h.

35 {
36 m_bChanged = TFALSE;
37 }
#define TFALSE
Definition Typedefs.h:24

◆ SetEuler()

void TTransformObject::SetEuler ( const TVector3 & a_rEuler)

Definition at line 122 of file TTransformObject.cpp.

123{
124 m_eMode = Mode::Euler;
125 m_Euler = a_rEuler;
126}

◆ SetEulerOrder()

void TTransformObject::SetEulerOrder ( TUINT8 a_uiX,
TUINT8 a_uiy,
TUINT8 a_uiz )

Definition at line 128 of file TTransformObject.cpp.

129{
130 m_EulerOrder[ 0 ] = x;
131 m_EulerOrder[ 1 ] = y;
132 m_EulerOrder[ 2 ] = z;
133}

◆ SetMatrix()

void TTransformObject::SetMatrix ( const TMatrix44 & a_rMatrix)

Definition at line 149 of file TTransformObject.cpp.

150{
151 m_eMode = Mode::Matrix;
152 m_Matrix = matrix;
153 m_Translation = matrix.GetTranslation3();
154}

◆ SetQuat()

void TTransformObject::SetQuat ( const TQuaternion & a_rQuaternion)

Definition at line 143 of file TTransformObject.cpp.

144{
145 m_eMode = Mode::Quat;
146 m_Quat = quaternion;
147}

◆ SetTranslate()

void TTransformObject::SetTranslate ( const TVector3 & a_rRranslation)

Definition at line 135 of file TTransformObject.cpp.

136{
137 m_Translation = translation;
138
139 if ( m_eMode == Mode::Matrix )
140 m_Matrix.SetTranslation( m_Translation );
141}

Member Data Documentation

◆ m_Euler

TVector3 TTransformObject::m_Euler

Definition at line 78 of file TTransformObject.h.

◆ m_Matrix

TMatrix44 TTransformObject::m_Matrix

Definition at line 76 of file TTransformObject.h.

◆ m_Quat

TQuaternion TTransformObject::m_Quat

Definition at line 77 of file TTransformObject.h.


The documentation for this class was generated from the following files: