|
Ray Tracer Common Project
Image rendering program based on the ray tracing technique.
|
Basic space entity. More...
#include <entity.hpp>
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 matrix & | globalMatrix () const |
| The global matrix of the entity. More... | |
| const matrix & | invertedGlobalMatrix () const |
| The invert of the global matrix of the entity. More... | |
| vector | globalPosition () const |
| Global position of the entity. More... | |
| const vector & | position () const |
| Entity location. | |
| const vector & | rotation () const |
| Entity rotation. | |
| void | setPosition (const vector &pos) |
| Set the entity position. More... | |
| void | setRotation (const vector &rot) |
| Set the entity rotation. More... | |
| Entity * | parent () const |
| The parent entity. More... | |
| void | setParent (Entity *) |
| Set the parent entity. More... | |
| Scene * | scene () 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... | |
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.
| rt::Entity::Entity | ( | Entity * | parent = 0 | ) |
Default entity constructor.
Make a new entity from its parent. The parent may be null.
Make a new entity from its position and parent.
The parent may be null.
| 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.
|
pure virtual |
Destructor.
All children are deleted when destructor is called.
| 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.
| 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.
| vector rt::Entity::globalPosition | ( | ) | const |
Global position of the entity.
Same as ‘globalMatrix().position()’.
| 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.
| bool rt::Entity::isDirty | ( | ) | const |
| Entity * rt::Entity::parent | ( | ) | const |
The parent entity.
If the entity has no parent, the null vector will be returned.
|
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.
| void rt::Entity::removeChild | ( | Entity * | node | ) |
Remove a child.
If the child exists, its parent will be set to null.
| void rt::Entity::setParent | ( | Entity * | parent | ) |
Set the parent entity.
The new parent may be null.
| 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.
| 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.
| 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.
| void rt::Entity::soil | ( | ) |
Make an entity dirty.
The global matrice will no longer be considered up to date will be computed again.
1.8.15