OGRE  1.8
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-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 
63  class _OgreExport Node : public NodeAlloc
64  {
65  public:
69  {
75  TS_WORLD
76  };
77  typedef HashMap<String, Node*> ChildNodeMap;
80 
84  {
85  public:
86  Listener() {}
87  virtual ~Listener() {}
95  virtual void nodeUpdated(const Node*) {}
97  virtual void nodeDestroyed(const Node*) {}
99  virtual void nodeAttached(const Node*) {}
101  virtual void nodeDetached(const Node*) {}
102  };
103 
105  class DebugRenderable : public Renderable, public NodeAlloc
106  {
107  protected:
112  public:
113  DebugRenderable(Node* parent);
114  ~DebugRenderable();
115  const MaterialPtr& getMaterial(void) const;
116  void getRenderOperation(RenderOperation& op);
117  void getWorldTransforms(Matrix4* xform) const;
118  Real getSquaredViewDepth(const Camera* cam) const;
119  const LightList& getLights(void) const;
120  void setScaling(Real s) { mScaling = s; }
121 
122  };
123 
124  protected:
129 
134  mutable bool mNeedParentUpdate;
136  mutable bool mNeedChildUpdate;
138  mutable bool mParentNotified ;
140  mutable bool mQueuedForUpdate;
141 
144 
147 
150 
153 
156 
159 
162 
164  virtual void setParent(Node* parent);
165 
174 
183 
192 
199  virtual void _updateFromParent(void) const;
200 
207  virtual void updateFromParentImpl(void) const;
208 
209 
211  virtual Node* createChildImpl(void) = 0;
212 
214  virtual Node* createChildImpl(const String& name) = 0;
215 
222 
226 
229 
232 
234 
237 
238  public:
243  Node();
248  Node(const String& name);
249 
250  virtual ~Node();
251 
253  const String& getName(void) const;
254 
257  virtual Node* getParent(void) const;
258 
261  virtual const Quaternion & getOrientation() const;
262 
276  virtual void setOrientation( const Quaternion& q );
277 
291  virtual void setOrientation( Real w, Real x, Real y, Real z);
292 
306  virtual void resetOrientation(void);
307 
310  virtual void setPosition(const Vector3& pos);
311 
314  virtual void setPosition(Real x, Real y, Real z);
315 
318  virtual const Vector3 & getPosition(void) const;
319 
332  virtual void setScale(const Vector3& scale);
333 
346  virtual void setScale(Real x, Real y, Real z);
347 
350  virtual const Vector3 & getScale(void) const;
351 
365  virtual void setInheritOrientation(bool inherit);
366 
380  virtual bool getInheritOrientation(void) const;
381 
394  virtual void setInheritScale(bool inherit);
395 
400  virtual bool getInheritScale(void) const;
401 
411  virtual void scale(const Vector3& scale);
412 
422  virtual void scale(Real x, Real y, Real z);
423 
433  virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT);
447  virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
467  virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT);
487  virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
488 
491  virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
492 
495  virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
496 
499  virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
500 
503  virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
504 
507  virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL);
508 
511  virtual Matrix3 getLocalAxes(void) const;
512 
519  virtual Node* createChild(
520  const Vector3& translate = Vector3::ZERO,
521  const Quaternion& rotate = Quaternion::IDENTITY );
522 
532  virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY);
533 
538  virtual void addChild(Node* child);
539 
542  virtual unsigned short numChildren(void) const;
543 
548  virtual Node* getChild(unsigned short index) const;
549 
552  virtual Node* getChild(const String& name) const;
553 
564  virtual ChildNodeIterator getChildIterator(void);
565 
576  virtual ConstChildNodeIterator getChildIterator(void) const;
577 
585  virtual Node* removeChild(unsigned short index);
593  virtual Node* removeChild(Node* child);
594 
600  virtual Node* removeChild(const String& name);
604  virtual void removeAllChildren(void);
605 
610  virtual void _setDerivedPosition(const Vector3& pos);
611 
617  virtual void _setDerivedOrientation(const Quaternion& q);
618 
621  virtual const Quaternion & _getDerivedOrientation(void) const;
622 
625  virtual const Vector3 & _getDerivedPosition(void) const;
626 
629  virtual const Vector3 & _getDerivedScale(void) const;
630 
640  virtual const Matrix4& _getFullTransform(void) const;
641 
654  virtual void _update(bool updateChildren, bool parentHasChanged);
655 
661  virtual void setListener(Listener* listener) { mListener = listener; }
662 
665  virtual Listener* getListener(void) const { return mListener; }
666 
667 
678  virtual void setInitialState(void);
679 
681  virtual void resetToInitialState(void);
682 
687  virtual const Vector3& getInitialPosition(void) const;
688 
690  virtual Vector3 convertWorldToLocalPosition( const Vector3 &worldPos );
691 
694  virtual Vector3 convertLocalToWorldPosition( const Vector3 &localPos );
695 
697  virtual Quaternion convertWorldToLocalOrientation( const Quaternion &worldOrientation );
698 
701  virtual Quaternion convertLocalToWorldOrientation( const Quaternion &localOrientation );
702 
704  virtual const Quaternion& getInitialOrientation(void) const;
705 
707  virtual const Vector3& getInitialScale(void) const;
708 
710  virtual Real getSquaredViewDepth(const Camera* cam) const;
711 
719  virtual void needUpdate(bool forceParentUpdate = false);
724  virtual void requestUpdate(Node* child, bool forceParentUpdate = false);
726  virtual void cancelUpdate(Node* child);
727 
729  virtual DebugRenderable* getDebugRenderable(Real scaling);
730 
738  static void queueNeedUpdate(Node* n);
740  static void processQueuedUpdates(void);
741 
742 
750  virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
751 
755  virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
756 
761  UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
762 
767  const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
768 
769  };
773 } //namespace
774 
775 #include "OgreHeaderSuffix.h"
776 
777 #endif
ChildNodeMap mChildren
Collection of pointers to direct children; hashmap for efficiency.
Definition: OgreNode.h:128
DebugRenderable * mDebug
Definition: OgreNode.h:233
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:149
float Real
Software floating point type.
Vector3 mInitialScale
The scale to use as a base for keyframe animation.
Definition: OgreNode.h:221
#define _OgreExport
Definition: OgrePlatform.h:233
ConstMapIterator< ChildNodeMap > ConstChildNodeIterator
Definition: OgreNode.h:79
Variant type that can hold Any other type.
Definition: OgreAny.h:56
Utility class to generate a sequentially numbered series of names.
Definition: OgreCommon.h:770
Transform is relative to the local space.
Definition: OgreNode.h:71
virtual Listener * getListener(void) const
Gets the current listener for this Node.
Definition: OgreNode.h:665
MapIterator< ChildNodeMap > ChildNodeIterator
Definition: OgreNode.h:78
virtual ~Listener()
Definition: OgreNode.h:87
virtual const Any & getUserAny(void) const
Definition: OgreNode.h:755
TransformSpace
Enumeration denoting the spaces which a transform can be relative to.
Definition: OgreNode.h:68
vector< Node * >::type QueuedUpdates
Definition: OgreNode.h:230
static const Vector3 ZERO
Definition: OgreVector3.h:796
bool mCachedTransformOutOfDate
Definition: OgreNode.h:225
Quaternion mDerivedOrientation
Cached combined orientation.
Definition: OgreNode.h:173
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:95
bool mParentNotified
Flag indicating that parent has been notified about update request.
Definition: OgreNode.h:138
Abstract class defining the interface all renderable objects must implement.
virtual void nodeDestroyed(const Node *)
Node is being destroyed.
Definition: OgreNode.h:97
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:152
virtual void nodeAttached(const Node *)
Node has been attached to a parent.
Definition: OgreNode.h:99
static QueuedUpdates msQueuedUpdates
Definition: OgreNode.h:231
UserObjectBindings & getUserObjectBindings()
Return an instance of user objects binding associated with this class.
Definition: OgreNode.h:761
virtual void setUserAny(const Any &anything)
Definition: OgreNode.h:750
static const Quaternion IDENTITY
Vector3 mDerivedScale
Cached combined scale.
Definition: OgreNode.h:191
bool mInheritOrientation
Stores whether this node inherits orientation from it's parent.
Definition: OgreNode.h:158
static NameGenerator msNameGenerator
Incremented count for next name extension.
Definition: OgreNode.h:146
ChildUpdateSet mChildrenToUpdate
List of children which need updating, used if self is not out of date but children are...
Definition: OgreNode.h:132
virtual void nodeDetached(const Node *)
Node has been detached from a parent.
Definition: OgreNode.h:101
bool mInheritScale
Stores whether this node inherits scale from it's parent.
Definition: OgreNode.h:161
Transform is relative to the space of the parent node.
Definition: OgreNode.h:73
bool mNeedParentUpdate
Flag to indicate own transform from parent is out of date.
Definition: OgreNode.h:134
Listener * mListener
Node listener - only one allowed (no list) for size & performance reasons.
Definition: OgreNode.h:228
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
UserObjectBindings mUserObjectBindings
User objects binding.
Definition: OgreNode.h:236
HashMap< String, Node * > ChildNodeMap
Definition: OgreNode.h:77
bool mQueuedForUpdate
Flag indicating that the node has been queued for update.
Definition: OgreNode.h:140
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:767
Vector3 mInitialPosition
The position to use as a base for keyframe animation.
Definition: OgreNode.h:217
'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:143
Quaternion mInitialOrientation
The orientation to use as a base for keyframe animation.
Definition: OgreNode.h:219
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:46
set< Node * >::type ChildUpdateSet
Definition: OgreNode.h:130
bool mNeedChildUpdate
Flag indicating that all children need to be updated.
Definition: OgreNode.h:136
Concrete IteratorWrapper for const access to the underlying key-value container.
Matrix4 mCachedTransform
Cached derived transform as a 4x4 matrix.
Definition: OgreNode.h:224
Vector3 mDerivedPosition
Cached combined position.
Definition: OgreNode.h:182
_StringBase String
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:688
Specialisation of SharedPtr to allow SharedPtr to be assigned to MeshPtr.
Definition: OgreMesh.h:875
Node * mParent
Pointer to parent node.
Definition: OgreNode.h:126
Vector3 mScale
Stores the scaling factor applied to this node.
Definition: OgreNode.h:155
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:63
Listener which gets called back on Node events.
Definition: OgreNode.h:83
Class that provide convenient interface to establish a linkage between custom user application object...
Inner class for displaying debug renderable for Node.
Definition: OgreNode.h:105
virtual void setListener(Listener *listener)
Sets a listener for this Node.
Definition: OgreNode.h:661