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 ; 00107 mutable bool mQueuedForUpdate; 00108 00110 String mName; 00111 00113 static unsigned long msNextGeneratedNameExt; 00114 00116 Quaternion mOrientation; 00117 00119 Vector3 mPosition; 00120 00122 Vector3 mScale; 00123 00125 bool mInheritOrientation; 00126 00128 bool mInheritScale; 00129 00131 mutable MaterialPtr mpMaterial; 00132 00134 virtual void setParent(Node* parent); 00135 00143 mutable Quaternion mDerivedOrientation; 00144 00152 mutable Vector3 mDerivedPosition; 00153 00161 mutable Vector3 mDerivedScale; 00162 00169 virtual void _updateFromParent(void) const; 00170 00172 virtual Node* createChildImpl(void) = 0; 00173 00175 virtual Node* createChildImpl(const String& name) = 0; 00176 00178 Vector3 mInitialPosition; 00180 Quaternion mInitialOrientation; 00182 Vector3 mInitialScale; 00183 00184 // Weight of applied animations so far, used for blending 00185 Real mAccumAnimWeight; 00186 // The total weighted translation from the initial state so far 00187 Vector3 mTransFromInitial; 00188 // The total weighted rotation from the initial state so far 00189 Quaternion mRotFromInitial; 00190 // The total weighted scale from the initial state so far 00191 Vector3 mScaleFromInitial; 00192 00194 mutable Matrix4 mCachedTransform; 00195 mutable bool mCachedTransformOutOfDate; 00196 00198 Listener* mListener; 00199 00200 typedef std::vector<Node*> QueuedUpdates; 00201 static QueuedUpdates msQueuedUpdates; 00202 00203 00204 public: 00209 Node(); 00214 Node(const String& name); 00215 00216 virtual ~Node(); 00217 00219 const String& getName(void) const; 00220 00223 virtual Node* getParent(void) const; 00224 00227 virtual const Quaternion & getOrientation() const; 00228 00242 virtual void setOrientation( const Quaternion& q ); 00243 00257 virtual void setOrientation( Real w, Real x, Real y, Real z); 00258 00272 virtual void resetOrientation(void); 00273 00276 virtual void setPosition(const Vector3& pos); 00277 00280 virtual void setPosition(Real x, Real y, Real z); 00281 00284 virtual const Vector3 & getPosition(void) const; 00285 00298 virtual void setScale(const Vector3& scale); 00299 00312 virtual void setScale(Real x, Real y, Real z); 00313 00316 virtual const Vector3 & getScale(void) const; 00317 00331 virtual void setInheritOrientation(bool inherit); 00332 00346 virtual bool getInheritOrientation(void) const; 00347 00360 virtual void setInheritScale(bool inherit); 00361 00366 virtual bool getInheritScale(void) const; 00367 00377 virtual void scale(const Vector3& scale); 00378 00388 virtual void scale(Real x, Real y, Real z); 00389 00399 virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT); 00413 virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT); 00433 virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT); 00453 virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT); 00454 00457 virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00458 #ifndef OGRE_FORCE_ANGLE_TYPES 00459 inline void roll(Real degrees, TransformSpace relativeTo = TS_LOCAL) { 00460 roll ( Angle(degrees), relativeTo ); 00461 } 00462 #endif//OGRE_FORCE_ANGLE_TYPES 00463 00466 virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00467 #ifndef OGRE_FORCE_ANGLE_TYPES 00468 inline void pitch(Real degrees, TransformSpace relativeTo = TS_LOCAL) { 00469 pitch ( Angle(degrees), relativeTo ); 00470 } 00471 #endif//OGRE_FORCE_ANGLE_TYPES 00472 00475 virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00476 #ifndef OGRE_FORCE_ANGLE_TYPES 00477 inline void yaw(Real degrees, TransformSpace relativeTo = TS_LOCAL) { 00478 yaw ( Angle(degrees), relativeTo ); 00479 } 00480 #endif//OGRE_FORCE_ANGLE_TYPES 00481 00484 virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00485 #ifndef OGRE_FORCE_ANGLE_TYPES 00486 inline void rotate(const Vector3& axis, Real degrees, TransformSpace relativeTo = TS_LOCAL) { 00487 rotate ( axis, Angle(degrees), relativeTo ); 00488 } 00489 #endif//OGRE_FORCE_ANGLE_TYPES 00490 00493 virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL); 00494 00497 virtual Matrix3 getLocalAxes(void) const; 00498 00505 virtual Node* createChild( 00506 const Vector3& translate = Vector3::ZERO, 00507 const Quaternion& rotate = Quaternion::IDENTITY ); 00508 00518 virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY); 00519 00524 virtual void addChild(Node* child); 00525 00528 virtual unsigned short numChildren(void) const; 00529 00534 virtual Node* getChild(unsigned short index) const; 00535 00538 virtual Node* getChild(const String& name) const; 00539 00550 virtual ChildNodeIterator getChildIterator(void); 00551 00562 virtual ConstChildNodeIterator getChildIterator(void) const; 00563 00571 virtual Node* removeChild(unsigned short index); 00579 virtual Node* removeChild(Node* child); 00580 00586 virtual Node* removeChild(const String& name); 00590 virtual void removeAllChildren(void); 00591 00594 virtual const Quaternion & _getDerivedOrientation(void) const; 00595 00598 virtual const Vector3 & _getDerivedPosition(void) const; 00599 00602 virtual const Vector3 & _getDerivedScale(void) const; 00603 00613 virtual const Matrix4& _getFullTransform(void) const; 00614 00627 virtual void _update(bool updateChildren, bool parentHasChanged); 00628 00634 virtual void setListener(Listener* listener) { mListener = listener; } 00635 00638 virtual Listener* getListener(void) const { return mListener; } 00639 00646 const MaterialPtr& getMaterial(void) const; 00653 void getRenderOperation(RenderOperation& op); 00660 void getWorldTransforms(Matrix4* xform) const; 00662 const Quaternion& getWorldOrientation(void) const; 00664 const Vector3& getWorldPosition(void) const; 00665 00676 virtual void setInitialState(void); 00677 00679 virtual void resetToInitialState(void); 00680 00685 virtual const Vector3& getInitialPosition(void) const; 00686 00688 virtual const Quaternion& getInitialOrientation(void) const; 00689 00691 virtual const Vector3& getInitialScale(void) const; 00692 00701 virtual void _weightedTransform(Real weight, const Vector3& translate, 00702 const Quaternion& rotate, const Vector3& scale); 00703 00705 Real getSquaredViewDepth(const Camera* cam) const; 00706 00714 virtual void needUpdate(bool forceParentUpdate = false); 00719 virtual void requestUpdate(Node* child, bool forceParentUpdate = false); 00721 virtual void cancelUpdate(Node* child); 00722 00730 static void queueNeedUpdate(Node* n); 00732 static void processQueuedUpdates(void); 00733 00735 const LightList& getLights(void) const; 00736 00737 00738 00739 }; 00740 00741 } //namespace 00742 00743 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Nov 12 10:50:12 2006