Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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-2006 Torus Knot Software Ltd
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 You may alternatively use this source under the terms of a specific version of
00025 the OGRE Unrestricted License provided you have obtained such a license from
00026 Torus Knot Software Ltd.
00027 -----------------------------------------------------------------------------
00028 */
00029 #ifndef _Node_H__
00030 #define _Node_H__
00031 
00032 #include "OgrePrerequisites.h"
00033 
00034 #include "OgreMatrix3.h"
00035 #include "OgreMatrix4.h"
00036 #include "OgreQuaternion.h"
00037 #include "OgreString.h"
00038 #include "OgreRenderable.h"
00039 #include "OgreIteratorWrappers.h"
00040 
00041 namespace Ogre {
00042 
00043 
00054     class _OgreExport Node : public Renderable
00055     {
00056     public:
00059         enum TransformSpace
00060         {
00062             TS_LOCAL,
00064             TS_PARENT,
00066             TS_WORLD
00067         };
00068         typedef HashMap<String, Node*> ChildNodeMap;
00069         typedef MapIterator<ChildNodeMap> ChildNodeIterator;
00070         typedef ConstMapIterator<ChildNodeMap> ConstChildNodeIterator;
00071 
00074         class _OgreExport Listener
00075         {
00076         public:
00077             Listener() {}
00078             virtual ~Listener() {}
00086             virtual void nodeUpdated(const Node*) {}
00088             virtual void nodeDestroyed(const Node*) {};
00090             virtual void nodeAttached(const Node*) {};
00092             virtual void nodeDetached(const Node*) {};
00093         };
00094 
00095     protected:
00097         Node* mParent;
00099         ChildNodeMap mChildren;
00100 
00101         typedef std::set<Node*> ChildUpdateSet;
00103         mutable ChildUpdateSet mChildrenToUpdate;
00105         mutable bool mNeedParentUpdate;
00107         mutable bool mNeedChildUpdate;
00109         mutable bool mParentNotified ;
00111         mutable bool mQueuedForUpdate;
00112 
00114         String mName;
00115 
00117         static unsigned long msNextGeneratedNameExt;
00118 
00120         Quaternion mOrientation;
00121 
00123         Vector3 mPosition;
00124 
00126         Vector3 mScale;
00127 
00129         bool mInheritOrientation;
00130 
00132         bool mInheritScale;
00133 
00135         mutable MaterialPtr mpMaterial;
00136 
00138         virtual void setParent(Node* parent);
00139 
00147         mutable Quaternion mDerivedOrientation;
00148 
00156         mutable Vector3 mDerivedPosition;
00157 
00165         mutable Vector3 mDerivedScale;
00166 
00173         virtual void _updateFromParent(void) const;
00174 
00176         virtual Node* createChildImpl(void) = 0;
00177 
00179         virtual Node* createChildImpl(const String& name) = 0;
00180 
00182         Vector3 mInitialPosition;
00184         Quaternion mInitialOrientation;
00186         Vector3 mInitialScale;
00187 
00189         mutable Matrix4 mCachedTransform;
00190         mutable bool mCachedTransformOutOfDate;
00191 
00193         Listener* mListener;
00194 
00195         typedef std::vector<Node*> QueuedUpdates;
00196         static QueuedUpdates msQueuedUpdates;
00197 
00198 
00199     public:
00204         Node();
00209         Node(const String& name);
00210 
00211         virtual ~Node();  
00212 
00214         const String& getName(void) const;
00215 
00218         virtual Node* getParent(void) const;
00219 
00222         virtual const Quaternion & getOrientation() const;
00223 
00237         virtual void setOrientation( const Quaternion& q );
00238 
00252         virtual void setOrientation( Real w, Real x, Real y, Real z);
00253 
00267         virtual void resetOrientation(void);
00268 
00271         virtual void setPosition(const Vector3& pos);
00272 
00275         virtual void setPosition(Real x, Real y, Real z);
00276 
00279         virtual const Vector3 & getPosition(void) const;
00280 
00293         virtual void setScale(const Vector3& scale);
00294 
00307         virtual void setScale(Real x, Real y, Real z);
00308 
00311         virtual const Vector3 & getScale(void) const;
00312 
00326         virtual void setInheritOrientation(bool inherit);
00327 
00341         virtual bool getInheritOrientation(void) const;
00342 
00355         virtual void setInheritScale(bool inherit);
00356 
00361         virtual bool getInheritScale(void) const;
00362 
00372         virtual void scale(const Vector3& scale);
00373 
00383         virtual void scale(Real x, Real y, Real z);
00384 
00394         virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT);
00408         virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
00428         virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT);
00448         virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
00449 
00452         virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
00453 #ifndef OGRE_FORCE_ANGLE_TYPES
00454         inline void roll(Real degrees, TransformSpace relativeTo = TS_LOCAL) {
00455             roll ( Angle(degrees), relativeTo );
00456         }
00457 #endif//OGRE_FORCE_ANGLE_TYPES
00458 
00461         virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
00462 #ifndef OGRE_FORCE_ANGLE_TYPES
00463         inline void pitch(Real degrees, TransformSpace relativeTo = TS_LOCAL) {
00464             pitch ( Angle(degrees), relativeTo );
00465         }
00466 #endif//OGRE_FORCE_ANGLE_TYPES
00467 
00470         virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
00471 #ifndef OGRE_FORCE_ANGLE_TYPES
00472         inline void yaw(Real degrees, TransformSpace relativeTo = TS_LOCAL) {
00473             yaw ( Angle(degrees), relativeTo );
00474         }
00475 #endif//OGRE_FORCE_ANGLE_TYPES
00476 
00479         virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
00480 #ifndef OGRE_FORCE_ANGLE_TYPES
00481         inline void rotate(const Vector3& axis, Real degrees, TransformSpace relativeTo = TS_LOCAL) {
00482             rotate ( axis, Angle(degrees), relativeTo );
00483         }
00484 #endif//OGRE_FORCE_ANGLE_TYPES
00485 
00488         virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL);
00489 
00492         virtual Matrix3 getLocalAxes(void) const;
00493 
00500         virtual Node* createChild(
00501             const Vector3& translate = Vector3::ZERO, 
00502             const Quaternion& rotate = Quaternion::IDENTITY );
00503 
00513         virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY);
00514 
00519         virtual void addChild(Node* child);
00520 
00523         virtual unsigned short numChildren(void) const;
00524 
00529         virtual Node* getChild(unsigned short index) const;    
00530 
00533         virtual Node* getChild(const String& name) const;
00534 
00545         virtual ChildNodeIterator getChildIterator(void);
00546 
00557         virtual ConstChildNodeIterator getChildIterator(void) const;
00558 
00566         virtual Node* removeChild(unsigned short index);
00574         virtual Node* removeChild(Node* child);
00575 
00581         virtual Node* removeChild(const String& name);
00585         virtual void removeAllChildren(void);
00586 
00589         virtual const Quaternion & _getDerivedOrientation(void) const;
00590 
00593         virtual const Vector3 & _getDerivedPosition(void) const;
00594 
00597         virtual const Vector3 & _getDerivedScale(void) const;
00598 
00608         virtual const Matrix4& _getFullTransform(void) const;
00609 
00622         virtual void _update(bool updateChildren, bool parentHasChanged);
00623 
00629         virtual void setListener(Listener* listener) { mListener = listener; }
00630         
00633         virtual Listener* getListener(void) const { return mListener; }
00634         
00641         const MaterialPtr& getMaterial(void) const;
00648         void getRenderOperation(RenderOperation& op);
00655         void getWorldTransforms(Matrix4* xform) const;
00657         const Quaternion& getWorldOrientation(void) const;
00659         const Vector3& getWorldPosition(void) const;
00660 
00671         virtual void setInitialState(void);
00672 
00674         virtual void resetToInitialState(void);
00675 
00680         virtual const Vector3& getInitialPosition(void) const;
00681 
00683         virtual const Quaternion& getInitialOrientation(void) const;
00684 
00686         virtual const Vector3& getInitialScale(void) const;
00687 
00689         Real getSquaredViewDepth(const Camera* cam) const;
00690 
00698         virtual void needUpdate(bool forceParentUpdate = false);
00703         virtual void requestUpdate(Node* child, bool forceParentUpdate = false);
00705         virtual void cancelUpdate(Node* child);
00706 
00714         static void queueNeedUpdate(Node* n);
00716         static void processQueuedUpdates(void);
00717 
00719         const LightList& getLights(void) const;
00720 
00721 
00722 
00723     };
00724 
00725 } //namespace
00726 
00727 #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 25 13:03:15 2007