# 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, public NodeAlloc
    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
    00181         virtual void updateFromParentImpl(void) const;
    00182
    00183
    00185         virtual Node* createChildImpl(void) = 0;
    00186
    00188         virtual Node* createChildImpl(const String& name) = 0;
    00189
    00191         Vector3 mInitialPosition;
    00193         Quaternion mInitialOrientation;
    00195         Vector3 mInitialScale;
    00196
    00198         mutable Matrix4 mCachedTransform;
    00199         mutable bool mCachedTransformOutOfDate;
    00200
    00202         Listener* mListener;
    00203
    00204         typedef std::vector<Node*> QueuedUpdates;
    00205         static QueuedUpdates msQueuedUpdates;
    00206
    00207
    00208     public:
    00213         Node();
    00218         Node(const String& name);
    00219
    00220         virtual ~Node();
    00221
    00223         const String& getName(void) const;
    00224
    00227         virtual Node* getParent(void) const;
    00228
    00231         virtual const Quaternion & getOrientation() const;
    00232
    00246         virtual void setOrientation( const Quaternion& q );
    00247
    00261         virtual void setOrientation( Real w, Real x, Real y, Real z);
    00262
    00276         virtual void resetOrientation(void);
    00277
    00280         virtual void setPosition(const Vector3& pos);
    00281
    00284         virtual void setPosition(Real x, Real y, Real z);
    00285
    00288         virtual const Vector3 & getPosition(void) const;
    00289
    00302         virtual void setScale(const Vector3& scale);
    00303
    00316         virtual void setScale(Real x, Real y, Real z);
    00317
    00320         virtual const Vector3 & getScale(void) const;
    00321
    00335         virtual void setInheritOrientation(bool inherit);
    00336
    00350         virtual bool getInheritOrientation(void) const;
    00351
    00364         virtual void setInheritScale(bool inherit);
    00365
    00370         virtual bool getInheritScale(void) const;
    00371
    00381         virtual void scale(const Vector3& scale);
    00382
    00392         virtual void scale(Real x, Real y, Real z);
    00393
    00403         virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT);
    00417         virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
    00437         virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT);
    00457         virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
    00458
    00461         virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
    00462
    00465         virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
    00466
    00469         virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
    00470
    00473         virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
    00474
    00477         virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL);
    00478
    00481         virtual Matrix3 getLocalAxes(void) const;
    00482
    00489         virtual Node* createChild(
    00490             const Vector3& translate = Vector3::ZERO,
    00491             const Quaternion& rotate = Quaternion::IDENTITY );
    00492
    00502         virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY);
    00503
    00508         virtual void addChild(Node* child);
    00509
    00512         virtual unsigned short numChildren(void) const;
    00513
    00518         virtual Node* getChild(unsigned short index) const;
    00519
    00522         virtual Node* getChild(const String& name) const;
    00523
    00534         virtual ChildNodeIterator getChildIterator(void);
    00535
    00546         virtual ConstChildNodeIterator getChildIterator(void) const;
    00547
    00555         virtual Node* removeChild(unsigned short index);
    00563         virtual Node* removeChild(Node* child);
    00564
    00570         virtual Node* removeChild(const String& name);
    00574         virtual void removeAllChildren(void);
    00575
    00578         virtual const Quaternion & _getDerivedOrientation(void) const;
    00579
    00582         virtual const Vector3 & _getDerivedPosition(void) const;
    00583
    00586         virtual const Vector3 & _getDerivedScale(void) const;
    00587
    00597         virtual const Matrix4& _getFullTransform(void) const;
    00598
    00611         virtual void _update(bool updateChildren, bool parentHasChanged);
    00612
    00618         virtual void setListener(Listener* listener) { mListener = listener; }
    00619
    00622         virtual Listener* getListener(void) const { return mListener; }
    00623
    00630         const MaterialPtr& getMaterial(void) const;
    00637         void getRenderOperation(RenderOperation& op);
    00644         void getWorldTransforms(Matrix4* xform) const;
    00645
    00656         virtual void setInitialState(void);
    00657
    00659         virtual void resetToInitialState(void);
    00660
    00665         virtual const Vector3& getInitialPosition(void) const;
    00666
    00668         virtual const Quaternion& getInitialOrientation(void) const;
    00669
    00671         virtual const Vector3& getInitialScale(void) const;
    00672
    00674         Real getSquaredViewDepth(const Camera* cam) const;
    00675
    00683         virtual void needUpdate(bool forceParentUpdate = false);
    00688         virtual void requestUpdate(Node* child, bool forceParentUpdate = false);
    00690         virtual void cancelUpdate(Node* child);
    00691
    00699         static void queueNeedUpdate(Node* n);
    00701         static void processQueuedUpdates(void);
    00702
    00704         const LightList& getLights(void) const;
    00705
    00706
    00707
    00708     };
    00709
    00710 } //namespace
    00711
    00712 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 13:46:41 2009