Carna  Version 3.0.1
Public Types | Public Member Functions | Public Attributes | List of all members
Carna::base::Spatial Class Reference

Represents a spatial scene element. It's location is determined relatively to another spatial that is called its *parent*. This parent-child relationship induces the scene graph concept. More...

#include <Spatial.h>

+ Inheritance diagram for Carna::base::Spatial:

Public Types

typedef std::function< void(Spatial &) > MutableVisitor
 Declares an entity that visits mutable Spatial instances.
 
typedef std::function< void(const Spatial &) > ImmutableVisitor
 Declares an entity that visits mutable Spatial instances.
 

Public Member Functions

 Spatial (const std::string &tag="")
 Instantiates. More...
 
virtual ~Spatial ()
 Does nothing.
 
bool hasParent () const
 Tells whether this spatial has a parent node.
 
SpatialdetachFromParent ()
 Detaches this spatial from it's parent node in \(\mathcal O\left(\log n\right)\) where \(n\) is the number of parent's children. The caller takes possession of this spatial. More...
 
void updateParent (Node &parent)
 Fixes tree consistency by updating parent of this spatial. This method is for internal usage only.
 
Nodeparent ()
 References the parent node. More...
 
const Nodeparent () const
 
NodefindRoot ()
 References the root node this spatial belongs to.
 
const NodefindRoot () const
 References the root node this spatial belongs to.
 
virtual void updateWorldTransform ()
 Computes the transformation to world space for this spatial. More...
 
const math::Matrix4fworldTransform () const
 Tells the transformation to world space for this spatial that was last computed.
 
template<typename UserDataType >
void setUserData (const UserDataType &userData)
 Links an arbitrary object with this Spatial instance. More...
 
void removeUserData ()
 Removes any object that has been linked with this Spatial instance through setUserData previously. More...
 
bool hasUserData () const
 Tells whether an object has been linked with this Spatial instance through setUserData previously.
 
template<typename UserDataType >
const UserDataType & userData () const
 Retrieves the object previously linked with this Spatial instance. More...
 
void setMovable (bool movable)
 Sets whether this spatial may be displaced w.r.t. it's parent through user interaction. Usually this will be false when this spatial represents a component of it's parent, like the shaft of an arrow. More...
 
bool isMovable () const
 Tells whether this spatial may be displaced w.r.t. it's parent through user interaction. Usually this will be false when this spatial represents a component of it's parent, like the shaft of an arrow. More...
 
virtual void invalidate ()
 Notifies all listeners of its parent nodes that their subtrees have changed. This may include changes of the tree structure as well as updated materials and suchlike.
 
void setTag (const std::string &tag)
 Sets an arbitrary tag that may be used to identify this object.
 
const std::string & tag () const
 Tells the tag set previously.
 

Public Attributes

math::Matrix4f localTransform
 Defines the location, rotation and scale of this spatial in relation to it's parent. If this spatial has no parent, the value has no meaning. More...
 

Detailed Description

Represents a spatial scene element. It's location is determined relatively to another spatial that is called its *parent*. This parent-child relationship induces the scene graph concept.

Author
Leonid Kostrykin
Date
21.2.15 - 6.3.15

Definition at line 44 of file Spatial.h.

Constructor & Destructor Documentation

Carna::base::Spatial::Spatial ( const std::string &  tag = "")
explicit

Instantiates.

Parameters
tagis an arbitrary string that may be used to identify this node.

Member Function Documentation

Spatial* Carna::base::Spatial::detachFromParent ( )

Detaches this spatial from it's parent node in \(\mathcal O\left(\log n\right)\) where \(n\) is the number of parent's children. The caller takes possession of this spatial.

Precondition
hasParent() == true
Postcondition
hasParent() == false
Returns
Possessing pointer to this spatial if it has successfully been detached from the parent or nullptr if it has no parent.
bool Carna::base::Spatial::isMovable ( ) const

Tells whether this spatial may be displaced w.r.t. it's parent through user interaction. Usually this will be false when this spatial represents a component of it's parent, like the shaft of an arrow.

Each spatial is movable by default.

Node& Carna::base::Spatial::parent ( )

References the parent node.

Precondition
hasParent() == true
const Node& Carna::base::Spatial::parent ( ) const

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

void Carna::base::Spatial::removeUserData ( )

Removes any object that has been linked with this Spatial instance through setUserData previously.

Postcondition
hasUserData() == false

Does nothing if hasUserData is false.

void Carna::base::Spatial::setMovable ( bool  movable)

Sets whether this spatial may be displaced w.r.t. it's parent through user interaction. Usually this will be false when this spatial represents a component of it's parent, like the shaft of an arrow.

Each spatial is movable by default.

template<typename UserDataType >
void Carna::base::Spatial::setUserData ( const UserDataType &  userData)

Links an arbitrary object with this Spatial instance.

Postcondition
hasUserData() == true

Definition at line 223 of file Spatial.h.

virtual void Carna::base::Spatial::updateWorldTransform ( )
virtual

Computes the transformation to world space for this spatial.

The default implementation concatenates the parent's world transformation with the local transformation of this spatial.

Reimplemented in Carna::base::Node, and Carna::base::Camera.

template<typename UserDataType >
const UserDataType & Carna::base::Spatial::userData ( ) const

Retrieves the object previously linked with this Spatial instance.

Precondition
hasUserData()

Definition at line 231 of file Spatial.h.

Member Data Documentation

math::Matrix4f Carna::base::Spatial::localTransform

Defines the location, rotation and scale of this spatial in relation to it's parent. If this spatial has no parent, the value has no meaning.

The default value is math::identity4f.

Definition at line 132 of file Spatial.h.


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