OgreNode.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef _Node_H__
29 #define _Node_H__
30 
31 #include "OgrePrerequisites.h"
32 
33 #include "OgreCommon.h"
34 #include "OgreMatrix3.h"
35 #include "OgreMatrix4.h"
36 #include "OgreQuaternion.h"
37 #include "OgreString.h"
38 #include "OgreRenderable.h"
39 #include "OgreIteratorWrappers.h"
40 #include "OgreMesh.h"
41 #include "OgreUserObjectBindings.h"
42 #include "OgreHeaderPrefix.h"
43 
44 namespace Ogre {
45 
46  class NameGenerator;
47 
64  class _OgreExport Node : public NodeAlloc
65  {
66  public:
70  {
76  TS_WORLD
77  };
78  typedef HashMap<String, Node*> ChildNodeMap;
81 
85  {
86  public:
87  Listener() {}
88  virtual ~Listener() {}
96  virtual void nodeUpdated(const Node*) {}
98  virtual void nodeDestroyed(const Node*) {}
100  virtual void nodeAttached(const Node*) {}
102  virtual void nodeDetached(const Node*) {}
103  };
104 
106  class DebugRenderable : public Renderable, public NodeAlloc
107  {
108  protected:
113  public:
116  const MaterialPtr& getMaterial(void) const;
118  void getWorldTransforms(Matrix4* xform) const;
119  Real getSquaredViewDepth(const Camera* cam) const;
120  const LightList& getLights(void) const;
121  void setScaling(Real s) { mScaling = s; }
122 
123  };
124 
125  protected:
130 
135  mutable bool mNeedParentUpdate;
137  mutable bool mNeedChildUpdate;
139  mutable bool mParentNotified ;
141  mutable bool mQueuedForUpdate;
142 
145 
148 
151 
154 
157 
160 
163 
165  virtual void setParent(Node* parent);
166 
175 
184 
193 
200  virtual void _updateFromParent(void) const;
201 
208  virtual void updateFromParentImpl(void) const;
209 
210 
212  virtual Node* createChildImpl(void) = 0;
213 
215  virtual Node* createChildImpl(const String& name) = 0;
216 
223 
227 
230 
233 
235 
238 
239  public:
244  Node();
249  Node(const String& name);
250 
251  virtual ~Node();
252 
254  const String& getName(void) const;
255 
258  virtual Node* getParent(void) const;
259 
262  virtual const Quaternion & getOrientation() const;
263 
277  virtual void setOrientation( const Quaternion& q );
278 
292  virtual void setOrientation( Real w, Real x, Real y, Real z);
293 
307  virtual void resetOrientation(void);
308 
311  virtual void setPosition(const Vector3& pos);
312 
315  virtual void setPosition(Real x, Real y, Real z);
316 
319  virtual const Vector3 & getPosition(void) const;
320 
333  virtual void setScale(const Vector3& scale);
334 
347  virtual void setScale(Real x, Real y, Real z);
348 
351  virtual const Vector3 & getScale(void) const;
352 
366  virtual void setInheritOrientation(bool inherit);
367 
381  virtual bool getInheritOrientation(void) const;
382 
395  virtual void setInheritScale(bool inherit);
396 
401  virtual bool getInheritScale(void) const;
402 
412  virtual void scale(const Vector3& scale);
413 
423  virtual void scale(Real x, Real y, Real z);
424 
434  virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT);
448  virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
468  virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT);
492  virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
493 
496  virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
497 
500  virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
501 
504  virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
505 
508  virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
509 
512  virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL);
513 
516  virtual Matrix3 getLocalAxes(void) const;
517 
524  virtual Node* createChild(
525  const Vector3& translate = Vector3::ZERO,
526  const Quaternion& rotate = Quaternion::IDENTITY );
527 
537  virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY);
538 
543  virtual void addChild(Node* child);
544 
547  virtual unsigned short numChildren(void) const;
548 
553  virtual Node* getChild(unsigned short index) const;
554 
557  virtual Node* getChild(const String& name) const;
558 
570 
582 
590  virtual Node* removeChild(unsigned short index);
598  virtual Node* removeChild(Node* child);
599 
605  virtual Node* removeChild(const String& name);
609  virtual void removeAllChildren(void);
610 
615  virtual void _setDerivedPosition(const Vector3& pos);
616 
622  virtual void _setDerivedOrientation(const Quaternion& q);
623 
626  virtual const Quaternion & _getDerivedOrientation(void) const;
627 
630  virtual const Vector3 & _getDerivedPosition(void) const;
631 
634  virtual const Vector3 & _getDerivedScale(void) const;
635 
645  virtual const Matrix4& _getFullTransform(void) const;
646 
659  virtual void _update(bool updateChildren, bool parentHasChanged);
660 
666  virtual void setListener(Listener* listener) { mListener = listener; }
667 
670  virtual Listener* getListener(void) const { return mListener; }
671 
672 
683  virtual void setInitialState(void);
684 
686  virtual void resetToInitialState(void);
687 
692  virtual const Vector3& getInitialPosition(void) const;
693 
695  virtual Vector3 convertWorldToLocalPosition( const Vector3 &worldPos );
696 
699  virtual Vector3 convertLocalToWorldPosition( const Vector3 &localPos );
700 
702  virtual Quaternion convertWorldToLocalOrientation( const Quaternion &worldOrientation );
703 
706  virtual Quaternion convertLocalToWorldOrientation( const Quaternion &localOrientation );
707 
709  virtual const Quaternion& getInitialOrientation(void) const;
710 
712  virtual const Vector3& getInitialScale(void) const;
713 
715  virtual Real getSquaredViewDepth(const Camera* cam) const;
716 
724  virtual void needUpdate(bool forceParentUpdate = false);
729  virtual void requestUpdate(Node* child, bool forceParentUpdate = false);
731  virtual void cancelUpdate(Node* child);
732 
735 
743  static void queueNeedUpdate(Node* n);
745  static void processQueuedUpdates(void);
746 
747 
755  OGRE_DEPRECATED virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
756 
760  OGRE_DEPRECATED virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
761 
766  UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
767 
772  const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
773 
774  };
778 } // namespace Ogre
779 
780 #include "OgreHeaderSuffix.h"
781 
782 #endif // _Node_H__
#define _OgreExport
Definition: OgrePlatform.h:257
#define OGRE_DEPRECATED
Definition: OgrePlatform.h:189
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Variant type that can hold Any other type.
Definition: OgreAny.h:57
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:87
Concrete IteratorWrapper for const access to the underlying key-value container.
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
A 3x3 matrix which can represent rotations around axes.
Definition: OgreMatrix3.h:69
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
Utility class to generate a sequentially numbered series of names.
Inner class for displaying debug renderable for Node.
Definition: OgreNode.h:107
const MaterialPtr & getMaterial(void) const
Retrieves a weak reference to the material this renderable object uses.
Real getSquaredViewDepth(const Camera *cam) const
Returns the camera-relative squared depth of this renderable.
const LightList & getLights(void) const
Gets a list of lights, ordered relative to how close they are to this renderable.
void getWorldTransforms(Matrix4 *xform) const
Gets the world transform matrix / matrices for this renderable object.
void getRenderOperation(RenderOperation &op)
Gets the render operation required to send this object to the frame buffer.
Listener which gets called back on Node events.
Definition: OgreNode.h:85
virtual void nodeDestroyed(const Node *)
Node is being destroyed.
Definition: OgreNode.h:98
virtual ~Listener()
Definition: OgreNode.h:88
virtual void nodeDetached(const Node *)
Node has been detached from a parent.
Definition: OgreNode.h:102
virtual void nodeUpdated(const Node *)
Called when a node gets updated.
Definition: OgreNode.h:96
virtual void nodeAttached(const Node *)
Node has been attached to a parent.
Definition: OgreNode.h:100
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:65
virtual void setPosition(const Vector3 &pos)
Sets the position of the node relative to it's parent.
virtual void resetOrientation(void)
Resets the nodes orientation (local axes as world axes, no rotation).
virtual const Vector3 & _getDerivedScale(void) const
Gets the scaling factor of the node as derived from all parents.
virtual void updateFromParentImpl(void) const
Class-specific implementation of _updateFromParent.
virtual Vector3 convertWorldToLocalPosition(const Vector3 &worldPos)
Gets the local position, relative to this node, of the given world-space position.
virtual void resetToInitialState(void)
Resets the position / orientation / scale of this node to it's initial state, see setInitialState for...
virtual Node * createChildImpl(void)=0
Internal method for creating a new child node - must be overridden per subclass.
virtual Node * removeChild(Node *child)
Drops the specified child from this node.
UserObjectBindings mUserObjectBindings
User objects binding.
Definition: OgreNode.h:237
Node * mParent
Pointer to parent node.
Definition: OgreNode.h:127
const String & getName(void) const
Returns the name of the node.
Quaternion mOrientation
Stores the orientation of the node relative to it's parent.
Definition: OgreNode.h:150
virtual bool getInheritOrientation(void) const
Returns true if this node is affected by orientation applied to the parent node.
Vector3 mDerivedScale
Cached combined scale.
Definition: OgreNode.h:192
virtual OGRE_DEPRECATED void setUserAny(const Any &anything)
Definition: OgreNode.h:755
virtual Node * getParent(void) const
Gets this node's parent (NULL if this is the root).
virtual void setPosition(Real x, Real y, Real z)
Sets the position of the node relative to it's parent.
virtual Real getSquaredViewDepth(const Camera *cam) const
Helper function, get the squared view depth.
Node(const String &name)
Constructor, should only be called by parent, not directly.
Vector3 mInitialScale
The scale to use as a base for keyframe animation.
Definition: OgreNode.h:222
virtual void setOrientation(Real w, Real x, Real y, Real z)
Sets the orientation of this node via quaternion parameters.
static void queueNeedUpdate(Node *n)
Queue a 'needUpdate' call to a node safely.
virtual OGRE_DEPRECATED const Any & getUserAny(void) const
Definition: OgreNode.h:760
virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo=TS_PARENT)
Moves the node along the Cartesian axes.
virtual void translate(const Matrix3 &axes, Real x, Real y, Real z, TransformSpace relativeTo=TS_PARENT)
Moves the node along arbitrary axes.
Listener * mListener
Node listener - only one allowed (no list) for size & performance reasons.
Definition: OgreNode.h:229
bool mNeedChildUpdate
Flag indicating that all children need to be updated.
Definition: OgreNode.h:137
virtual unsigned short numChildren(void) const
Reports the number of child nodes under this one.
virtual ~Node()
ChildUpdateSet mChildrenToUpdate
List of children which need updating, used if self is not out of date but children are.
Definition: OgreNode.h:133
virtual Node * createChild(const String &name, const Vector3 &translate=Vector3::ZERO, const Quaternion &rotate=Quaternion::IDENTITY)
Creates a new named Node as a child of this node.
virtual Vector3 convertLocalToWorldPosition(const Vector3 &localPos)
Gets the world position of a point in the node local space useful for simple transforms that don't re...
virtual void requestUpdate(Node *child, bool forceParentUpdate=false)
Called by children to notify their parent that they need an update.
virtual Matrix3 getLocalAxes(void) const
Gets a matrix whose columns are the local axes based on the nodes orientation relative to it's parent...
virtual void _update(bool updateChildren, bool parentHasChanged)
Internal method to update the Node.
virtual void setScale(Real x, Real y, Real z)
Sets the scaling factor applied to this node.
bool mQueuedForUpdate
Flag indicating that the node has been queued for update.
Definition: OgreNode.h:141
virtual void setInheritScale(bool inherit)
Tells the node whether it should inherit scaling factors from it's parent node.
String mName
Friendly name of this node, can be automatically generated if you don't care.
Definition: OgreNode.h:144
virtual void translate(const Vector3 &d, TransformSpace relativeTo=TS_PARENT)
Moves the node along the Cartesian axes.
ConstMapIterator< ChildNodeMap > ConstChildNodeIterator
Definition: OgreNode.h:80
virtual void setParent(Node *parent)
Only available internally - notification of parent.
vector< Node * >::type QueuedUpdates
Definition: OgreNode.h:231
virtual void scale(Real x, Real y, Real z)
Scales the node, combining it's current scale with the passed in scaling factor.
virtual void removeAllChildren(void)
Removes all child Nodes attached to this node.
virtual Node * removeChild(const String &name)
Drops the named child from this node.
Quaternion mDerivedOrientation
Cached combined orientation.
Definition: OgreNode.h:174
Vector3 mDerivedPosition
Cached combined position.
Definition: OgreNode.h:183
virtual void setInitialState(void)
Sets the current transform of this node to be the 'initial state' ie that position / orientation / sc...
virtual void setInheritOrientation(bool inherit)
Tells the node whether it should inherit orientation from it's parent node.
virtual const Quaternion & getInitialOrientation(void) const
Gets the initial orientation of this node, see setInitialState for more info.
virtual Listener * getListener(void) const
Gets the current listener for this Node.
Definition: OgreNode.h:670
Vector3 mScale
Stores the scaling factor applied to this node.
Definition: OgreNode.h:156
virtual void needUpdate(bool forceParentUpdate=false)
To be called in the event of transform changes to this node that require it's recalculation.
Quaternion mInitialOrientation
The orientation to use as a base for keyframe animation.
Definition: OgreNode.h:220
Matrix4 mCachedTransform
Cached derived transform as a 4x4 matrix.
Definition: OgreNode.h:225
MapIterator< ChildNodeMap > ChildNodeIterator
Definition: OgreNode.h:79
virtual void rotate(const Vector3 &axis, const Radian &angle, TransformSpace relativeTo=TS_LOCAL)
Rotate the node around an arbitrary axis.
virtual Node * createChild(const Vector3 &translate=Vector3::ZERO, const Quaternion &rotate=Quaternion::IDENTITY)
Creates an unnamed new Node as a child of this node.
virtual Node * removeChild(unsigned short index)
Drops the specified child from this node.
virtual const Vector3 & _getDerivedPosition(void) const
Gets the position of the node as derived from all parents.
Node()
Constructor, should only be called by parent, not directly.
virtual const Quaternion & getOrientation() const
Returns a quaternion representing the nodes orientation.
virtual Node * getChild(const String &name) const
Gets a pointer to a named child node.
Vector3 mPosition
Stores the position/translation of the node relative to its parent.
Definition: OgreNode.h:153
virtual Quaternion convertLocalToWorldOrientation(const Quaternion &localOrientation)
Gets the world orientation of an orientation in the node local space useful for simple transforms tha...
const UserObjectBindings & getUserObjectBindings() const
Return an instance of user objects binding associated with this class.
Definition: OgreNode.h:772
Vector3 mInitialPosition
The position to use as a base for keyframe animation.
Definition: OgreNode.h:218
virtual const Vector3 & getPosition(void) const
Gets the position of the node relative to it's parent.
virtual bool getInheritScale(void) const
Returns true if this node is affected by scaling factors applied to the parent node.
virtual DebugRenderable * getDebugRenderable(Real scaling)
Get a debug renderable for rendering the Node.
virtual const Vector3 & getInitialPosition(void) const
Gets the initial position of this node, see setInitialState for more info.
virtual void setOrientation(const Quaternion &q)
Sets the orientation of this node via a quaternion.
virtual void _updateFromParent(void) const
Triggers the node to update it's combined transforms.
static QueuedUpdates msQueuedUpdates
Definition: OgreNode.h:232
bool mInheritScale
Stores whether this node inherits scale from it's parent.
Definition: OgreNode.h:162
bool mParentNotified
Flag indicating that parent has been notified about update request.
Definition: OgreNode.h:139
static NameGenerator msNameGenerator
Incremented count for next name extension.
Definition: OgreNode.h:147
virtual const Quaternion & _getDerivedOrientation(void) const
Gets the orientation of the node as derived from all parents.
virtual const Matrix4 & _getFullTransform(void) const
Gets the full transformation matrix for this node.
virtual void _setDerivedPosition(const Vector3 &pos)
Sets the final world position of the node directly.
bool mCachedTransformOutOfDate
Definition: OgreNode.h:226
virtual Node * createChildImpl(const String &name)=0
Internal method for creating a new child node - must be overridden per subclass.
virtual void _setDerivedOrientation(const Quaternion &q)
Sets the final world orientation of the node directly.
TransformSpace
Enumeration denoting the spaces which a transform can be relative to.
Definition: OgreNode.h:70
@ TS_PARENT
Transform is relative to the space of the parent node.
Definition: OgreNode.h:74
@ TS_LOCAL
Transform is relative to the local space.
Definition: OgreNode.h:72
virtual void translate(const Matrix3 &axes, const Vector3 &move, TransformSpace relativeTo=TS_PARENT)
Moves the node along arbitrary axes.
DebugRenderable * mDebug
Definition: OgreNode.h:234
virtual ConstChildNodeIterator getChildIterator(void) const
Retrieves an iterator for efficiently looping through all children of this node.
virtual void pitch(const Radian &angle, TransformSpace relativeTo=TS_LOCAL)
Rotate the node around the X-axis.
virtual void setListener(Listener *listener)
Sets a listener for this Node.
Definition: OgreNode.h:666
virtual Node * getChild(unsigned short index) const
Gets a pointer to a child node.
virtual void addChild(Node *child)
Adds a (precreated) child scene node to this node.
virtual void setScale(const Vector3 &scale)
Sets the scaling factor applied to this node.
ChildNodeMap mChildren
Collection of pointers to direct children; hashmap for efficiency.
Definition: OgreNode.h:129
virtual const Vector3 & getScale(void) const
Gets the scaling factor of this node.
virtual void scale(const Vector3 &scale)
Scales the node, combining it's current scale with the passed in scaling factor.
virtual void cancelUpdate(Node *child)
Called by children to notify their parent that they no longer need an update.
virtual ChildNodeIterator getChildIterator(void)
Retrieves an iterator for efficiently looping through all children of this node.
bool mInheritOrientation
Stores whether this node inherits orientation from it's parent.
Definition: OgreNode.h:159
HashMap< String, Node * > ChildNodeMap
Definition: OgreNode.h:78
virtual Quaternion convertWorldToLocalOrientation(const Quaternion &worldOrientation)
Gets the local orientation, relative to this node, of the given world-space orientation.
bool mNeedParentUpdate
Flag to indicate own transform from parent is out of date.
Definition: OgreNode.h:135
virtual void roll(const Radian &angle, TransformSpace relativeTo=TS_LOCAL)
Rotate the node around the Z-axis.
virtual const Vector3 & getInitialScale(void) const
Gets the initial position of this node, see setInitialState for more info.
set< Node * >::type ChildUpdateSet
Definition: OgreNode.h:131
virtual void rotate(const Quaternion &q, TransformSpace relativeTo=TS_LOCAL)
Rotate the node around an aritrary axis using a Quarternion.
virtual void yaw(const Radian &angle, TransformSpace relativeTo=TS_LOCAL)
Rotate the node around the Y-axis.
UserObjectBindings & getUserObjectBindings()
Return an instance of user objects binding associated with this class.
Definition: OgreNode.h:766
static void processQueuedUpdates(void)
Process queued 'needUpdate' calls.
Implementation of a Quaternion, i.e.
static const Quaternion IDENTITY
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:48
'New' rendering operation using vertex buffers.
Abstract class defining the interface all renderable objects must implement.
Class that provides convenient interface to establish a linkage between custom user application objec...
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
static const Vector3 ZERO
Definition: OgreVector3.h:800
float Real
Software floating point type.
_StringBase String

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.