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-2013 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 #include "OgreHeaderPrefix.h" 00043 00044 namespace Ogre { 00045 00046 class NameGenerator; 00047 00064 class _OgreExport Node : public NodeAlloc 00065 { 00066 public: 00069 enum TransformSpace 00070 { 00072 TS_LOCAL, 00074 TS_PARENT, 00076 TS_WORLD 00077 }; 00078 typedef HashMap<String, Node*> ChildNodeMap; 00079 typedef MapIterator<ChildNodeMap> ChildNodeIterator; 00080 typedef ConstMapIterator<ChildNodeMap> ConstChildNodeIterator; 00081 00084 class _OgreExport Listener 00085 { 00086 public: 00087 Listener() {} 00088 virtual ~Listener() {} 00096 virtual void nodeUpdated(const Node*) {} 00098 virtual void nodeDestroyed(const Node*) {} 00100 virtual void nodeAttached(const Node*) {} 00102 virtual void nodeDetached(const Node*) {} 00103 }; 00104 00106 class DebugRenderable : public Renderable, public NodeAlloc 00107 { 00108 protected: 00109 Node* mParent; 00110 MeshPtr mMeshPtr; 00111 MaterialPtr mMat; 00112 Real mScaling; 00113 public: 00114 DebugRenderable(Node* parent); 00115 ~DebugRenderable(); 00116 const MaterialPtr& getMaterial(void) const; 00117 void getRenderOperation(RenderOperation& op); 00118 void getWorldTransforms(Matrix4* xform) const; 00119 Real getSquaredViewDepth(const Camera* cam) const; 00120 const LightList& getLights(void) const; 00121 void setScaling(Real s) { mScaling = s; } 00122 00123 }; 00124 00125 protected: 00127 Node* mParent; 00129 ChildNodeMap mChildren; 00130 00131 typedef set<Node*>::type ChildUpdateSet; 00133 mutable ChildUpdateSet mChildrenToUpdate; 00135 mutable bool mNeedParentUpdate; 00137 mutable bool mNeedChildUpdate; 00139 mutable bool mParentNotified ; 00141 mutable bool mQueuedForUpdate; 00142 00144 String mName; 00145 00147 static NameGenerator msNameGenerator; 00148 00150 Quaternion mOrientation; 00151 00153 Vector3 mPosition; 00154 00156 Vector3 mScale; 00157 00159 bool mInheritOrientation; 00160 00162 bool mInheritScale; 00163 00165 virtual void setParent(Node* parent); 00166 00174 mutable Quaternion mDerivedOrientation; 00175 00183 mutable Vector3 mDerivedPosition; 00184 00192 mutable Vector3 mDerivedScale; 00193 00200 virtual void _updateFromParent(void) const; 00201 00208 virtual void updateFromParentImpl(void) const; 00209 00210 00212 virtual Node* createChildImpl(void) = 0; 00213 00215 virtual Node* createChildImpl(const String& name) = 0; 00216 00218 Vector3 mInitialPosition; 00220 Quaternion mInitialOrientation; 00222 Vector3 mInitialScale; 00223 00225 mutable Matrix4 mCachedTransform; 00226 mutable bool mCachedTransformOutOfDate; 00227 00229 Listener* mListener; 00230 00231 typedef vector<Node*>::type QueuedUpdates; 00232 static QueuedUpdates msQueuedUpdates; 00233 00234 DebugRenderable* mDebug; 00235 00237 UserObjectBindings mUserObjectBindings; 00238 00239 public: 00244 Node(); 00249 Node(const String& name); 00250 00251 virtual ~Node(); 00252 00254 const String& getName(void) const; 00255 00258 virtual Node* getParent(void) const; 00259 00262 virtual const Quaternion & getOrientation() const; 00263 00277 virtual void setOrientation( const Quaternion& q ); 00278 00292 virtual void setOrientation( Real w, Real x, Real y, Real z); 00293 00307 virtual void resetOrientation(void); 00308 00311 virtual void setPosition(const Vector3& pos); 00312 00315 virtual void setPosition(Real x, Real y, Real z); 00316 00319 virtual const Vector3 & getPosition(void) const; 00320 00333 virtual void setScale(const Vector3& scale); 00334 00347 virtual void setScale(Real x, Real y, Real z); 00348 00351 virtual const Vector3 & getScale(void) const; 00352 00366 virtual void setInheritOrientation(bool inherit); 00367 00381 virtual bool getInheritOrientation(void) const; 00382 00395 virtual void setInheritScale(bool inherit); 00396 00401 virtual bool getInheritScale(void) const; 00402 00412 virtual void scale(const Vector3& scale); 00413 00423 virtual void scale(Real x, Real y, Real z); 00424 00434 virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT); 00448 virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT); 00468 virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT); 00492 virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT); 00493 00496 virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00497 00500 virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00501 00504 virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00505 00508 virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00509 00512 virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL); 00513 00516 virtual Matrix3 getLocalAxes(void) const; 00517 00524 virtual Node* createChild( 00525 const Vector3& translate = Vector3::ZERO, 00526 const Quaternion& rotate = Quaternion::IDENTITY ); 00527 00537 virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY); 00538 00543 virtual void addChild(Node* child); 00544 00547 virtual unsigned short numChildren(void) const; 00548 00553 virtual Node* getChild(unsigned short index) const; 00554 00557 virtual Node* getChild(const String& name) const; 00558 00569 virtual ChildNodeIterator getChildIterator(void); 00570 00581 virtual ConstChildNodeIterator getChildIterator(void) const; 00582 00590 virtual Node* removeChild(unsigned short index); 00598 virtual Node* removeChild(Node* child); 00599 00605 virtual Node* removeChild(const String& name); 00609 virtual void removeAllChildren(void); 00610 00615 virtual void _setDerivedPosition(const Vector3& pos); 00616 00622 virtual void _setDerivedOrientation(const Quaternion& q); 00623 00626 virtual const Quaternion & _getDerivedOrientation(void) const; 00627 00630 virtual const Vector3 & _getDerivedPosition(void) const; 00631 00634 virtual const Vector3 & _getDerivedScale(void) const; 00635 00645 virtual const Matrix4& _getFullTransform(void) const; 00646 00659 virtual void _update(bool updateChildren, bool parentHasChanged); 00660 00666 virtual void setListener(Listener* listener) { mListener = listener; } 00667 00670 virtual Listener* getListener(void) const { return mListener; } 00671 00672 00683 virtual void setInitialState(void); 00684 00686 virtual void resetToInitialState(void); 00687 00692 virtual const Vector3& getInitialPosition(void) const; 00693 00695 virtual Vector3 convertWorldToLocalPosition( const Vector3 &worldPos ); 00696 00699 virtual Vector3 convertLocalToWorldPosition( const Vector3 &localPos ); 00700 00702 virtual Quaternion convertWorldToLocalOrientation( const Quaternion &worldOrientation ); 00703 00706 virtual Quaternion convertLocalToWorldOrientation( const Quaternion &localOrientation ); 00707 00709 virtual const Quaternion& getInitialOrientation(void) const; 00710 00712 virtual const Vector3& getInitialScale(void) const; 00713 00715 virtual Real getSquaredViewDepth(const Camera* cam) const; 00716 00724 virtual void needUpdate(bool forceParentUpdate = false); 00729 virtual void requestUpdate(Node* child, bool forceParentUpdate = false); 00731 virtual void cancelUpdate(Node* child); 00732 00734 virtual DebugRenderable* getDebugRenderable(Real scaling); 00735 00743 static void queueNeedUpdate(Node* n); 00745 static void processQueuedUpdates(void); 00746 00747 00755 OGRE_DEPRECATED virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); } 00756 00760 OGRE_DEPRECATED virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); } 00761 00766 UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; } 00767 00772 const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; } 00773 00774 }; 00778 } // namespace Ogre 00779 00780 #include "OgreHeaderSuffix.h" 00781 00782 #endif // _Node_H__
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:44