LibCarna Version 3.4.0
Loading...
Searching...
No Matches
Spatial.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2016 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 *
11 * Copyright (C) 2021 - 2025 Leonid Kostrykin
12 *
13 */
14
15#ifndef SPATIAL_H_6014714286
16#define SPATIAL_H_6014714286
17
18#include <LibCarna/LibCarna.hpp>
21#include <functional>
22
28namespace LibCarna
29{
30
31namespace base
32{
33
34
35
36// ----------------------------------------------------------------------------------
37// Spatial
38// ----------------------------------------------------------------------------------
39
47class LIBCARNA Spatial
48{
49
51
52 Node* myParent;
53 math::Matrix4f myWorldTransform;
54 const void* myUserData;
55 bool movable;
56 std::string myTag;
57
58public:
59
61
67 explicit Spatial( const std::string& tag = "" );
68
72 virtual ~Spatial();
73
77 typedef std::function< void( Spatial& ) > MutableVisitor;
78
82 typedef std::function< void( const Spatial& ) > ImmutableVisitor;
83
87 bool hasParent() const;
88
102
107 void updateParent( Node& parent );
108
114
117 const Node& parent() const;
118
123
127 const Node& findRoot() const;
128
136
143 virtual void updateWorldTransform();
144
150
157 template< typename UserDataType >
158 void setUserData( const UserDataType& userData );
159
170
175 bool hasUserData() const;
176
184 template< typename UserDataType >
185 const UserDataType& userData() const;
186
194 void setMovable( bool movable );
195
203 bool isMovable() const;
204
210 virtual void invalidate();
211
215 void setTag( const std::string& tag );
216
220 const std::string& tag() const;
221
222}; // Spatial
223
224
225template< typename UserDataType >
226void Spatial::setUserData( const UserDataType& userData )
227{
228 myUserData = &userData;
230}
231
232
233template< typename UserDataType >
235{
237 return *static_cast< const UserDataType* >( myUserData );
238}
239
240
241
242} // namespace LibCarna :: base
243
244} // namespace LibCarna
245
246#endif // SPATIAL_H_6014714286
#define LIBCARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
Contains forward-declarations.
Represents an association.
Defines the inner node of a scene graph. Implements a spatial scene element that is allowed to have c...
Definition Node.hpp:48
Represents a spatial scene element. It's location is determined relatively to another spatial that is...
Definition Spatial.hpp:48
Node & findRoot()
References the root node this spatial belongs to.
virtual ~Spatial()
Does nothing.
const UserDataType & userData() const
Retrieves the object previously linked with this Spatial instance.
Definition Spatial.hpp:234
void setMovable(bool movable)
Sets whether this spatial may be displaced w.r.t. it's parent through user interaction....
void setTag(const std::string &tag)
Sets an arbitrary tag that may be used to identify this object.
const Node & parent() const
virtual void updateWorldTransform()
Computes the transformation to world space for this spatial.
bool hasParent() const
Tells whether this spatial has a parent node.
void removeUserData()
Removes any object that has been linked with this Spatial instance through setUserData previously.
void setUserData(const UserDataType &userData)
Links an arbitrary object with this Spatial instance.
Definition Spatial.hpp:226
Node & parent()
References the parent node.
bool hasUserData() const
Tells whether an object has been linked with this Spatial instance through setUserData previously.
bool isMovable() const
Tells whether this spatial may be displaced w.r.t. it's parent through user interaction....
std::function< void(Spatial &) > MutableVisitor
Declares an entity that visits mutable Spatial instances.
Definition Spatial.hpp:77
Spatial(const std::string &tag="")
Instantiates.
Spatial * detachFromParent()
Detaches this spatial from it's parent node in where is the number of parent's children....
virtual void invalidate()
Notifies all listeners of its parent nodes that their subtrees have changed. This may include changes...
const math::Matrix4f & worldTransform() const
Tells the transformation to world space for this spatial that was last computed.
void updateParent(Node &parent)
Fixes tree consistency by updating parent of this spatial. This method is for internal usage only.
const std::string & tag() const
Tells the tag set previously.
const Node & findRoot() const
References the root node this spatial belongs to.
std::function< void(const Spatial &) > ImmutableVisitor
Declares an entity that visits mutable Spatial instances.
Definition Spatial.hpp:82
math::Matrix4f localTransform
Defines the location, rotation and scale of this spatial in relation to it's parent....
Definition Spatial.hpp:135
Defines LibCarna::base::math namespace and LIBCARNA_FOR_VECTOR3UI.
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > Matrix4f
Defines matrix.
Definition math.hpp:197
Defines LibCarna::base::noncopyable and NON_COPYABLE.
#define NON_COPYABLE
Marks the class that it is placed in as non-copyable.