Hymn to Beauty
C++ 3D Engine
Entity Class Reference

Entity containing various components. More...

#include <Entity.hpp>

Public Member Functions

 Entity (World *world, const std::string &name)
 Create new entity. More...
 
 ~Entity ()
 Destructor. More...
 
EntityGetParent () const
 Get the entity's parent entity. More...
 
EntityAddChild (const std::string &name="")
 Add child entity. More...
 
bool RemoveChild (Entity *child)
 Remove child entity. More...
 
EntitySetParent (Entity *newParent)
 Set a new parent. More...
 
bool HasChild (const Entity *child, bool deep=true) const
 Check if entity is a child. More...
 
EntityInstantiateScene (const std::string &name)
 Instantiate a scene as a child to this entity. More...
 
EntityInstantiateScene (const std::string &name, const std::string &originScene)
 Instantiate a scene as a child to this entity. More...
 
void CheckIfSceneExists (const std::string &filename, bool &error, const std::string &originScene, Json::Value root)
 Check if scene already exists in any of json files. More...
 
const std::vector< Entity * > & GetChildren () const
 Get all of the entity's children. More...
 
EntityGetChild (const std::string &name) const
 Get child based on its name. More...
 
EntityGetChildFromIndex (int index) const
 Get child based on its name. More...
 
unsigned int GetNumChildren () const
 Get the number of children. More...
 
bool IsScene () const
 Get whether the entity is an instantiated scene. More...
 
template<typename T >
T * AddComponent ()
 Adds component with type T. More...
 
template<typename T >
T * GetComponent () const
 Gets component with type T. More...
 
template<typename T >
void KillComponent ()
 Kill component of type T. More...
 
void Kill ()
 Kill the entity, will be removed at the end of the frame. More...
 
bool IsKilled () const
 Get whether entity has been killed. More...
 
void Serialize (Json::Value &node, bool load)
 Save or load entity to/from JSON. More...
 
const glm::vec3 & GetPosition () const
 Get the local position. More...
 
void SetPosition (const glm::vec3 &position)
 Set the local position. More...
 
glm::vec3 GetWorldPosition () const
 Get the position in the world. More...
 
void SetWorldPosition (const glm::vec3 &worldPos)
 Set the position of the entity in world space. More...
 
void Move (const glm::vec3 &translation)
 Move in local space. More...
 
const glm::vec3 & GetScale () const
 Get the local scale. More...
 
void SetScale (const glm::vec3 &scale)
 Set the local scale. More...
 
const glm::quat & GetRotation () const
 Get the rotation of this entity. More...
 
void SetRotation (const glm::quat &localRot)
 Set the local rotation of the entity. More...
 
glm::quat GetWorldRotation () const
 Get rotation of the entity. More...
 
void SetWorldRotation (const glm::quat &worldRot)
 Set the rotation of the entity in world space. More...
 
glm::vec3 GetWorldDirection () const
 Get direction of the entity. More...
 
void RotateYaw (float angle)
 Rotates around the Y axis. More...
 
void RotatePitch (float angle)
 Rotates around the X axis. More...
 
void RotateRoll (float angle)
 Rotates around the Z axis. More...
 
void RotateAroundWorldAxis (float angle, const glm::vec3 &axis)
 Rotates around an axis given in world space. More...
 
const glm::mat4 & GetLocalMatrix () const
 Get the local model matrix. More...
 
const glm::mat4 & GetWorldModelMatrix () const
 Get the world model matrix. More...
 
void SetEnabled (bool enabled, bool recursive=false)
 Set whether the entity should be enabled. More...
 
bool IsEnabled () const
 Get whether the entity is enabled. More...
 
unsigned int GetUniqueIdentifier () const
 Get the entity's UID. More...
 
void SetUniqueIdentifier (unsigned int UID)
 Set the entity's UID. More...
 

Public Attributes

std::string name
 Name of the entity. More...
 
bool loadPaintModeClicked = false
 Variables used for enabling and disabling the paint brush tool. More...
 
bool brushActive = false
 
bool vertsLoaded = false
 
bool painting = false
 
bool sceneChosen = false
 

Detailed Description

Entity containing various components.

Constructor & Destructor Documentation

◆ Entity()

Entity::Entity ( World world,
const std::string &  name 
)

Create new entity.

Parameters
worldThe game world in which the entity is contained.
nameName of the entity.

◆ ~Entity()

Entity::~Entity ( )

Destructor.

Member Function Documentation

◆ AddChild()

Entity * Entity::AddChild ( const std::string &  name = "")

Add child entity.

Parameters
nameThe name of the child entity.
Returns
The new entity.

◆ AddComponent()

template<typename T >
T * Entity::AddComponent

Adds component with type T.

Returns
The created component.

◆ CheckIfSceneExists()

void Entity::CheckIfSceneExists ( const std::string &  filename,
bool &  error,
const std::string &  originScene,
Json::Value  root 
)

Check if scene already exists in any of json files.

Parameters
filenameThe name of the scene to check.
errorSet to true inside the function if it allready exists.
originSceneName of scene you want to check.
rootThe json value of root scene.

◆ GetChild()

Entity * Entity::GetChild ( const std::string &  name) const

Get child based on its name.

Parameters
nameThe name of the child to get.
Returns
The child or nullptr if none was found.

◆ GetChildFromIndex()

Entity * Entity::GetChildFromIndex ( int  index) const

Get child based on its name.

Parameters
indexThe index of the child to get.
Returns
The child or nullptr if none was found.

◆ GetChildren()

const std::vector< Entity * > & Entity::GetChildren ( ) const

Get all of the entity's children.

Returns
All the children.

◆ GetComponent()

template<typename T >
T * Entity::GetComponent

Gets component with type T.

Returns
The requested component (or nullptr).

◆ GetLocalMatrix()

const glm::mat4 & Entity::GetLocalMatrix ( ) const

Get the local model matrix.

Returns
The local model matrix.

◆ GetNumChildren()

unsigned int Entity::GetNumChildren ( ) const

Get the number of children.

Returns
Number of children the entity has.

◆ GetParent()

Entity * Entity::GetParent ( ) const

Get the entity's parent entity.

Returns
The parent entity, or nullptr if none.

◆ GetPosition()

const glm::vec3 & Entity::GetPosition ( ) const

Get the local position.

Returns
The entity's position.

◆ GetRotation()

const glm::quat & Entity::GetRotation ( ) const

Get the rotation of this entity.

Returns
The rotation in local space.

◆ GetScale()

const glm::vec3 & Entity::GetScale ( ) const

Get the local scale.

Returns
The entity's scale.

◆ GetUniqueIdentifier()

unsigned int Entity::GetUniqueIdentifier ( ) const

Get the entity's UID.

Returns
The entity's UID

◆ GetWorldDirection()

glm::vec3 Entity::GetWorldDirection ( ) const

Get direction of the entity.

Returns
The entity's direction.

◆ GetWorldModelMatrix()

const glm::mat4 & Entity::GetWorldModelMatrix ( ) const

Get the world model matrix.

Returns
The world model matrix.

◆ GetWorldPosition()

glm::vec3 Entity::GetWorldPosition ( ) const

Get the position in the world.

Returns
The position in the world (not relative to parent).

◆ GetWorldRotation()

glm::quat Entity::GetWorldRotation ( ) const

Get rotation of the entity.

Returns
The rotation in world space.

◆ HasChild()

bool Entity::HasChild ( const Entity child,
bool  deep = true 
) const

Check if entity is a child.

Parameters
childThe entity you want to check if it is a child.
deepTrue if we want to check if it's a grandchild, false if we do not.
Returns
True if it has a child, false if it does not.

◆ InstantiateScene() [1/2]

Entity * Entity::InstantiateScene ( const std::string &  name)

Instantiate a scene as a child to this entity.

Parameters
nameThe name of the scene to instantiate.
Returns
The created root entity of the scene.

◆ InstantiateScene() [2/2]

Entity * Entity::InstantiateScene ( const std::string &  name,
const std::string &  originScene 
)

Instantiate a scene as a child to this entity.

Parameters
nameThe name of the scene to instantiate.
originSceneThe name of the scene to instantiate within (to check for recursion).
Returns
The created root entity of the scene.

◆ IsEnabled()

bool Entity::IsEnabled ( ) const

Get whether the entity is enabled.

Returns
Whether the entity is enabled.

◆ IsKilled()

bool Entity::IsKilled ( ) const

Get whether entity has been killed.

Returns
Whether the entity has been killed.

◆ IsScene()

bool Entity::IsScene ( ) const

Get whether the entity is an instantiated scene.

Returns
Whether the entity is an instantiated scene.

◆ Kill()

void Entity::Kill ( )

Kill the entity, will be removed at the end of the frame.

◆ KillComponent()

template<typename T >
void Entity::KillComponent

Kill component of type T.

◆ Move()

void Entity::Move ( const glm::vec3 &  translation)

Move in local space.

Parameters
translationMovement in local space.

◆ RemoveChild()

bool Entity::RemoveChild ( Entity child)

Remove child entity.

Parameters
childThe entity you want to remove.
Returns
Did we manage to remove the child.

◆ RotateAroundWorldAxis()

void Entity::RotateAroundWorldAxis ( float  angle,
const glm::vec3 &  axis 
)

Rotates around an axis given in world space.

Parameters
angleThe angle in radians that we want to rotate.
axisWorld space axis to rotate around.

◆ RotatePitch()

void Entity::RotatePitch ( float  angle)

Rotates around the X axis.

Parameters
angleThe angle in radians that we want to rotate.

◆ RotateRoll()

void Entity::RotateRoll ( float  angle)

Rotates around the Z axis.

Parameters
angleThe angle in radians that we want to rotate.

◆ RotateYaw()

void Entity::RotateYaw ( float  angle)

Rotates around the Y axis.

Parameters
angleThe angle in radians that we want to rotate.

◆ Serialize()

void Entity::Serialize ( Json::Value &  node,
bool  load 
)

Save or load entity to/from JSON.

Parameters
nodeThe JSON node to save to or load from.
loadWhether to load (otherwise saves).

◆ SetEnabled()

void Entity::SetEnabled ( bool  enabled,
bool  recursive = false 
)

Set whether the entity should be enabled.

Parameters
enabledWhether the entity should be enabled.
recursiveWhether to set all children recursively.

◆ SetParent()

Entity * Entity::SetParent ( Entity newParent)

Set a new parent.

Parameters
newParentThe entity you want to be the new parent.
Returns
The old parent.

◆ SetPosition()

void Entity::SetPosition ( const glm::vec3 &  position)

Set the local position.

Parameters
positionThe new position.

◆ SetRotation()

void Entity::SetRotation ( const glm::quat &  localRot)

Set the local rotation of the entity.

Parameters
localRotThe local rotation you want the entity to have.

◆ SetScale()

void Entity::SetScale ( const glm::vec3 &  scale)

Set the local scale.

Parameters
scaleThe new scale.

◆ SetUniqueIdentifier()

void Entity::SetUniqueIdentifier ( unsigned int  UID)

Set the entity's UID.

Parameters
UIDthe entity's unique identifier to be set

◆ SetWorldPosition()

void Entity::SetWorldPosition ( const glm::vec3 &  worldPos)

Set the position of the entity in world space.

Parameters
worldPosThe world position you want the entity to have.

◆ SetWorldRotation()

void Entity::SetWorldRotation ( const glm::quat &  worldRot)

Set the rotation of the entity in world space.

Parameters
worldRotNew rotation.

Member Data Documentation

◆ brushActive

bool Entity::brushActive = false

◆ loadPaintModeClicked

bool Entity::loadPaintModeClicked = false

Variables used for enabling and disabling the paint brush tool.

◆ name

std::string Entity::name

Name of the entity.

◆ painting

bool Entity::painting = false

◆ sceneChosen

bool Entity::sceneChosen = false

◆ vertsLoaded

bool Entity::vertsLoaded = false

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