OpenBarnyard
 
Loading...
Searching...
No Matches
TSceneObject.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TSceneObject.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
14{
15 m_SomeVector2.y = 1.0f;
16}
17
22
24{
25 m_eFlags |= 0b00001000;
26 m_pModelRef = a_pModelPtr;
27 m_pModelInstance = a_pModelPtr->GetModel()->CreateInstance();
28 TTODO( "Initialise some unknown values" );
29}
30
32{
33 if ( this )
34 delete this;
35}
36
37void TSceneObject::Update( TFLOAT a_fDeltaTime )
38{
39 m_pModelInstance->Update( a_fDeltaTime );
40}
41
42TBOOL TSceneObject::Render( TUINT a_uiClipFlags, const TVector3& a_rBounding )
43{
44 TIMPLEMENT();
46
47 m_pModelInstance->SetLOD( 0 );
48
49 auto uiOldClipFlags = pContext->SetClipFlags( a_uiClipFlags );
50
51 m_TransformObject.Push();
52 m_pModelInstance->Render();
53 m_TransformObject.Pop();
54
55 pContext->SetClipFlags( uiOldClipFlags );
56
57 return TTRUE;
58}
59
61{
63 auto pModel = m_pModelInstance->GetModel();
64 auto& lod = pModel->GetLOD( 0 );
65
66 TVector4 transformScale = m_TransformObject.GetScale();
67 TSphere bounding = lod.BoundingSphere;
68 bounding.AsVector4().Multiply( TVector4(
69 transformScale.x,
70 transformScale.y,
71 transformScale.z,
72 TMath::Max( TMath::Max( transformScale.x, transformScale.y ), transformScale.z )
73 ) );
74
75 TMatrix44 transformMatrix;
76 m_TransformObject.GetLocalMatrixImp( transformMatrix );
77
78 TMatrix44::TransformVector( bounding.GetOrigin(), transformMatrix, bounding.GetOrigin() );
79
80 if ( bounding.GetRadius() > 0.0f )
81 {
82 auto pWorldPlanes = pContext->GetWorldPlanes();
83
84 if ( !pContext->CullSphereToFrustumSimple( bounding, pWorldPlanes, 6 ) )
85 {
86 return TFALSE;
87 }
88 }
89
90 return Render( pContext->GetClipFlags(), bounding.GetOrigin() );
91}
92
94{
95 if ( m_pModelInstance )
96 {
97 m_pModelInstance->Delete();
98 m_pModelInstance = TNULL;
99 m_eFlags &= ~0b00001000;
100 }
101}
102
Rendering system interface for the Toshi engine.
#define TIMPLEMENT()
Definition Defines.h:136
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TTODO(DESC)
Definition Defines.h:134
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
unsigned int TUINT
Definition Typedefs.h:8
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
TFORCEINLINE const T & Max(const T &a, const T &b)
static constexpr void TransformVector(TVector3 &a_rOutVector, const TMatrix44 &a_rMatrix, const TVector3 &a_rVector)
Definition TMatrix44.h:280
TFORCEINLINE TVector4 & AsVector4()
Definition TSphere.h:111
constexpr TFORCEINLINE TFLOAT GetRadius() const
Definition TSphere.h:106
constexpr TFORCEINLINE TVector3 & GetOrigin()
Definition TSphere.h:96
constexpr void Multiply(const TVector4 &vec)
Definition TVector4.h:170
TFLOAT x
Definition TVector4.h:367
TFLOAT y
Definition TVector4.h:367
TFLOAT z
Definition TVector4.h:367
TModelInstance * CreateInstance()
Definition TModel.cpp:196
TModel * GetModel() const
TUINT SetClipFlags(TUINT a_uiClipFlags)
TRenderContext * GetCurrentContext() const
void DestroyModelInstance()
TBOOL Render(TUINT a_uiClipFlags, const TVector3 &a_rBounding)
void Create(TManagedModel *a_pModelPtr)
void Update(TFLOAT a_fDeltaTime)
TBOOL RenderIfVisible()
static TFORCEINLINE TRenderInterface * GetSingleton()
Definition TSingleton.h:49