Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
mnd::GameObject Class Reference

Node in the scene graph: a named transform that owns components and children. More...

#include <GameObject.h>

Public Member Functions

virtual ~GameObject ()=default
 
virtual void LoadProperties (const nlohmann::json &json)
 
virtual void Init ()
 
virtual void Update (f32 deltaTime)
 Update this object and all its components and children recursively.
 
const strGetName () const
 Returns the object's display name.
 
void SetName (const str &name)
 Sets the display name (used by FindChildByName).
 
GameObjectGetParent ()
 Returns the parent node, or nullptr for root objects.
 
bool IsAlive () const
 Returns false after MarkForDestroy() is called.
 
void MarkForDestroy ()
 Flag this object for removal at end of frame.
 
void AddComponent (Component *component)
 Attach a component to this object (takes ownership).
 
template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<Component, T>>>
TGetComponent ()
 Find and return the first component of type T attached to this object.
 
bool SetParent (GameObject *parent)
 Re-parent this object in the scene hierarchy.
 
SceneGetScene ()
 Returns the Scene that owns this object.
 
void SetActive (bool active)
 Show/hide this object (and stop Update calls).
 
bool IsActive () const
 Returns false if the object is hidden.
 
void SetWorldPosition (const vec3 &pos)
 
quat GetWorldRotation ()
 
void SetWorldRotation (const quat &rot)
 
GameObjectFindChildByName (const std::string &name)
 Depth-first search for a child with the given name.
 
const std::vector< std::unique_ptr< GameObject > > & GetChildren () const
 Editor access: iterate immediate children (non-owning).
 
const std::vector< std::unique_ptr< Component > > & GetComponents () const
 Editor access: iterate attached components (non-owning).
 
Local Transform

Position, rotation, and scale are all relative to the parent object.

const vec3GetPosition () const
 
void SetPosition (const vec3 &pos)
 
void SetRotation (const quat &rot)
 
const quatGetRotation () const
 
const vec3GetScale () const
 
void SetScale (const vec3 &scale)
 
World-Space Queries
mat4 GetLocalTransform () const
 Compute the local transform matrix (TRS order).
 
mat4 GetWorldTransform () const
 Compute the world transform by walking up the parent chain.
 
vec3 GetWorldPosition () const
 Extract the world-space position from GetWorldTransform().
 

Static Public Member Functions

static GameObjectLoadGLTF (const std::string &path, Scene *scene)
 Load a GLTF / GLB file and build a matching GameObject hierarchy.
 

Protected Member Functions

 GameObject ()=default
 

Friends

class Scene
 

Detailed Description

Node in the scene graph: a named transform that owns components and children.

GameObjects are created and owned exclusively by Scene (via Scene::CreateObject). They are never constructed directly to ensure the scene always holds ownership.

Definition at line 90 of file GameObject.h.

Constructor & Destructor Documentation

◆ ~GameObject()

virtual mnd::GameObject::~GameObject ( )
virtualdefault

◆ GameObject()

mnd::GameObject::GameObject ( )
protecteddefault

Member Function Documentation

◆ AddComponent()

void mnd::GameObject::AddComponent ( Component component)

Attach a component to this object (takes ownership).

Parameters
componentHeap-allocated Component subclass. The GameObject owns it.

Definition at line 100 of file GameObject.cpp.

References mnd::Component::Init(), LOG_ERROR, LOG_INFO, and mnd::Component::m_owner.

◆ FindChildByName()

GameObject * mnd::GameObject::FindChildByName ( const std::string &  name)

Depth-first search for a child with the given name.

Parameters
nameExact name to search for (case-sensitive).
Returns
Pointer to the first matching descendant, or nullptr.

Definition at line 624 of file GameObject.cpp.

◆ GetChildren()

const std::vector< std::unique_ptr< GameObject > > & mnd::GameObject::GetChildren ( ) const
inline

Editor access: iterate immediate children (non-owning).

Definition at line 210 of file GameObject.h.

◆ GetComponent()

template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<Component, T>>>
T * mnd::GameObject::GetComponent ( )
inline

Find and return the first component of type T attached to this object.

Template Parameters
TA Component subclass decorated with the COMPONENT macro.
Returns
Raw pointer to the component, or nullptr if none is attached.

Definition at line 125 of file GameObject.h.

References mnd::T.

◆ GetComponents()

const std::vector< std::unique_ptr< Component > > & mnd::GameObject::GetComponents ( ) const
inline

Editor access: iterate attached components (non-owning).

Definition at line 213 of file GameObject.h.

◆ GetLocalTransform()

mat4 mnd::GameObject::GetLocalTransform ( ) const

Compute the local transform matrix (TRS order).

Returns
A 4×4 matrix combining local position, rotation, and scale.

Definition at line 149 of file GameObject.cpp.

Referenced by GetWorldTransform().

◆ GetName()

const str & mnd::GameObject::GetName ( ) const

Returns the object's display name.

Definition at line 574 of file GameObject.cpp.

Referenced by mnd::Scene::CreateObject(), mnd::Scene::SetParent(), and mnd::MeshComponent::Update().

◆ GetParent()

GameObject * mnd::GameObject::GetParent ( )

Returns the parent node, or nullptr for root objects.

Definition at line 598 of file GameObject.cpp.

Referenced by mnd::CameraComponent::GetViewMatrix(), and mnd::Scene::SetParent().

◆ GetPosition()

const vec3 & mnd::GameObject::GetPosition ( ) const

Definition at line 113 of file GameObject.cpp.

Referenced by mnd::CameraComponent::GetViewMatrix(), and mnd::InspectTransform().

◆ GetRotation()

const quat & mnd::GameObject::GetRotation ( ) const

◆ GetScale()

const vec3 & mnd::GameObject::GetScale ( ) const

Definition at line 133 of file GameObject.cpp.

Referenced by mnd::InspectTransform().

◆ GetScene()

Scene * mnd::GameObject::GetScene ( )

Returns the Scene that owns this object.

Definition at line 593 of file GameObject.cpp.

Referenced by mnd::ParseGLTFNode().

◆ GetWorldPosition()

vec3 mnd::GameObject::GetWorldPosition ( ) const

Extract the world-space position from GetWorldTransform().

Returns
The translation column of the world matrix.

Definition at line 143 of file GameObject.cpp.

References GetWorldTransform().

Referenced by mnd::PhysicsComponent::Init(), mnd::PlayerControllerComponent::Init(), mnd::AudioComponent::Update(), and mnd::AudioListenerComponent::Update().

◆ GetWorldRotation()

quat mnd::GameObject::GetWorldRotation ( )

Definition at line 207 of file GameObject.cpp.

References GetWorldRotation().

Referenced by GetWorldRotation(), mnd::PhysicsComponent::Init(), and SetWorldRotation().

◆ GetWorldTransform()

mat4 mnd::GameObject::GetWorldTransform ( ) const

Compute the world transform by walking up the parent chain.

Returns
Product of all ancestor local transforms × this local transform.

Definition at line 168 of file GameObject.cpp.

References GetLocalTransform(), and GetWorldTransform().

Referenced by mnd::CameraComponent::GetViewMatrix(), GetWorldPosition(), GetWorldTransform(), SetWorldPosition(), mnd::MeshComponent::Update(), and mnd::SkinnedMeshComponent::Update().

◆ Init()

virtual void mnd::GameObject::Init ( )
inlinevirtual

Definition at line 97 of file GameObject.h.

◆ IsActive()

bool mnd::GameObject::IsActive ( ) const

Returns false if the object is hidden.

Definition at line 619 of file GameObject.cpp.

◆ IsAlive()

bool mnd::GameObject::IsAlive ( ) const

Returns false after MarkForDestroy() is called.

Definition at line 603 of file GameObject.cpp.

◆ LoadGLTF()

GameObject * mnd::GameObject::LoadGLTF ( const std::string &  path,
Scene scene 
)
static

Load a GLTF / GLB file and build a matching GameObject hierarchy.

Each GLTF node becomes a child GameObject. Meshes get a MeshComponent, animations get an AnimationComponent attached to the root.

Parameters
pathFilesystem path to the .gltf or .glb file.
Returns
Root of the loaded hierarchy (heap-allocated, caller takes ownership).

Definition at line 426 of file GameObject.cpp.

References mnd::Scene::CreateObject(), mnd::FileSystem::GetAssetsFolder(), mnd::Engine::GetFileSystem(), mnd::Engine::GetInstance(), mnd::FileSystem::LoadAssetFileText(), LOG_ERROR, mnd::ParseGLTFNode(), mnd::ReadOutputQuat, mnd::ReadOutputVec3, mnd::ReadTimes, and mnd::TransformTrack::targetName.

◆ LoadProperties()

virtual void mnd::GameObject::LoadProperties ( const nlohmann::json &  json)
inlinevirtual

Definition at line 95 of file GameObject.h.

◆ MarkForDestroy()

void mnd::GameObject::MarkForDestroy ( )

Flag this object for removal at end of frame.

Definition at line 608 of file GameObject.cpp.

References LOG_INFO.

Referenced by mnd::HealthComponent::ApplyDamage().

◆ SetActive()

void mnd::GameObject::SetActive ( bool  active)

Show/hide this object (and stop Update calls).

Definition at line 614 of file GameObject.cpp.

◆ SetName()

void mnd::GameObject::SetName ( const str name)

Sets the display name (used by FindChildByName).

Definition at line 579 of file GameObject.cpp.

Referenced by mnd::Scene::CreateObject(), and mnd::Scene::CreateObject().

◆ SetParent()

bool mnd::GameObject::SetParent ( GameObject parent)

Re-parent this object in the scene hierarchy.

Parameters
parentNew parent node, or nullptr to make this a root object.
Returns
true on success.

Definition at line 584 of file GameObject.cpp.

References mnd::Scene::SetParent().

◆ SetPosition()

void mnd::GameObject::SetPosition ( const vec3 pos)

◆ SetRotation()

void mnd::GameObject::SetRotation ( const quat rot)

◆ SetScale()

void mnd::GameObject::SetScale ( const vec3 scale)

Definition at line 138 of file GameObject.cpp.

Referenced by mnd::InspectTransform().

◆ SetWorldPosition()

void mnd::GameObject::SetWorldPosition ( const vec3 pos)

Definition at line 179 of file GameObject.cpp.

References GetWorldTransform(), and SetPosition().

Referenced by mnd::PhysicsComponent::Update().

◆ SetWorldRotation()

void mnd::GameObject::SetWorldRotation ( const quat rot)

Definition at line 193 of file GameObject.cpp.

References GetWorldRotation(), and SetRotation().

Referenced by mnd::PhysicsComponent::Update().

◆ Update()

void mnd::GameObject::Update ( f32  deltaTime)
virtual

Update this object and all its components and children recursively.

Parameters
deltaTimeSeconds since the previous frame.

Definition at line 75 of file GameObject.cpp.

Friends And Related Symbol Documentation

◆ Scene

friend class Scene
friend

Definition at line 232 of file GameObject.h.


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