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 © 2000-2002 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 00067 protected: 00069 Node* mParent; 00071 ChildNodeMap mChildren; 00072 00073 typedef std::set<Node*> ChildUpdateSet; 00075 mutable ChildUpdateSet mChildrenToUpdate; 00077 mutable bool mNeedParentUpdate; 00079 mutable bool mNeedChildUpdate; 00081 mutable bool mParentNotified ; 00082 00084 String mName; 00085 00087 static unsigned long msNextGeneratedNameExt; 00088 00090 Quaternion mOrientation; 00091 00093 Vector3 mPosition; 00094 00096 Vector3 mScale; 00097 00099 bool mInheritScale; 00100 00102 void setParent(Node* parent); 00103 00111 mutable Quaternion mDerivedOrientation; 00112 00120 mutable Vector3 mDerivedPosition; 00121 00129 mutable Vector3 mDerivedScale; 00130 00137 virtual void _updateFromParent(void) const; 00138 00140 virtual Node* createChildImpl(void) = 0; 00141 00143 virtual Node* createChildImpl(const String& name) = 0; 00144 00151 void makeTransform( 00152 const Vector3& position, 00153 const Vector3& scale, 00154 const Quaternion& orientation, 00155 Matrix4& destMatrix ) const; 00156 00162 void makeInverseTransform( 00163 const Vector3& position, 00164 const Vector3& scale, 00165 const Quaternion& orientation, 00166 Matrix4& destMatrix ); 00167 00169 Vector3 mInitialPosition; 00171 Quaternion mInitialOrientation; 00173 Vector3 mInitialScale; 00174 00175 // Weight of applied animations so far, used for blending 00176 Real mAccumAnimWeight; 00177 // The total weighted translation from the initial state so far 00178 Vector3 mTransFromInitial; 00179 // The total weighted rotation from the initial state so far 00180 Quaternion mRotFromInitial; 00181 // The total weighted scale from the initial state so far 00182 Vector3 mScaleFromInitial; 00183 00185 mutable Matrix4 mCachedTransform; 00186 mutable bool mCachedTransformOutOfDate; 00187 00188 00189 public: 00194 Node(); 00199 Node(const String& name); 00200 00201 virtual ~Node(); 00202 00204 const String& getName(void) const; 00205 00208 virtual Node* getParent(void) const; 00209 00212 virtual const Quaternion & getOrientation() const; 00213 00216 virtual void setOrientation( const Quaternion& q ); 00217 00220 virtual void setOrientation( Real w, Real x, Real y, Real z); 00221 00224 virtual void resetOrientation(void); 00225 00228 virtual void setPosition(const Vector3& pos); 00229 00232 virtual void setPosition(Real x, Real y, Real z); 00233 00236 virtual const Vector3 & getPosition(void) const; 00237 00251 virtual void setScale(const Vector3& scale); 00252 00266 virtual void setScale(Real x, Real y, Real z); 00267 00270 virtual const Vector3 & getScale(void) const; 00271 00285 virtual void setInheritScale(bool inherit); 00286 00291 virtual bool getInheritScale(void) const; 00292 00302 virtual void scale(const Vector3& scale); 00303 00313 virtual void scale(Real x, Real y, Real z); 00314 00324 virtual void translate(const Vector3& d, TransformSpace relativeTo = TS_PARENT); 00338 virtual void translate(Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT); 00358 virtual void translate(const Matrix3& axes, const Vector3& move, TransformSpace relativeTo = TS_PARENT); 00378 virtual void translate(const Matrix3& axes, Real x, Real y, Real z, TransformSpace relativeTo = TS_PARENT); 00379 00382 virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00383 #ifndef OGRE_FORCE_ANGLE_TYPES 00384 inline void roll(Real degrees, TransformSpace relativeTo = TS_LOCAL) { 00385 roll ( Angle(degrees), relativeTo ); 00386 } 00387 #endif//OGRE_FORCE_ANGLE_TYPES 00388 00391 virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00392 #ifndef OGRE_FORCE_ANGLE_TYPES 00393 inline void pitch(Real degrees, TransformSpace relativeTo = TS_LOCAL) { 00394 pitch ( Angle(degrees), relativeTo ); 00395 } 00396 #endif//OGRE_FORCE_ANGLE_TYPES 00397 00400 virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00401 #ifndef OGRE_FORCE_ANGLE_TYPES 00402 inline void yaw(Real degrees, TransformSpace relativeTo = TS_LOCAL) { 00403 yaw ( Angle(degrees), relativeTo ); 00404 } 00405 #endif//OGRE_FORCE_ANGLE_TYPES 00406 00409 virtual void rotate(const Vector3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL); 00410 #ifndef OGRE_FORCE_ANGLE_TYPES 00411 inline void rotate(const Vector3& axis, Real degrees, TransformSpace relativeTo = TS_LOCAL) { 00412 rotate ( axis, Angle(degrees), relativeTo ); 00413 } 00414 #endif//OGRE_FORCE_ANGLE_TYPES 00415 00418 virtual void rotate(const Quaternion& q, TransformSpace relativeTo = TS_LOCAL); 00419 00422 virtual Matrix3 getLocalAxes(void) const; 00423 00430 virtual Node* createChild( 00431 const Vector3& translate = Vector3::ZERO, 00432 const Quaternion& rotate = Quaternion::IDENTITY ); 00433 00443 virtual Node* createChild(const String& name, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY); 00444 00448 virtual void addChild(Node* child); 00449 00452 virtual unsigned short numChildren(void) const; 00453 00458 virtual Node* getChild(unsigned short index) const; 00459 00462 virtual Node* getChild(const String& name) const; 00463 00474 virtual ChildNodeIterator getChildIterator(void); 00475 00483 virtual Node* removeChild(unsigned short index); 00491 virtual Node* removeChild(Node* child); 00492 00498 virtual Node* removeChild(const String& name); 00502 virtual void removeAllChildren(void); 00503 00506 virtual const Quaternion & _getDerivedOrientation(void) const; 00507 00510 virtual const Vector3 & _getDerivedPosition(void) const; 00511 00514 virtual const Vector3 & _getDerivedScale(void) const; 00515 00525 virtual Matrix4 _getFullTransform(void) const; 00526 00539 virtual void _update(bool updateChildren, bool parentHasChanged); 00540 00547 Material* getMaterial(void) const; 00554 void getRenderOperation(RenderOperation& op); 00561 void getWorldTransforms(Matrix4* xform) const; 00563 const Quaternion& getWorldOrientation(void) const; 00565 const Vector3& getWorldPosition(void) const; 00566 00577 virtual void setInitialState(void); 00578 00580 virtual void resetToInitialState(void); 00581 00586 virtual const Vector3& getInitialPosition(void) const; 00587 00589 virtual const Quaternion& getInitialOrientation(void) const; 00590 00592 virtual const Vector3& getInitialScale(void) const; 00593 00602 virtual void _weightedTransform(Real weight, const Vector3& translate, 00603 const Quaternion& rotate, const Vector3& scale); 00604 00606 Real getSquaredViewDepth(const Camera* cam) const; 00607 00613 virtual void needUpdate(); 00615 virtual void requestUpdate(Node* child); 00617 virtual void cancelUpdate(Node* child); 00618 00620 const LightList& getLights(void) const 00621 { 00622 // Nodes should not be lit by the scene, this will not get called 00623 static LightList ll; 00624 return ll; 00625 } 00626 00627 00628 00629 }; 00630 00631 } //namespace 00632 00633 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:36 2004