Ray Tracer Common Project
Image rendering program based on the ray tracing technique.
Public Member Functions | List of all members
rt::Entity Class Referenceabstract

Basic space entity. More...

#include <entity.hpp>

Inheritance diagram for rt::Entity:
rt::Camera rt::Geometry rt::Light rt::Object rt::Mesh rt::Plan rt::Sphere rt::OmniLight

Public Member Functions

 Entity (Entity *parent=0)
 Default entity constructor. More...
 
 Entity (const vector &pos, Entity *parent=0)
 Make a new entity from its position and parent. More...
 
 Entity (double x, double y, double z, Entity *parent=0)
 Make a new entity from its position coordinates and parent. More...
 
virtual ~Entity ()=0
 Destructor. More...
 
void soil ()
 Make an entity dirty. More...
 
bool isDirty () const
 
virtual void update ()
 Update the global matrix of the entity and its children.
 
const matrixglobalMatrix () const
 The global matrix of the entity. More...
 
const matrixinvertedGlobalMatrix () const
 The invert of the global matrix of the entity. More...
 
vector globalPosition () const
 Global position of the entity. More...
 
const vectorposition () const
 Entity location.
 
const vectorrotation () const
 Entity rotation.
 
void setPosition (const vector &pos)
 Set the entity position. More...
 
void setRotation (const vector &rot)
 Set the entity rotation. More...
 
Entityparent () const
 The parent entity. More...
 
void setParent (Entity *)
 Set the parent entity. More...
 
Scenescene () const
 The scene of the entity.
 
void setScene (Scene *)
 Set the scene of the entity. More...
 
const std::unordered_set< Entity * > & children () const
 Entity children.
 
void addChild (Entity *)
 Add a child. More...
 
void removeChild (Entity *)
 Remove a child. More...
 
template<class T >
void queryAll (std::list< const T *> &list) const
 Get the list of a specific type of entity. More...
 

Detailed Description

Basic space entity.

An entity is a parent/children-relationship based, and located object in scene space.

An entity is described by its position and rotation in its parent referential. If it has no parent, theses attributes are described in global space.

You can add an entity to a scene by passing it to Scene::append(Entity*) method (in this case it will be a root element of the scene), or by setting it as child of an other entity already in the scene.

Even if the entity is described by local attributes, you can find the global position of an entity with the Entity::globalPosition() method. You can also get the transformation matrices used to map a vector in global or local space with Entity::globalMatrix() and Entity::invertedGlobalMatrix() methods.

These two matrices are computed as late as possible (never if it can be avoid) to prevent performences loses. An entity is said to be dirty if its global matrix is not up to date.

When an entity is deleted, all its children are deleted too.

Constructor & Destructor Documentation

◆ Entity() [1/3]

rt::Entity::Entity ( Entity parent = 0)

Default entity constructor.

Make a new entity from its parent. The parent may be null.

◆ Entity() [2/3]

rt::Entity::Entity ( const vector pos,
Entity parent = 0 
)

Make a new entity from its position and parent.

The parent may be null.

◆ Entity() [3/3]

rt::Entity::Entity ( double  x,
double  y,
double  z,
Entity parent = 0 
)

Make a new entity from its position coordinates and parent.

The parent may be null.

◆ ~Entity()

rt::Entity::~Entity ( )
pure virtual

Destructor.

All children are deleted when destructor is called.

Member Function Documentation

◆ addChild()

void rt::Entity::addChild ( Entity node)

Add a child.

If the new child already has a parent, it will be disconnected to its parent first.

◆ globalMatrix()

const matrix & rt::Entity::globalMatrix ( ) const

The global matrix of the entity.

This matrix can be used to map a local vector into global space:

 Entity e = ...;
 e->setPosition(vector(10.0, 5.0, 3.0));
 vector v(0.0, 1.0, 0.0); // a vector local to e

 e->globalMatrix()*v; // -> vector(10.0, 6.0, 3.0);

The global matrix is computed only if it is necessary.

◆ globalPosition()

vector rt::Entity::globalPosition ( ) const

Global position of the entity.

Same as ‘globalMatrix().position()’.

◆ invertedGlobalMatrix()

const matrix & rt::Entity::invertedGlobalMatrix ( ) const

The invert of the global matrix of the entity.

This matrix can be used to map a global vector into local space:

 Entity e = ...;
 e->setPosition(vector(10.0, 5.0, 3.0));
 vector v(10.0, 6.0, 3.0); // a global vector

 e->invertedGlobalMatrix()*v; // -> vector(0.0, 1.0, 0.0);

The inverted matrix is computed together with global matrix, that mean that this method is not the same as globalMatrix().inverted() and is costless.

◆ isDirty()

bool rt::Entity::isDirty ( ) const
Returns
if the global matrix is up to date.

◆ parent()

Entity * rt::Entity::parent ( ) const

The parent entity.

If the entity has no parent, the null vector will be returned.

◆ queryAll()

template<class T >
void rt::Entity::queryAll ( std::list< const T *> &  list) const
inline

Get the list of a specific type of entity.

This method search into the entity tree to find all entities of a specific type. For exemple, it can be used to get all the lights of an entity tree:

 Entity *e = ...;

 for(int i = 0; i < 100; ++i){
     e->append(new Light);
     e->append(new Object);
 }

 std::list<Light *> list;
 e->queryAll<Light>(list);
 // the list contains all the lights of the entity tree e.

◆ removeChild()

void rt::Entity::removeChild ( Entity node)

Remove a child.

If the child exists, its parent will be set to null.

◆ setParent()

void rt::Entity::setParent ( Entity parent)

Set the parent entity.

The new parent may be null.

◆ setPosition()

void rt::Entity::setPosition ( const vector pos)

Set the entity position.

When used, the entity is marked as dirty, and the the global matrix will be updated if needed.

◆ setRotation()

void rt::Entity::setRotation ( const vector rot)

Set the entity rotation.

When used, the entity is marked as dirty, and the the global matrix will be updated if needed.

◆ setScene()

void rt::Entity::setScene ( Scene scene)

Set the scene of the entity.

If the new scene is diffent of the parent entity scene, then set parent is set to null.

◆ soil()

void rt::Entity::soil ( )

Make an entity dirty.

The global matrice will no longer be considered up to date will be computed again.


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