OGRE  2.0
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 "OgreMatrix4.h"
34 #include "OgreRenderable.h"
35 #include "OgreUserObjectBindings.h"
36 #include "OgreId.h"
38 #include "OgreHeaderPrefix.h"
39 
40 namespace Ogre {
41 
58  class _OgreExport Node : public NodeAlloc, public IdObject
59  {
60  public:
64  {
70  TS_WORLD
71  };
75 
79  {
80  public:
81  Listener() {}
82  virtual ~Listener() {}
90  virtual void nodeUpdated(const Node*) {}
92  virtual void nodeDestroyed(const Node*) {}
94  virtual void nodeAttached(const Node*) {}
96  virtual void nodeDetached(const Node*) {}
97  };
98 
100  class DebugRenderable : public Renderable, public NodeAlloc
101  {
102  protected:
107  public:
108  DebugRenderable(Node* parent);
109  ~DebugRenderable();
110  const MaterialPtr& getMaterial(void) const;
111  void getRenderOperation(RenderOperation& op);
112  void getWorldTransforms(Matrix4* xform) const;
113  Real getSquaredViewDepth(const Camera* cam) const;
114  const LightList& getLights(void) const;
115  void setScaling(Real s) { mScaling = s; }
116 
117  };
118 
119  protected:
128 
131 
133  void setParent( Node* parent );
134  void unsetParent(void);
135 
137  void parentDepthLevelChanged(void);
138 
145  void _updateFromParent(void);
146 
153  virtual void updateFromParentImpl(void);
154 
156  virtual Node* createChildImpl( SceneMemoryMgrTypes sceneType ) = 0;
157 
158 #ifndef NDEBUG
160 #endif
161 
164 
167 
169 
172 
173  public:
180  size_t mGlobalIndex;
182  size_t mParentIndex;
183 
188  Node( IdType id, NodeMemoryManager *nodeMemoryManager, Node *parent );
189 
193  Node( const Transform &transformPtrs );
194 
195  virtual ~Node();
196 
198  void setName( const String &name ) { mName = name; }
199 
201  const String& getName(void) const { return mName; }
202 
204  Node* getParent(void) const;
205 
207  bool isStatic() const;
208 
224  virtual bool setStatic( bool bStatic );
225 
227  uint16 getDepthLevel() const { return mDepthLevel; }
228 
230  Transform& _getTransform() { return mTransform; }
231 
234  virtual void _notifyStaticDirty(void) const;
235 
240  virtual_l2 Quaternion getOrientation() const;
241 
256  virtual_l1 void setOrientation( Quaternion q );
257 
272  virtual_l1 void setOrientation( Real w, Real x, Real y, Real z);
273 
287  virtual_l1 void resetOrientation(void);
288 
293  virtual_l1 void setPosition( const Vector3& pos );
294 
299  virtual_l1 void setPosition(Real x, Real y, Real z);
300 
305  virtual_l2 Vector3 getPosition(void) const;
306 
320  virtual_l1 void setScale(const Vector3& scale);
321 
335  virtual_l1 void setScale(Real x, Real y, Real z);
336 
341  virtual_l2 Vector3 getScale(void) const;
342 
356  virtual_l2 void setInheritOrientation(bool inherit);
357 
371  virtual_l2 bool getInheritOrientation(void) const;
372 
385  virtual_l2 void setInheritScale(bool inherit);
386 
391  virtual_l2 bool getInheritScale(void) const;
392 
402  virtual_l2 void scale(const Vector3& scale);
403 
413  virtual_l2 void scale(Real x, Real y, Real z);
414 
424  virtual_l2 void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT);
438  virtual_l2 void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
458  virtual_l2 void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT);
482  virtual_l2 void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
483 
486  virtual_l2 void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
487 
490  virtual_l2 void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
491 
494  virtual_l2 void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
495 
498  virtual_l2 void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
499 
502  virtual_l2 void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL);
503 
506  virtual_l2 Matrix3 getLocalAxes(void) const;
507 
514  virtual Node* createChild(
516  const Vector3& translate = Vector3::ZERO,
517  const Quaternion& rotate = Quaternion::IDENTITY );
518 
523  void addChild(Node* child);
524 
527  size_t numChildren(void) const { return mChildren.size(); }
528 
530  Node* getChild( size_t index ) { return mChildren[index]; }
531  const Node* getChild( size_t index ) const { return mChildren[index]; }
532 
543  NodeVecIterator getChildIterator(void);
544 
555  ConstNodeVecIterator getChildIterator(void) const;
556 
564  virtual void removeChild( Node* child );
565 
569  virtual void removeAllChildren(void);
570 
575  virtual_l2 void _setDerivedPosition(const Vector3& pos);
576 
582  virtual_l2 void _setDerivedOrientation(const Quaternion& q);
583 
591  virtual_l2 Quaternion _getDerivedOrientation(void) const;
592 
601  virtual_l2 Quaternion _getDerivedOrientationUpdated(void);
602 
610  virtual_l2 Vector3 _getDerivedPosition(void) const;
611 
620  virtual_l2 Vector3 _getDerivedPositionUpdated(void);
621 
629  virtual_l2 Vector3 _getDerivedScale(void) const;
630 
639  virtual_l2 Vector3 _getDerivedScaleUpdated(void);
640 
652  {
653  assert( !mCachedTransformOutOfDate );
654  return mTransform.mDerivedTransform[mTransform.mIndex];
655  }
656 
658  virtual_l2 const Matrix4& _getFullTransformUpdated(void);
659 
665  virtual void setListener(Listener* listener) { mListener = listener; }
666 
669  Listener* getListener(void) const { return mListener; }
670 
675  static void updateAllTransforms( const size_t numNodes, Transform t );
676 
678  virtual_l2 Vector3 convertWorldToLocalPosition( const Vector3 &worldPos );
679 
682  virtual_l2 Vector3 convertLocalToWorldPosition( const Vector3 &localPos );
683 
685  virtual_l2 Quaternion convertWorldToLocalOrientation( const Quaternion &worldOrientation );
686 
689  virtual_l2 Quaternion convertLocalToWorldOrientation( const Quaternion &localOrientation );
690 
692  virtual Real getSquaredViewDepth(const Camera* cam) const;
693 
695  virtual DebugRenderable* getDebugRenderable(Real scaling);
696 
704  OGRE_DEPRECATED virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
705 
709  OGRE_DEPRECATED virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
710 
715  UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
716 
721  const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
722 
728  void _setNullNodeMemoryManager(void) { mNodeMemoryManager = 0; }
729 
733  virtual void _callMemoryChangeListeners(void) = 0;
734 
735 #ifndef NDEBUG
736  virtual void _setCachedTransformOutOfDate(void);
737  bool isCachedTransformOutOfDate(void) const { return mCachedTransformOutOfDate; }
738 #endif
739  };
743 } // namespace Ogre
744 
745 #include "OgreHeaderSuffix.h"
746 
747 #endif // _Node_H__
vector< Node * >::type NodeVec
Definition: OgreNode.h:72
DebugRenderable * mDebug
Definition: OgreNode.h:168
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
Represents the transform of a single object, arranged in SoA (Structure of Arrays) ...
Definition: OgreTransform.h:37
float Real
Software floating point type.
Transform & _getTransform()
Returns a direct access to the Transform state.
Definition: OgreNode.h:230
const Node * getChild(size_t index) const
Definition: OgreNode.h:531
#define _OgreExport
Definition: OgrePlatform.h:255
Variant type that can hold Any other type.
Definition: OgreAny.h:54
uint16 getDepthLevel() const
Returns how deep in the hierarchy we are (eg. 0 -> root node, 1 -> child of root) ...
Definition: OgreNode.h:227
Transform is relative to the local space.
Definition: OgreNode.h:66
virtual ~Listener()
Definition: OgreNode.h:82
TransformSpace
Enumeration denoting the spaces which a transform can be relative to.
Definition: OgreNode.h:63
static const Vector3 ZERO
Definition: OgreVector3.h:807
bool mCachedTransformOutOfDate
Definition: OgreNode.h:159
#define virtual_l2
Definition: OgrePlatform.h:379
void setName(const String &name)
Sets a custom name for this node.
Definition: OgreNode.h:198
A 3x3 matrix which can represent rotations around axes.
Definition: OgreMatrix3.h:68
Transform mTransform
All the transform data needed in SoA form.
Definition: OgreNode.h:127
virtual void nodeUpdated(const Node *)
Called when a node gets updated.
Definition: OgreNode.h:90
Abstract class defining the interface all renderable objects must implement.
virtual void nodeDestroyed(const Node *)
Node is being destroyed.
Definition: OgreNode.h:92
Implementation of a Quaternion, i.e.
virtual void nodeAttached(const Node *)
Node has been attached to a parent.
Definition: OgreNode.h:94
UserObjectBindings & getUserObjectBindings()
Return an instance of user objects binding associated with this class.
Definition: OgreNode.h:715
#define virtual_l1
Definition: OgrePlatform.h:374
static const Quaternion IDENTITY
virtual void nodeDetached(const Node *)
Node has been detached from a parent.
Definition: OgreNode.h:96
bool isCachedTransformOutOfDate(void) const
Definition: OgreNode.h:737
Ogre::uint32 IdType
Big projects with lots, lots of units for very long periods of time (MMORPGs?) may want to define thi...
Definition: OgreId.h:36
Transform is relative to the space of the parent node.
Definition: OgreNode.h:68
Concrete IteratorWrapper for const access to the underlying container.
Listener * mListener
Node listener - only one allowed (no list) for size & performance reasons.
Definition: OgreNode.h:163
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
UserObjectBindings mUserObjectBindings
User objects binding.
Definition: OgreNode.h:171
NodeVec mChildren
Collection of pointers to direct children; hashmap for efficiency.
Definition: OgreNode.h:125
virtual_l2 FORCEINLINE const Matrix4 & _getFullTransform(void) const
Gets the full transformation matrix for this node.
Definition: OgreNode.h:651
const String & getName(void) const
Returns the name of the node.
Definition: OgreNode.h:201
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
const UserObjectBindings & getUserObjectBindings() const
Return an instance of user objects binding associated with this class.
Definition: OgreNode.h:721
size_t mParentIndex
Index in the vector holding this node reference (could be our parent node, or a global array tracking...
Definition: OgreNode.h:182
virtual OGRE_DEPRECATED void setUserAny(const Any &anything)
Definition: OgreNode.h:704
'New' rendering operation using vertex buffers.
String mName
Friendly name of this node, can be empty.
Definition: OgreNode.h:130
Node * getChild(size_t index)
Gets a pointer to a child node.
Definition: OgreNode.h:530
virtual OGRE_DEPRECATED const Any & getUserAny(void) const
Definition: OgreNode.h:709
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:49
VectorIterator< NodeVec > NodeVecIterator
Definition: OgreNode.h:73
SceneMemoryMgrTypes
The types of NodeMemoryManager & ObjectMemoryManagers.
Definition: OgreCommon.h:318
void _setNullNodeMemoryManager(void)
Manually set the mNodeMemoryManager to a null ptr.
Definition: OgreNode.h:728
size_t numChildren(void) const
Reports the number of child nodes under this one.
Definition: OgreNode.h:527
#define FORCEINLINE
Definition: OgrePlatform.h:104
_StringBase String
Definition: OgreCommon.h:53
#define OGRE_DEPRECATED
Definition: OgrePlatform.h:185
uint16 mDepthLevel
Depth level in the hierarchy tree (0: Root node, 1: Child of root, etc)
Definition: OgreNode.h:121
size_t mGlobalIndex
Index in the vector holding this node reference (could be our parent node, or a global array tracking...
Definition: OgreNode.h:180
unsigned short uint16
Definition: OgrePlatform.h:421
Concrete IteratorWrapper for nonconst access to the underlying container.
Node * mParent
Pointer to parent node.
Definition: OgreNode.h:123
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:58
Listener * getListener(void) const
Gets the current listener for this Node.
Definition: OgreNode.h:669
Listener which gets called back on Node events.
Definition: OgreNode.h:78
ConstVectorIterator< NodeVec > ConstNodeVecIterator
Definition: OgreNode.h:74
Wrap-around class that contains multiple ArrayMemoryManager, one per hierarchy depth.
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:100
virtual void setListener(Listener *listener)
Sets a listener for this Node.
Definition: OgreNode.h:665
NodeMemoryManager * mNodeMemoryManager
The memory manager used to allocate the Transform.
Definition: OgreNode.h:166