template<class Transformation>
Magnum::SceneGraph::Object class

Object.

Base of scene graph. Contains specific transformation implementation, takes care of parent/children relationship and contains features. See Using the scene graph for introduction.

Common usage is to typedef Object with desired transformation type to save unnecessary typing later, along with Scene and possibly other types, e.g.:

typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D> Scene3D;
typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D> Object3D;

Uses Corrade::Containers::LinkedList for efficient hierarchy management. Traversing through the list of child objects can be done using range-based for:

Object3D o;
for(Object3D& child: o.children()) {
    ;
}

Or, if you need more flexibility, like in the following code. It is also possible to go in reverse order using Corrade::Containers::LinkedList::last() and previousSibling().

for(Object3D* child = o.children().first(); child; child = child->nextSibling()) {
    
}

Explicit template specializations

The following specializations are explicitly compiled into the SceneGraph library. For other specializations (e.g. using Double type or special transformation class) you have to use the Object.hpp implementation file (and possibly others) to avoid linker errors. See also relevant sections in the AbstractObject and AbstractTransformation class documentation or Template headers and implementation files for more information.

Base classes

template<UnsignedInt dimensions, class T>
class AbstractObject<Transformation::Dimensions, Transformation::Type>
Base for objects.

Derived classes

template<class Transformation>
class Scene
Scene.

Public types

using MatrixType = MatrixTypeFor<Transformation::Dimensions, typename Transformation::Type>
Matrix type.

Constructors, destructors, conversion operators

Object(Object<Transformation>* parent = nullptr) explicit
Constructor.
Object(const Object<Transformation>&) deleted
Copying is not allowed.
Object(Object<Transformation>&&) deleted
Moving is not allowed.
~Object()
Destructor.

Public functions

auto operator=(const Object<Transformation>&) -> Object<Transformation>& deleted
Copying is not allowed.
auto operator=(Object<Transformation>&&) -> Object<Transformation>& deleted
Moving is not allowed.

Scene hierarchy

See Scene hierarchy for more information.

auto scene() -> Scene<Transformation>*
Scene.
auto scene() const -> const Scene<Transformation>*
auto parent() -> Object<Transformation>*
Parent object or nullptr, if this is the root object.
auto parent() const -> const Object<Transformation>*
auto move(Object<Transformation>& child, Object<Transformation>* before) -> Object<Transformation>& new in Git master
Move a child object before another.
auto previousSibling() -> Object<Transformation>*
Previous sibling object or nullptr, if this is the first object.
auto previousSibling() const -> const Object<Transformation>*
auto nextSibling() -> Object<Transformation>*
Next sibling object or nullptr, if this is the last object.
auto nextSibling() const -> const Object<Transformation>*
auto children() -> Containers::LinkedList<Object<Transformation>>&
Child objects.
auto children() const -> const Containers::LinkedList<Object<Transformation>>&
template<class T, class ... Args>
auto addChild(Args && ... args) -> T&
Add a child.
auto setParent(Object<Transformation>* parent) -> Object<Transformation>&
Set parent object.
auto setParentKeepTransformation(Object<Transformation>* parent) -> Object<Transformation>&
Set parent object and keep absolute transformation.

Object transformation

auto transformationMatrix() const -> MatrixType
Transformation matrix.
auto absoluteTransformationMatrix() const -> MatrixType
Transformation matrix relative to the root object.
auto absoluteTransformation() const -> Transformation::DataType
Transformation relative to the root object.
auto transformationMatrices(const std::vector<std::reference_wrapper<Object<Transformation>>>& objects, const MatrixType& finalTransformationMatrix = MatrixType()) const -> std::vector<MatrixType>
Transformation matrices of given set of objects relative to this object.
auto transformations(std::vector<std::reference_wrapper<Object<Transformation>>> objects, const typename Transformation::DataType& finalTransformation = typename Transformation::DataType()) const -> std::vector<typename Transformation::DataType>
Transformations of given group of objects relative to this object.

Transformation caching

See Transformation caching in features for more information.

auto isDirty() const -> bool
Whether absolute transformation is dirty.
void setDirty()
Set object absolute transformation as dirty.
void setClean()
Clean object absolute transformation.
static void setClean(std::vector<std::reference_wrapper<Object<Transformation>>> objects)
Clean absolute transformations of given set of objects.

Function documentation

template<class Transformation>
Magnum::SceneGraph::Object<Transformation>::Object(Object<Transformation>* parent = nullptr) explicit

Constructor.

Parameters
parent Parent object

template<class Transformation>
Magnum::SceneGraph::Object<Transformation>::~Object()

Destructor.

Destroys all own children and then removes itself from the parent list. Features are then deleted in the AbstractObject destructor.

template<class Transformation>
Scene<Transformation>* Magnum::SceneGraph::Object<Transformation>::scene()

Scene.

Returns Scene or nullptr, if the object is not part of any scene.

template<class Transformation>
const Scene<Transformation>* Magnum::SceneGraph::Object<Transformation>::scene() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Transformation>
const Object<Transformation>* Magnum::SceneGraph::Object<Transformation>::parent() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Transformation>
Object<Transformation>& Magnum::SceneGraph::Object<Transformation>::move(Object<Transformation>& child, Object<Transformation>* before) new in Git master

Move a child object before another.

Returns Reference to self (for method chaining)

Doesn't have any effect on draw order, only on the child order when iterating through children(). The child is expected to be a child of this object, before is either a child of this object or nullptr in which case the child is moved to the last position in the child list.

template<class Transformation>
const Object<Transformation>* Magnum::SceneGraph::Object<Transformation>::previousSibling() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Transformation>
const Object<Transformation>* Magnum::SceneGraph::Object<Transformation>::nextSibling() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Transformation>
Containers::LinkedList<Object<Transformation>>& Magnum::SceneGraph::Object<Transformation>::children()

Child objects.

template<class Transformation>
const Containers::LinkedList<Object<Transformation>>& Magnum::SceneGraph::Object<Transformation>::children() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Transformation> template<class T, class ... Args>
T& Magnum::SceneGraph::Object<Transformation>::addChild(Args && ... args)

Add a child.

Calling object.addChild<MyObject>(args...) is equivalent to new MyObject{args...} followed by an appropriate setParent() call.

template<class Transformation>
Object<Transformation>& Magnum::SceneGraph::Object<Transformation>::setParent(Object<Transformation>* parent)

Set parent object.

Returns Reference to self (for method chaining)

template<class Transformation>
Object<Transformation>& Magnum::SceneGraph::Object<Transformation>::setParentKeepTransformation(Object<Transformation>* parent)

Set parent object and keep absolute transformation.

Returns Reference to self (for method chaining)

While setParent() preserves relative transformation of the object, this function preserves absolute transformation (i.e., the object stays in place after reparenting).

template<class Transformation>
MatrixType Magnum::SceneGraph::Object<Transformation>::transformationMatrix() const

Transformation matrix.

See also transformation() function of various transformation classes.

template<class Transformation>
MatrixType Magnum::SceneGraph::Object<Transformation>::absoluteTransformationMatrix() const

Transformation matrix relative to the root object.

template<class Transformation>
Transformation::DataType Magnum::SceneGraph::Object<Transformation>::absoluteTransformation() const

Transformation relative to the root object.

template<class Transformation>
std::vector<MatrixType> Magnum::SceneGraph::Object<Transformation>::transformationMatrices(const std::vector<std::reference_wrapper<Object<Transformation>>>& objects, const MatrixType& finalTransformationMatrix = MatrixType()) const

Transformation matrices of given set of objects relative to this object.

All transformations are post-multiplied with finalTransformationMatrix, if specified (it gets applied on the left-most side, suitable for example for an inverse camera transformation or a projection matrix).

template<class Transformation>
std::vector<typename Transformation::DataType> Magnum::SceneGraph::Object<Transformation>::transformations(std::vector<std::reference_wrapper<Object<Transformation>>> objects, const typename Transformation::DataType& finalTransformation = typename Transformation::DataType()) const

Transformations of given group of objects relative to this object.

All transformations are post-multiplied with finalTransformation, if specified (it gets applied on the left-most side, suitable for example for an inverse camera transformation).

template<class Transformation>
bool Magnum::SceneGraph::Object<Transformation>::isDirty() const

Whether absolute transformation is dirty.

Returns true if transformation of the object or any parent has changed since last call to setClean(), false otherwise. All objects are dirty by default.

template<class Transformation>
void Magnum::SceneGraph::Object<Transformation>::setDirty()

Set object absolute transformation as dirty.

Calls AbstractFeature::markDirty() on all object features and recursively calls setDirty() on every child object which is not already dirty. If the object is already marked as dirty, the function does nothing.

template<class Transformation>
void Magnum::SceneGraph::Object<Transformation>::setClean()

Clean object absolute transformation.

Calls AbstractFeature::clean() and/or AbstractFeature::cleanInverted() on all object features which have caching enabled and recursively calls setClean() on every parent which is not already clean. If the object is already clean, the function does nothing.

See also setClean(std::vector<std::reference_wrapper<Object<Transformation>>>), which cleans given set of objects more efficiently than when calling setClean() on each object individually.

template<class Transformation>
static void Magnum::SceneGraph::Object<Transformation>::setClean(std::vector<std::reference_wrapper<Object<Transformation>>> objects)

Clean absolute transformations of given set of objects.

Only dirty objects in the list are cleaned.