OGRE: OgreNode.h Source File - OGRE Documentation

# 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-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef _Node_H__
    00029 #define _Node_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032
    00033 #include "OgreCommon.h"
    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 #include "OgreMesh.h"
    00041 #include "OgreUserObjectBindings.h"
    00042
    00043 namespace Ogre {
    00044
    00045
    00062     class _OgreExport Node : public NodeAlloc
    00063     {
    00064     public:
    00067         enum TransformSpace
    00068         {
    00070             TS_LOCAL,
    00072             TS_PARENT,
    00074             TS_WORLD
    00075         };
    00076         typedef HashMap<String, Node*> ChildNodeMap;
    00077         typedef MapIterator<ChildNodeMap> ChildNodeIterator;
    00078         typedef ConstMapIterator<ChildNodeMap> ConstChildNodeIterator;
    00079
    00082         class _OgreExport Listener
    00083         {
    00084         public:
    00085             Listener() {}
    00086             virtual ~Listener() {}
    00094             virtual void nodeUpdated(const Node*) {}
    00096             virtual void nodeDestroyed(const Node*) {}
    00098             virtual void nodeAttached(const Node*) {}
    00100             virtual void nodeDetached(const Node*) {}
    00101         };
    00102
    00104         class DebugRenderable : public Renderable, public NodeAlloc
    00105         {
    00106         protected:
    00107             Node* mParent;
    00108             MeshPtr mMeshPtr;
    00109             MaterialPtr mMat;
    00110             Real mScaling;
    00111         public:
    00112             DebugRenderable(Node* parent);
    00113             ~DebugRenderable();
    00114             const MaterialPtr& getMaterial(void) const;
    00115             void getRenderOperation(RenderOperation& op);
    00116             void getWorldTransforms(Matrix4* xform) const;
    00117             Real getSquaredViewDepth(const Camera* cam) const;
    00118             const LightList& getLights(void) const;
    00119             void setScaling(Real s) { mScaling = s; }
    00120
    00121         };
    00122
    00123     protected:
    00125         Node* mParent;
    00127         ChildNodeMap mChildren;
    00128
    00129         typedef set<Node*>::type ChildUpdateSet;
    00131         mutable ChildUpdateSet mChildrenToUpdate;
    00133         mutable bool mNeedParentUpdate;
    00135         mutable bool mNeedChildUpdate;
    00137         mutable bool mParentNotified ;
    00139         mutable bool mQueuedForUpdate;
    00140
    00142         String mName;
    00143
    00145         static NameGenerator msNameGenerator;
    00146
    00148         Quaternion mOrientation;
    00149
    00151         Vector3 mPosition;
    00152
    00154         Vector3 mScale;
    00155
    00157         bool mInheritOrientation;
    00158
    00160         bool mInheritScale;
    00161
    00163         virtual void setParent(Node* parent);
    00164
    00172         mutable Quaternion mDerivedOrientation;
    00173
    00181         mutable Vector3 mDerivedPosition;
    00182
    00190         mutable Vector3 mDerivedScale;
    00191
    00198         virtual void _updateFromParent(void) const;
    00199
    00206         virtual void updateFromParentImpl(void) const;
    00207
    00208
    00210         virtual Node* createChildImpl(void) = 0;
    00211
    00213         virtual Node* createChildImpl(const String& name) = 0;
    00214
    00216         Vector3 mInitialPosition;
    00218         Quaternion mInitialOrientation;
    00220         Vector3 mInitialScale;
    00221
    00223         mutable Matrix4 mCachedTransform;
    00224         mutable bool mCachedTransformOutOfDate;
    00225
    00227         Listener* mListener;
    00228
    00229         typedef vector<Node*>::type QueuedUpdates;
    00230         static QueuedUpdates msQueuedUpdates;
    00231
    00232         DebugRenderable* mDebug;
    00233
    00235         UserObjectBindings mUserObjectBindings;
    00236
    00237     public:
    00242         Node();
    00247         Node(const String& name);
    00248
    00249         virtual ~Node();
    00250
    00252         const String& getName(void) const;
    00253
    00256         virtual Node* getParent(void) const;
    00257
    00260         virtual const Quaternion & getOrientation() const;
    00261
    00275         virtual void setOrientation( const Quaternion& q );
    00276
    00290         virtual void setOrientation( Real w, Real x, Real y, Real z);
    00291
    00305         virtual void resetOrientation(void);
    00306
    00309         virtual void setPosition(const Vector3& pos);
    00310
    00313         virtual void setPosition(Real x, Real y, Real z);
    00314
    00317         virtual const Vector3 & getPosition(void) const;
    00318
    00331         virtual void setScale(const Vector3& scale);
    00332
    00345         virtual void setScale(Real x, Real y, Real z);
    00346
    00349         virtual const Vector3 & getScale(void) const;
    00350
    00364         virtual void setInheritOrientation(bool inherit);
    00365
    00379         virtual bool getInheritOrientation(void) const;
    00380
    00393         virtual void setInheritScale(bool inherit);
    00394
    00399         virtual bool getInheritScale(void) const;
    00400
    00410         virtual void scale(const Vector3& scale);
    00411
    00421         virtual void scale(Real x, Real y, Real z);
    00422
    00432         virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT);
    00446         virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
    00466         virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT);
    00486         virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT);
    00487
    00490         virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
    00491
    00494         virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
    00495
    00498         virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
    00499
    00502         virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
    00503
    00506         virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL);
    00507
    00510         virtual Matrix3 getLocalAxes(void) const;
    00511
    00518         virtual Node* createChild(
    00519             const Vector3& translate = Vector3::ZERO,
    00520             const Quaternion& rotate = Quaternion::IDENTITY );
    00521
    00531         virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY);
    00532
    00537         virtual void addChild(Node* child);
    00538
    00541         virtual unsigned short numChildren(void) const;
    00542
    00547         virtual Node* getChild(unsigned short index) const;
    00548
    00551         virtual Node* getChild(const String& name) const;
    00552
    00563         virtual ChildNodeIterator getChildIterator(void);
    00564
    00575         virtual ConstChildNodeIterator getChildIterator(void) const;
    00576
    00584         virtual Node* removeChild(unsigned short index);
    00592         virtual Node* removeChild(Node* child);
    00593
    00599         virtual Node* removeChild(const String& name);
    00603         virtual void removeAllChildren(void);
    00604
    00609         virtual void _setDerivedPosition(const Vector3& pos);
    00610
    00616         virtual void _setDerivedOrientation(const Quaternion& q);
    00617
    00620         virtual const Quaternion & _getDerivedOrientation(void) const;
    00621
    00624         virtual const Vector3 & _getDerivedPosition(void) const;
    00625
    00628         virtual const Vector3 & _getDerivedScale(void) const;
    00629
    00639         virtual const Matrix4& _getFullTransform(void) const;
    00640
    00653         virtual void _update(bool updateChildren, bool parentHasChanged);
    00654
    00660         virtual void setListener(Listener* listener) { mListener = listener; }
    00661
    00664         virtual Listener* getListener(void) const { return mListener; }
    00665
    00666
    00677         virtual void setInitialState(void);
    00678
    00680         virtual void resetToInitialState(void);
    00681
    00686         virtual const Vector3& getInitialPosition(void) const;
    00687
    00689         virtual Vector3 convertWorldToLocalPosition( const Vector3 &worldPos );
    00690
    00693         virtual Vector3 convertLocalToWorldPosition( const Vector3 &localPos );
    00694
    00696         virtual Quaternion convertWorldToLocalOrientation( const Quaternion &worldOrientation );
    00697
    00700         virtual Quaternion convertLocalToWorldOrientation( const Quaternion &localOrientation );
    00701
    00703         virtual const Quaternion& getInitialOrientation(void) const;
    00704
    00706         virtual const Vector3& getInitialScale(void) const;
    00707
    00709         Real getSquaredViewDepth(const Camera* cam) const;
    00710
    00718         virtual void needUpdate(bool forceParentUpdate = false);
    00723         virtual void requestUpdate(Node* child, bool forceParentUpdate = false);
    00725         virtual void cancelUpdate(Node* child);
    00726
    00728         virtual DebugRenderable* getDebugRenderable(Real scaling);
    00729
    00737         static void queueNeedUpdate(Node* n);
    00739         static void processQueuedUpdates(void);
    00740
    00741
    00749         virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
    00750
    00754         virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
    00755
    00760         UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
    00761
    00766         const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
    00767
    00768     };
    00772 } //namespace
    00773
    00774 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52