OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 
43 namespace Ogre {
44 
45 
62  class _OgreExport Node : public NodeAlloc
63  {
64  public:
68  {
74  TS_WORLD
75  };
76  typedef HashMap<String, Node*> ChildNodeMap;
79 
83  {
84  public:
85  Listener() {}
86  virtual ~Listener() {}
94  virtual void nodeUpdated(const Node*) {}
96  virtual void nodeDestroyed(const Node*) {}
98  virtual void nodeAttached(const Node*) {}
100  virtual void nodeDetached(const Node*) {}
101  };
102 
104  class DebugRenderable : public Renderable, public NodeAlloc
105  {
106  protected:
111  public:
112  DebugRenderable(Node* parent);
113  ~DebugRenderable();
114  const MaterialPtr& getMaterial(void) const;
115  void getRenderOperation(RenderOperation& op);
116  void getWorldTransforms(Matrix4* xform) const;
117  Real getSquaredViewDepth(const Camera* cam) const;
118  const LightList& getLights(void) const;
119  void setScaling(Real s) { mScaling = s; }
120 
121  };
122 
123  protected:
128 
133  mutable bool mNeedParentUpdate;
135  mutable bool mNeedChildUpdate;
137  mutable bool mParentNotified ;
139  mutable bool mQueuedForUpdate;
140 
143 
146 
149 
152 
155 
158 
161 
163  virtual void setParent(Node* parent);
164 
173 
182 
191 
198  virtual void _updateFromParent(void) const;
199 
206  virtual void updateFromParentImpl(void) const;
207 
208 
210  virtual Node* createChildImpl(void) = 0;
211 
213  virtual Node* createChildImpl(const String& name) = 0;
214 
221 
225 
228 
231 
233 
236 
237  public:
242  Node();
247  Node(const String& name);
248 
249  virtual ~Node();
250 
252  const String& getName(void) const;
253 
256  virtual Node* getParent(void) const;
257 
260  virtual const Quaternion & getOrientation() const;
261 
275  virtual void setOrientation( const Quaternion& q );
276 
290  virtual void setOrientation( Real w, Real x, Real y, Real z);
291 
305  virtual void resetOrientation(void);
306 
309  virtual void setPosition(const Vector3& pos);
310 
313  virtual void setPosition(Real x, Real y, Real z);
314 
317  virtual const Vector3 & getPosition(void) const;
318 
331  virtual void setScale(const Vector3& scale);
332 
345  virtual void setScale(Real x, Real y, Real z);
346 
349  virtual const Vector3 & getScale(void) const;
350 
364  virtual void setInheritOrientation(bool inherit);
365 
379  virtual bool getInheritOrientation(void) const;
380 
393  virtual void setInheritScale(bool inherit);
394 
399  virtual bool getInheritScale(void) const;
400 
410  virtual void scale(const Vector3& scale);
411 
421  virtual void scale(Real x, Real y, Real z);
422 
432  virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT);
446  virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
466  virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT);
486  virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
487 
490  virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
491 
494  virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
495 
498  virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
499 
502  virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
503 
506  virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL);
507 
510  virtual Matrix3 getLocalAxes(void) const;
511 
518  virtual Node* createChild(
519  const Vector3& translate = Vector3::ZERO,
520  const Quaternion& rotate = Quaternion::IDENTITY );
521 
531  virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY);
532 
537  virtual void addChild(Node* child);
538 
541  virtual unsigned short numChildren(void) const;
542 
547  virtual Node* getChild(unsigned short index) const;
548 
551  virtual Node* getChild(const String& name) const;
552 
563  virtual ChildNodeIterator getChildIterator(void);
564 
575  virtual ConstChildNodeIterator getChildIterator(void) const;
576 
584  virtual Node* removeChild(unsigned short index);
592  virtual Node* removeChild(Node* child);
593 
599  virtual Node* removeChild(const String& name);
603  virtual void removeAllChildren(void);
604 
609  virtual void _setDerivedPosition(const Vector3& pos);
610 
616  virtual void _setDerivedOrientation(const Quaternion& q);
617 
620  virtual const Quaternion & _getDerivedOrientation(void) const;
621 
624  virtual const Vector3 & _getDerivedPosition(void) const;
625 
628  virtual const Vector3 & _getDerivedScale(void) const;
629 
639  virtual const Matrix4& _getFullTransform(void) const;
640 
653  virtual void _update(bool updateChildren, bool parentHasChanged);
654 
660  virtual void setListener(Listener* listener) { mListener = listener; }
661 
664  virtual Listener* getListener(void) const { return mListener; }
665 
666 
677  virtual void setInitialState(void);
678 
680  virtual void resetToInitialState(void);
681 
686  virtual const Vector3& getInitialPosition(void) const;
687 
689  virtual Vector3 convertWorldToLocalPosition( const Vector3 &worldPos );
690 
693  virtual Vector3 convertLocalToWorldPosition( const Vector3 &localPos );
694 
696  virtual Quaternion convertWorldToLocalOrientation( const Quaternion &worldOrientation );
697 
700  virtual Quaternion convertLocalToWorldOrientation( const Quaternion &localOrientation );
701 
703  virtual const Quaternion& getInitialOrientation(void) const;
704 
706  virtual const Vector3& getInitialScale(void) const;
707 
709  Real getSquaredViewDepth(const Camera* cam) const;
710 
718  virtual void needUpdate(bool forceParentUpdate = false);
723  virtual void requestUpdate(Node* child, bool forceParentUpdate = false);
725  virtual void cancelUpdate(Node* child);
726 
728  virtual DebugRenderable* getDebugRenderable(Real scaling);
729 
737  static void queueNeedUpdate(Node* n);
739  static void processQueuedUpdates(void);
740 
741 
749  virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
750 
754  virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
755 
760  UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
761 
766  const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
767 
768  };
772 } //namespace
773 
774 #endif
ChildNodeMap mChildren
Collection of pointers to direct children; hashmap for efficiency.
Definition: OgreNode.h:127
DebugRenderable * mDebug
Definition: OgreNode.h:232
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:85
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:148
float Real
Software floating point type.
Vector3 mInitialScale
The scale to use as a base for keyframe animation.
Definition: OgreNode.h:220
#define _OgreExport
Definition: OgrePlatform.h:203
ConstMapIterator< ChildNodeMap > ConstChildNodeIterator
Definition: OgreNode.h:78
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:741
Transform is relative to the local space.
Definition: OgreNode.h:70
virtual Listener * getListener(void) const
Gets the current listener for this Node.
Definition: OgreNode.h:664
MapIterator< ChildNodeMap > ChildNodeIterator
Definition: OgreNode.h:77
virtual ~Listener()
Definition: OgreNode.h:86
virtual const Any & getUserAny(void) const
Definition: OgreNode.h:754
TransformSpace
Enumeration denoting the spaces which a transform can be relative to.
Definition: OgreNode.h:67
vector< Node * >::type QueuedUpdates
Definition: OgreNode.h:229
static const Vector3 ZERO
Definition: OgreVector3.h:774
bool mCachedTransformOutOfDate
Definition: OgreNode.h:224
Quaternion mDerivedOrientation
Cached combined orientation.
Definition: OgreNode.h:172
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:94
bool mParentNotified
Flag indicating that parent has been notified about update request.
Definition: OgreNode.h:137
Abstract class defining the interface all renderable objects must implement.
virtual void nodeDestroyed(const Node *)
Node is being destroyed.
Definition: OgreNode.h:96
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:151
virtual void nodeAttached(const Node *)
Node has been attached to a parent.
Definition: OgreNode.h:98
static QueuedUpdates msQueuedUpdates
Definition: OgreNode.h:230
UserObjectBindings & getUserObjectBindings()
Return an instance of user objects binding associated with this class.
Definition: OgreNode.h:760
virtual void setUserAny(const Any &anything)
Definition: OgreNode.h:749
static const Quaternion IDENTITY
Vector3 mDerivedScale
Cached combined scale.
Definition: OgreNode.h:190
bool mInheritOrientation
Stores whether this node inherits orientation from it's parent.
Definition: OgreNode.h:157
static NameGenerator msNameGenerator
Incremented count for next name extension.
Definition: OgreNode.h:145
ChildUpdateSet mChildrenToUpdate
List of children which need updating, used if self is not out of date but children are...
Definition: OgreNode.h:131
virtual void nodeDetached(const Node *)
Node has been detached from a parent.
Definition: OgreNode.h:100
bool mInheritScale
Stores whether this node inherits scale from it's parent.
Definition: OgreNode.h:160
Transform is relative to the space of the parent node.
Definition: OgreNode.h:72
bool mNeedParentUpdate
Flag to indicate own transform from parent is out of date.
Definition: OgreNode.h:133
Listener * mListener
Node listener - only one allowed (no list) for size & performance reasons.
Definition: OgreNode.h:227
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
UserObjectBindings mUserObjectBindings
User objects binding.
Definition: OgreNode.h:235
HashMap< String, Node * > ChildNodeMap
Definition: OgreNode.h:76
bool mQueuedForUpdate
Flag indicating that the node has been queued for update.
Definition: OgreNode.h:139
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:766
Vector3 mInitialPosition
The position to use as a base for keyframe animation.
Definition: OgreNode.h:216
'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:142
Quaternion mInitialOrientation
The orientation to use as a base for keyframe animation.
Definition: OgreNode.h:218
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:46
set< Node * >::type ChildUpdateSet
Definition: OgreNode.h:129
bool mNeedChildUpdate
Flag indicating that all children need to be updated.
Definition: OgreNode.h:135
Concrete IteratorWrapper for const access to the underlying key-value container.
Matrix4 mCachedTransform
Cached derived transform as a 4x4 matrix.
Definition: OgreNode.h:223
Vector3 mDerivedPosition
Cached combined position.
Definition: OgreNode.h:181
_StringBase String
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:677
Specialisation of SharedPtr to allow SharedPtr to be assigned to MeshPtr.
Definition: OgreMesh.h:894
Node * mParent
Pointer to parent node.
Definition: OgreNode.h:125
Vector3 mScale
Stores the scaling factor applied to this node.
Definition: OgreNode.h:154
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:62
Listener which gets called back on Node events.
Definition: OgreNode.h:82
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:104
virtual void setListener(Listener *listener)
Sets a listener for this Node.
Definition: OgreNode.h:660