OpenBarnyard
 
Loading...
Searching...
No Matches
AGUI2Transform.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AGUI2Transform.h"
3
4//-----------------------------------------------------------------------------
5// Enables memory debugging.
6// Note: Should be the last include!
7//-----------------------------------------------------------------------------
9
11
13{
14 TFLOAT fSin, fCos;
15 TMath::SinCos( a_fAngle, fSin, fCos );
16
17 TVector2 vecRot0 = m_aMatrixRows[ 0 ];
18 TVector2 vecRot1 = m_aMatrixRows[ 1 ];
19
20 m_aMatrixRows[ 0 ].x = vecRot0.x * fCos + vecRot1.x * fSin;
21 m_aMatrixRows[ 0 ].y = vecRot0.y * fCos + vecRot1.y * fSin;
22 m_aMatrixRows[ 1 ].x = vecRot1.x * fCos - vecRot0.x * fSin;
23 m_aMatrixRows[ 1 ].y = vecRot1.y * fCos - vecRot0.y * fSin;
24}
25
27{
28 TVector2 vecRot0 = m_aMatrixRows[ 0 ];
29 TVector2 vecRot1 = m_aMatrixRows[ 1 ];
30
31 m_aMatrixRows[ 0 ].x = a_rTransform.m_aMatrixRows[ 0 ].x * vecRot0.x + a_rTransform.m_aMatrixRows[ 0 ].y * vecRot1.x;
32 m_aMatrixRows[ 0 ].y = a_rTransform.m_aMatrixRows[ 0 ].x * vecRot0.y + a_rTransform.m_aMatrixRows[ 0 ].y * vecRot1.y;
33 m_aMatrixRows[ 1 ].x = a_rTransform.m_aMatrixRows[ 1 ].x * vecRot0.x + a_rTransform.m_aMatrixRows[ 1 ].y * vecRot1.x;
34 m_aMatrixRows[ 1 ].y = a_rTransform.m_aMatrixRows[ 1 ].x * vecRot0.y + a_rTransform.m_aMatrixRows[ 1 ].y * vecRot1.y;
35}
36
37void AGUI2Transform::Scale( TFLOAT a_fScaleX, TFLOAT a_fScaleY )
38{
39 AGUI2Transform transform;
40 transform.m_aMatrixRows[ 0 ] = { a_fScaleX, 0.0f };
41 transform.m_aMatrixRows[ 1 ] = { 0.0f, a_fScaleY };
42 transform.m_vecTranslation = { 0.0f, 0.0f };
43 PreMultiply( transform );
44}
45
46void AGUI2Transform::Transform( TVector2& a_rOutVec, const TVector2& a_rTransformVec ) const
47{
48 a_rOutVec.x = m_vecTranslation.x + m_aMatrixRows[ 0 ].x * a_rTransformVec.x + m_aMatrixRows[ 1 ].x * a_rTransformVec.y;
49 a_rOutVec.y = m_vecTranslation.y + m_aMatrixRows[ 0 ].y * a_rTransformVec.x + m_aMatrixRows[ 1 ].y * a_rTransformVec.y;
50}
51
53{
54 TFLOAT fMultiplier = 1.0f / ( m_aMatrixRows[ 0 ].x * m_aMatrixRows[ 1 ].y - m_aMatrixRows[ 0 ].y * m_aMatrixRows[ 1 ].x );
55
56 // NOTE: this code seems to be returning incorrect inverse matrices but
57 // it's the way it works in Barnyard. In de Blob, however, it was rewritten
58 // to do math the correct way.
59 a_rInverse.m_aMatrixRows[ 0 ].x = fMultiplier * m_aMatrixRows[ 0 ].x;
60 a_rInverse.m_aMatrixRows[ 0 ].y = fMultiplier * m_aMatrixRows[ 1 ].x;
61 a_rInverse.m_aMatrixRows[ 1 ].x = fMultiplier * m_aMatrixRows[ 0 ].y;
62 a_rInverse.m_aMatrixRows[ 1 ].y = fMultiplier * m_aMatrixRows[ 1 ].y;
63
64 // Someone probably forgot to remove some extra code?
65 a_rInverse.m_vecTranslation = TVector2( 0.0f, 0.0f );
66 a_rInverse.m_vecTranslation.x = a_rInverse.m_aMatrixRows[ 1 ].x * m_vecTranslation.y + a_rInverse.m_aMatrixRows[ 0 ].x * m_vecTranslation.x + a_rInverse.m_vecTranslation.x;
67 a_rInverse.m_vecTranslation.y = a_rInverse.m_aMatrixRows[ 0 ].y * m_vecTranslation.x + a_rInverse.m_aMatrixRows[ 1 ].y * m_vecTranslation.y + a_rInverse.m_vecTranslation.y;
68 a_rInverse.m_vecTranslation.Negate();
69}
70
71void AGUI2Transform::SetScale( TFLOAT a_fScaleX, TFLOAT a_fScaleY )
72{
73 TVector2 vecTranslation = m_vecTranslation;
75 Scale( a_fScaleX, a_fScaleY );
76 m_vecTranslation = vecTranslation;
77}
78
79void AGUI2Transform::SetFromScale( TFLOAT a_fScaleX, TFLOAT a_fScaleY )
80{
82 Scale( a_fScaleX, a_fScaleY );
83}
84
85void AGUI2Transform::Multiply( AGUI2Transform& a_rOutTransform, const AGUI2Transform& a_rA, const AGUI2Transform& a_rB )
86{
87 a_rOutTransform.m_aMatrixRows[ 0 ].x = a_rB.m_aMatrixRows[ 0 ].y * a_rA.m_aMatrixRows[ 1 ].x + a_rA.m_aMatrixRows[ 0 ].x * a_rB.m_aMatrixRows[ 0 ].x;
88 a_rOutTransform.m_aMatrixRows[ 0 ].y = a_rB.m_aMatrixRows[ 0 ].y * a_rA.m_aMatrixRows[ 1 ].y + a_rA.m_aMatrixRows[ 0 ].y * a_rB.m_aMatrixRows[ 0 ].x;
89 a_rOutTransform.m_aMatrixRows[ 1 ].x = a_rB.m_aMatrixRows[ 1 ].x * a_rA.m_aMatrixRows[ 0 ].x + a_rB.m_aMatrixRows[ 1 ].y * a_rA.m_aMatrixRows[ 1 ].x;
90 a_rOutTransform.m_aMatrixRows[ 1 ].y = a_rB.m_aMatrixRows[ 1 ].x * a_rA.m_aMatrixRows[ 0 ].y + a_rB.m_aMatrixRows[ 1 ].y * a_rA.m_aMatrixRows[ 1 ].y;
91 a_rOutTransform.m_vecTranslation.x = a_rB.m_vecTranslation.x * a_rA.m_aMatrixRows[ 0 ].x + a_rB.m_vecTranslation.y * a_rA.m_aMatrixRows[ 1 ].x + a_rA.m_vecTranslation.x;
92 a_rOutTransform.m_vecTranslation.y = a_rB.m_vecTranslation.x * a_rA.m_aMatrixRows[ 0 ].y + a_rB.m_vecTranslation.y * a_rA.m_aMatrixRows[ 1 ].y + a_rA.m_vecTranslation.y;
93}
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
float TFLOAT
Definition Typedefs.h:4
TFORCEINLINE void SinCos(TFLOAT fVal, TFLOAT &a_rSin, TFLOAT &a_rCos)
TFLOAT y
Definition TVector2.h:139
TFLOAT x
Definition TVector2.h:139
void PreMultiply(const AGUI2Transform &a_rTransform)
void Transform(Toshi::TVector2 &a_rOutVec, const Toshi::TVector2 &a_rTransformVec) const
void Rotate(TFLOAT a_fAngle)
Toshi::TVector2 m_vecTranslation
Toshi::TVector2 m_aMatrixRows[2]
void SetFromScale(TFLOAT a_fScaleX, TFLOAT a_fScaleY)
static void Multiply(AGUI2Transform &a_rOutTransform, const AGUI2Transform &a_rA, const AGUI2Transform &a_rB)
constexpr AGUI2Transform()
constexpr void SetIdentity()
void SetScale(TFLOAT a_fScaleX, TFLOAT a_fScaleY)
void Scale(TFLOAT a_fScaleX, TFLOAT a_fScaleY)
void GetInverse(AGUI2Transform &a_rInverse) const