OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2014 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:
114  DebugRenderable(Node* parent);
115  ~DebugRenderable();
116  const MaterialPtr& getMaterial(void) const;
117  void getRenderOperation(RenderOperation& op);
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 
569  virtual ChildNodeIterator getChildIterator(void);
570 
581  virtual ConstChildNodeIterator getChildIterator(void) const;
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 
734  virtual DebugRenderable* getDebugRenderable(Real scaling);
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__
ChildNodeMap mChildren
Collection of pointers to direct children; hashmap for efficiency.
Definition: OgreNode.h:129
DebugRenderable * mDebug
Definition: OgreNode.h:234
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
Quaternion mOrientation
Stores the orientation of the node relative to it's parent.
Definition: OgreNode.h:150
float Real
Software floating point type.
Vector3 mInitialScale
The scale to use as a base for keyframe animation.
Definition: OgreNode.h:222
#define _OgreExport
Definition: OgrePlatform.h:260
ConstMapIterator< ChildNodeMap > ConstChildNodeIterator
Definition: OgreNode.h:80
Variant type that can hold Any other type.
Definition: OgreAny.h:56
Utility class to generate a sequentially numbered series of names.
Transform is relative to the local space.
Definition: OgreNode.h:72
virtual Listener * getListener(void) const
Gets the current listener for this Node.
Definition: OgreNode.h:670
MapIterator< ChildNodeMap > ChildNodeIterator
Definition: OgreNode.h:79
virtual ~Listener()
Definition: OgreNode.h:88
TransformSpace
Enumeration denoting the spaces which a transform can be relative to.
Definition: OgreNode.h:69
vector< Node * >::type QueuedUpdates
Definition: OgreNode.h:231
static const Vector3 ZERO
Definition: OgreVector3.h:800
bool mCachedTransformOutOfDate
Definition: OgreNode.h:226
Quaternion mDerivedOrientation
Cached combined orientation.
Definition: OgreNode.h:174
A 3x3 matrix which can represent rotations around axes.
Definition: OgreMatrix3.h:68
virtual void nodeUpdated(const Node *)
Called when a node gets updated.
Definition: OgreNode.h:96
bool mParentNotified
Flag indicating that parent has been notified about update request.
Definition: OgreNode.h:139
Abstract class defining the interface all renderable objects must implement.
virtual void nodeDestroyed(const Node *)
Node is being destroyed.
Definition: OgreNode.h:98
Implementation of a Quaternion, i.e.
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
Vector3 mPosition
Stores the position/translation of the node relative to its parent.
Definition: OgreNode.h:153
virtual void nodeAttached(const Node *)
Node has been attached to a parent.
Definition: OgreNode.h:100
static QueuedUpdates msQueuedUpdates
Definition: OgreNode.h:232
UserObjectBindings & getUserObjectBindings()
Return an instance of user objects binding associated with this class.
Definition: OgreNode.h:766
static const Quaternion IDENTITY
Vector3 mDerivedScale
Cached combined scale.
Definition: OgreNode.h:192
bool mInheritOrientation
Stores whether this node inherits orientation from it's parent.
Definition: OgreNode.h:159
static NameGenerator msNameGenerator
Incremented count for next name extension.
Definition: OgreNode.h:147
ChildUpdateSet mChildrenToUpdate
List of children which need updating, used if self is not out of date but children are...
Definition: OgreNode.h:133
virtual void nodeDetached(const Node *)
Node has been detached from a parent.
Definition: OgreNode.h:102
bool mInheritScale
Stores whether this node inherits scale from it's parent.
Definition: OgreNode.h:162
Transform is relative to the space of the parent node.
Definition: OgreNode.h:74
bool mNeedParentUpdate
Flag to indicate own transform from parent is out of date.
Definition: OgreNode.h:135
Listener * mListener
Node listener - only one allowed (no list) for size & performance reasons.
Definition: OgreNode.h:229
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
UserObjectBindings mUserObjectBindings
User objects binding.
Definition: OgreNode.h:237
HashMap< String, Node * > ChildNodeMap
Definition: OgreNode.h:78
bool mQueuedForUpdate
Flag indicating that the node has been queued for update.
Definition: OgreNode.h:141
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
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 OGRE_DEPRECATED void setUserAny(const Any &anything)
Definition: OgreNode.h:755
'New' rendering operation using vertex buffers.
String mName
Friendly name of this node, can be automatically generated if you don't care.
Definition: OgreNode.h:144
virtual OGRE_DEPRECATED const Any & getUserAny(void) const
Definition: OgreNode.h:760
Quaternion mInitialOrientation
The orientation to use as a base for keyframe animation.
Definition: OgreNode.h:220
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:47
set< Node * >::type ChildUpdateSet
Definition: OgreNode.h:131
bool mNeedChildUpdate
Flag indicating that all children need to be updated.
Definition: OgreNode.h:137
Concrete IteratorWrapper for const access to the underlying key-value container.
Matrix4 mCachedTransform
Cached derived transform as a 4x4 matrix.
Definition: OgreNode.h:225
Vector3 mDerivedPosition
Cached combined position.
Definition: OgreNode.h:183
_StringBase String
#define OGRE_DEPRECATED
Definition: OgrePlatform.h:192
Node * mParent
Pointer to parent node.
Definition: OgreNode.h:127
Vector3 mScale
Stores the scaling factor applied to this node.
Definition: OgreNode.h:156
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:64
Listener which gets called back on Node events.
Definition: OgreNode.h:84
Class that provides convenient interface to establish a linkage between custom user application objec...
Inner class for displaying debug renderable for Node.
Definition: OgreNode.h:106
virtual void setListener(Listener *listener)
Sets a listener for this Node.
Definition: OgreNode.h:666