Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OgreNode.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2005 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef _Node_H__
00026 #define _Node_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 
00030 #include "OgreMatrix3.h"
00031 #include "OgreMatrix4.h"
00032 #include "OgreQuaternion.h"
00033 #include "OgreString.h"
00034 #include "OgreRenderable.h"
00035 #include "OgreIteratorWrappers.h"
00036 
00037 namespace Ogre {
00038 
00039 
00050     class _OgreExport Node : public Renderable
00051     {
00052     public:
00055         enum TransformSpace
00056         {
00058             TS_LOCAL,
00060             TS_PARENT,
00062             TS_WORLD
00063         };
00064         typedef HashMap<String, Node*> ChildNodeMap;
00065         typedef MapIterator<ChildNodeMap> ChildNodeIterator;
00066         typedef ConstMapIterator<ChildNodeMap> ConstChildNodeIterator;
00067 
00070         class _OgreExport Listener
00071         {
00072         public:
00073             Listener() {}
00074             virtual ~Listener() {}
00082             virtual void nodeUpdated(const Node* node) {}
00084             virtual void nodeDestroyed(const Node* node) {};
00086             virtual void nodeAttached(const Node* node) {};
00088             virtual void nodeDetached(const Node* node) {};
00089         };
00090 
00091     protected:
00093         Node* mParent;
00095         ChildNodeMap mChildren;
00096 
00097         typedef std::set<Node*> ChildUpdateSet;
00099         mutable ChildUpdateSet mChildrenToUpdate;
00101         mutable bool mNeedParentUpdate;
00103         mutable bool mNeedChildUpdate;
00105         mutable bool mParentNotified ;
00106 
00108         String mName;
00109 
00111         static unsigned long msNextGeneratedNameExt;
00112 
00114         Quaternion mOrientation;
00115 
00117         Vector3 mPosition;
00118 
00120         Vector3 mScale;
00121 
00123         bool mInheritOrientation;
00124 
00126         bool mInheritScale;
00127 
00129         mutable MaterialPtr mpMaterial;
00130 
00132         virtual void setParent(Node* parent);
00133 
00141         mutable Quaternion mDerivedOrientation;
00142 
00150         mutable Vector3 mDerivedPosition;
00151 
00159         mutable Vector3 mDerivedScale;
00160 
00167         virtual void _updateFromParent(void) const;
00168 
00170         virtual Node* createChildImpl(void) = 0;
00171 
00173         virtual Node* createChildImpl(const String& name) = 0;
00174 
00176         Vector3 mInitialPosition;
00178         Quaternion mInitialOrientation;
00180         Vector3 mInitialScale;
00181 
00182         // Weight of applied animations so far, used for blending
00183         Real mAccumAnimWeight;
00184         // The total weighted translation from the initial state so far
00185         Vector3 mTransFromInitial;
00186         // The total weighted rotation from the initial state so far
00187         Quaternion mRotFromInitial;
00188         // The total weighted scale from the initial state so far
00189         Vector3 mScaleFromInitial;
00190 
00192         mutable Matrix4 mCachedTransform;
00193         mutable bool mCachedTransformOutOfDate;
00194 
00196         Listener* mListener;
00197 
00198         typedef std::vector<Node*> QueuedUpdates;
00199         static QueuedUpdates msQueuedUpdates;
00200 
00201 
00202     public:
00207         Node();
00212         Node(const String& name);
00213 
00214         virtual ~Node();  
00215 
00217         const String& getName(void) const;
00218 
00221         virtual Node* getParent(void) const;
00222 
00225         virtual const Quaternion & getOrientation() const;
00226 
00240         virtual void setOrientation( const Quaternion& q );
00241 
00255         virtual void setOrientation( Real w, Real x, Real y, Real z);
00256 
00270         virtual void resetOrientation(void);
00271 
00274         virtual void setPosition(const Vector3& pos);
00275 
00278         virtual void setPosition(Real x, Real y, Real z);
00279 
00282         virtual const Vector3 & getPosition(void) const;
00283 
00296         virtual void setScale(const Vector3& scale);
00297 
00310         virtual void setScale(Real x, Real y, Real z);
00311 
00314         virtual const Vector3 & getScale(void) const;
00315 
00329         virtual void setInheritOrientation(bool inherit);
00330 
00344         virtual bool getInheritOrientation(void) const;
00345 
00358         virtual void setInheritScale(bool inherit);
00359 
00364         virtual bool getInheritScale(void) const;
00365 
00375         virtual void scale(const Vector3& scale);
00376 
00386         virtual void scale(Real x, Real y, Real z);
00387 
00397         virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT);
00411         virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
00431         virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT);
00451         virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
00452 
00455         virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
00456 #ifndef OGRE_FORCE_ANGLE_TYPES
00457         inline void roll(Real degrees, TransformSpace relativeTo = TS_LOCAL) {
00458             roll ( Angle(degrees), relativeTo );
00459         }
00460 #endif//OGRE_FORCE_ANGLE_TYPES
00461 
00464         virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
00465 #ifndef OGRE_FORCE_ANGLE_TYPES
00466         inline void pitch(Real degrees, TransformSpace relativeTo = TS_LOCAL) {
00467             pitch ( Angle(degrees), relativeTo );
00468         }
00469 #endif//OGRE_FORCE_ANGLE_TYPES
00470 
00473         virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
00474 #ifndef OGRE_FORCE_ANGLE_TYPES
00475         inline void yaw(Real degrees, TransformSpace relativeTo = TS_LOCAL) {
00476             yaw ( Angle(degrees), relativeTo );
00477         }
00478 #endif//OGRE_FORCE_ANGLE_TYPES
00479 
00482         virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
00483 #ifndef OGRE_FORCE_ANGLE_TYPES
00484         inline void rotate(const Vector3& axis, Real degrees, TransformSpace relativeTo = TS_LOCAL) {
00485             rotate ( axis, Angle(degrees), relativeTo );
00486         }
00487 #endif//OGRE_FORCE_ANGLE_TYPES
00488 
00491         virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL);
00492 
00495         virtual Matrix3 getLocalAxes(void) const;
00496 
00503         virtual Node* createChild(
00504             const Vector3& translate = Vector3::ZERO, 
00505             const Quaternion& rotate = Quaternion::IDENTITY );
00506 
00516         virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY);
00517 
00522         virtual void addChild(Node* child);
00523 
00526         virtual unsigned short numChildren(void) const;
00527 
00532         virtual Node* getChild(unsigned short index) const;    
00533 
00536         virtual Node* getChild(const String& name) const;
00537 
00548         virtual ChildNodeIterator getChildIterator(void);
00549 
00560         virtual ConstChildNodeIterator getChildIterator(void) const;
00561 
00569         virtual Node* removeChild(unsigned short index);
00577         virtual Node* removeChild(Node* child);
00578 
00584         virtual Node* removeChild(const String& name);
00588         virtual void removeAllChildren(void);
00589 
00592         virtual const Quaternion & _getDerivedOrientation(void) const;
00593 
00596         virtual const Vector3 & _getDerivedPosition(void) const;
00597 
00600         virtual const Vector3 & _getDerivedScale(void) const;
00601 
00611         virtual Matrix4 _getFullTransform(void) const;
00612 
00625         virtual void _update(bool updateChildren, bool parentHasChanged);
00626 
00632         virtual void setListener(Listener* listener) { mListener = listener; }
00633         
00636         virtual Listener* getListener(void) const { return mListener; }
00637         
00644         const MaterialPtr& getMaterial(void) const;
00651         void getRenderOperation(RenderOperation& op);
00658         void getWorldTransforms(Matrix4* xform) const;
00660         const Quaternion& getWorldOrientation(void) const;
00662         const Vector3& getWorldPosition(void) const;
00663 
00674         virtual void setInitialState(void);
00675 
00677         virtual void resetToInitialState(void);
00678 
00683         virtual const Vector3& getInitialPosition(void) const;
00684 
00686         virtual const Quaternion& getInitialOrientation(void) const;
00687 
00689         virtual const Vector3& getInitialScale(void) const;
00690 
00699         virtual void _weightedTransform(Real weight, const Vector3& translate, 
00700             const Quaternion& rotate, const Vector3& scale);
00701 
00703         Real getSquaredViewDepth(const Camera* cam) const;
00704 
00712         virtual void needUpdate(bool forceParentUpdate = false);
00717         virtual void requestUpdate(Node* child, bool forceParentUpdate = false);
00719         virtual void cancelUpdate(Node* child);
00720 
00728         static void queueNeedUpdate(Node* n);
00730         static void processQueuedUpdates(void);
00731 
00733         const LightList& getLights(void) const;
00734 
00735 
00736 
00737     };
00738 
00739 } //namespace
00740 
00741 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:44 2006