Carna Version 3.3.3
Loading...
Searching...
No Matches
Spatial.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2015 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 */
11
12#ifndef SPATIAL_H_6014714286
13#define SPATIAL_H_6014714286
14
15#include <Carna/Carna.h>
16#include <Carna/base/math.h>
18#include <functional>
19
24namespace Carna
25{
26
27namespace base
28{
29
30
31
32// ----------------------------------------------------------------------------------
33// Spatial
34// ----------------------------------------------------------------------------------
35
44class CARNA_LIB Spatial
45{
46
48
49 Node* myParent;
50 math::Matrix4f myWorldTransform;
51 const void* myUserData;
52 bool movable;
53 std::string myTag;
54
55public:
56
58
64 explicit Spatial( const std::string& tag = "" );
65
69 virtual ~Spatial();
70
74 typedef std::function< void( Spatial& ) > MutableVisitor;
75
79 typedef std::function< void( const Spatial& ) > ImmutableVisitor;
80
84 bool hasParent() const;
85
99
104 void updateParent( Node& parent );
105
111
114 const Node& parent() const;
115
120
124 const Node& findRoot() const;
125
133
140 virtual void updateWorldTransform();
141
147
154 template< typename UserDataType >
155 void setUserData( const UserDataType& userData );
156
167
172 bool hasUserData() const;
173
181 template< typename UserDataType >
182 const UserDataType& userData() const;
183
191 void setMovable( bool movable );
192
200 bool isMovable() const;
201
207 virtual void invalidate();
208
212 void setTag( const std::string& tag );
213
217 const std::string& tag() const;
218
219}; // Spatial
220
221
222template< typename UserDataType >
223void Spatial::setUserData( const UserDataType& userData )
224{
225 myUserData = &userData;
227}
228
229
230template< typename UserDataType >
232{
234 return *static_cast< const UserDataType* >( myUserData );
235}
236
237
238
239} // namespace Carna :: base
240
241} // namespace Carna
242
243#endif // SPATIAL_H_6014714286
#define CARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
Represents an association.
Definition Association.h:45
Defines the inner node of a scene graph. Implements a spatial scene element that is allowed to have c...
Definition Node.h:45
Represents a spatial scene element. It's location is determined relatively to another spatial that is...
Definition Spatial.h:45
void updateParent(Node &parent)
Fixes tree consistency by updating parent of this spatial. This method is for internal usage only.
void setMovable(bool movable)
Sets whether this spatial may be displaced w.r.t. it's parent through user interaction....
virtual void invalidate()
Notifies all listeners of its parent nodes that their subtrees have changed. This may include changes...
void setUserData(const UserDataType &userData)
Links an arbitrary object with this Spatial instance.
Definition Spatial.h:223
bool hasParent() const
Tells whether this spatial has a parent node.
bool hasUserData() const
Tells whether an object has been linked with this Spatial instance through setUserData previously.
virtual ~Spatial()
Does nothing.
std::function< void(Spatial &) > MutableVisitor
Declares an entity that visits mutable Spatial instances.
Definition Spatial.h:74
const UserDataType & userData() const
Retrieves the object previously linked with this Spatial instance.
Definition Spatial.h:231
bool isMovable() const
Tells whether this spatial may be displaced w.r.t. it's parent through user interaction....
Node & parent()
References the parent node.
const Node & findRoot() const
References the root node this spatial belongs to.
void removeUserData()
Removes any object that has been linked with this Spatial instance through setUserData previously.
std::function< void(const Spatial &) > ImmutableVisitor
Declares an entity that visits mutable Spatial instances.
Definition Spatial.h:79
Spatial(const std::string &tag="")
Instantiates.
virtual void updateWorldTransform()
Computes the transformation to world space for this spatial.
Spatial * detachFromParent()
Detaches this spatial from it's parent node in where is the number of parent's children....
const std::string & tag() const
Tells the tag set previously.
const math::Matrix4f & worldTransform() const
Tells the transformation to world space for this spatial that was last computed.
Node & findRoot()
References the root node this spatial belongs to.
const Node & parent() const
math::Matrix4f localTransform
Defines the location, rotation and scale of this spatial in relation to it's parent....
Definition Spatial.h:132
void setTag(const std::string &tag)
Sets an arbitrary tag that may be used to identify this object.
Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > Matrix4f
Defines matrix.
Definition math.h:193
#define NON_COPYABLE
Features class it is placed in as non-copyable.