OpenBarnyard
 
Loading...
Searching...
No Matches
TTransformObject.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TTransformObject.h"
3#include "TRenderInterface.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
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}
20
24
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}
70
72{
73 auto pRender = TRenderInterface::GetSingleton();
74
75 pRender->GetTransforms().Pop();
76 pRender->GetCurrentContext()->SetModelViewMatrix( pRender->GetTransforms().Top() );
77}
78
80{
81 return ( m_eMode != Mode::Matrix ) ? m_Translation : m_Matrix.GetTranslation().AsVector3();
82}
83
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}
121
123{
124 m_eMode = Mode::Euler;
125 m_Euler = a_rEuler;
126}
127
129{
130 m_EulerOrder[ 0 ] = x;
131 m_EulerOrder[ 1 ] = y;
132 m_EulerOrder[ 2 ] = z;
133}
134
135void TTransformObject::SetTranslate( const TVector3& translation )
136{
137 m_Translation = translation;
138
139 if ( m_eMode == Mode::Matrix )
140 m_Matrix.SetTranslation( m_Translation );
141}
142
143void TTransformObject::SetQuat( const TQuaternion& quaternion )
144{
145 m_eMode = Mode::Quat;
146 m_Quat = quaternion;
147}
148
150{
151 m_eMode = Mode::Matrix;
152 m_Matrix = matrix;
153 m_Translation = matrix.GetTranslation3();
154}
155
Rendering system interface for the Toshi engine.
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
uint8_t TUINT8
Definition Typedefs.h:17
int TINT
Definition Typedefs.h:7
TVector3 & GetTranslation3()
Definition TMatrix44.h:147
static constexpr void TransformVector(TVector3 &a_rOutVector, const TMatrix44 &a_rMatrix, const TVector3 &a_rVector)
Definition TMatrix44.h:280
void RotateZ(TFLOAT a_fAngle)
void RotateX(TFLOAT a_fAngle)
constexpr void Scale(TFLOAT a_fScalar1, TFLOAT a_fScalar2, TFLOAT a_fScalar3)
Definition TMatrix44.h:176
constexpr void Identity()
Definition TMatrix44.h:110
void SetTranslation(const TVector4 &a_rTranslation)
Definition TMatrix44.h:167
void RotateY(TFLOAT a_fAngle)
TMatrix44 & SetFromQuaternion(const TQuaternion &a_rQuaternion)
void SetEulerOrder(TUINT8 a_uiX, TUINT8 a_uiy, TUINT8 a_uiz)
void SetEuler(const TVector3 &a_rEuler)
TVector3 & GetTranslation()
void SetTranslate(const TVector3 &a_rRranslation)
void GetLocalMatrixImp(TMatrix44 &a_rOutMatrix)
void SetQuat(const TQuaternion &a_rQuaternion)
void SetMatrix(const TMatrix44 &a_rMatrix)
static TFORCEINLINE TRenderInterface * GetSingleton()
Definition TSingleton.h:49