| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of OGRE |
|---|
| 4 | (Object-oriented Graphics Rendering Engine) |
|---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
|---|
| 6 | |
|---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
|---|
| 8 | Also see acknowledgements in Readme.html |
|---|
| 9 | |
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 13 | version. |
|---|
| 14 | |
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 18 | |
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 23 | |
|---|
| 24 | You may alternatively use this source under the terms of a specific version of |
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
|---|
| 26 | Torus Knot Software Ltd. |
|---|
| 27 | ----------------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | #ifndef __Bone_H__ |
|---|
| 31 | #define __Bone_H__ |
|---|
| 32 | |
|---|
| 33 | #include "OgrePrerequisites.h" |
|---|
| 34 | #include "OgreNode.h" |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | namespace Ogre |
|---|
| 38 | { |
|---|
| 39 | /** A bone in a skeleton. |
|---|
| 40 | @remarks |
|---|
| 41 | See Skeleton for more information about the principles behind skeletal animation. |
|---|
| 42 | This class is a node in the joint hierarchy. Mesh vertices also have assignments |
|---|
| 43 | to bones to define how they move in relation to the skeleton. |
|---|
| 44 | */ |
|---|
| 45 | class _OgreExport Bone : public Node |
|---|
| 46 | { |
|---|
| 47 | public: |
|---|
| 48 | /** Constructor, not to be used directly (use Bone::createChild or Skeleton::createBone) */ |
|---|
| 49 | Bone(unsigned short handle, Skeleton* creator); |
|---|
| 50 | /** Constructor, not to be used directly (use Bone::createChild or Skeleton::createBone) */ |
|---|
| 51 | Bone(const String& name, unsigned short handle, Skeleton* creator); |
|---|
| 52 | ~Bone(); |
|---|
| 53 | |
|---|
| 54 | /** Creates a new Bone as a child of this bone. |
|---|
| 55 | @remarks |
|---|
| 56 | This method creates a new bone which will inherit the transforms of this |
|---|
| 57 | bone, with the handle specified. |
|---|
| 58 | @param |
|---|
| 59 | handle The numeric handle to give the new bone; must be unique within the Skeleton. |
|---|
| 60 | @param |
|---|
| 61 | translate Initial translation offset of child relative to parent |
|---|
| 62 | @param |
|---|
| 63 | rotate Initial rotation relative to parent |
|---|
| 64 | */ |
|---|
| 65 | Bone* createChild(unsigned short handle, |
|---|
| 66 | const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY); |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | /** Gets the numeric handle for this bone (unique within the skeleton). */ |
|---|
| 70 | unsigned short getHandle(void) const; |
|---|
| 71 | |
|---|
| 72 | /** Sets the current position / orientation to be the 'binding pose' ie the layout in which |
|---|
| 73 | bones were originally bound to a mesh. |
|---|
| 74 | */ |
|---|
| 75 | void setBindingPose(void); |
|---|
| 76 | |
|---|
| 77 | /** Resets the position and orientation of this Bone to the original binding position. |
|---|
| 78 | @remarks |
|---|
| 79 | Bones are bound to the mesh in a binding pose. They are then modified from this |
|---|
| 80 | position during animation. This method returns the bone to it's original position and |
|---|
| 81 | orientation. |
|---|
| 82 | */ |
|---|
| 83 | void reset(void); |
|---|
| 84 | |
|---|
| 85 | /** Sets whether or not this bone is manually controlled. |
|---|
| 86 | @remarks |
|---|
| 87 | Manually controlled bones can be altered by the application at runtime, |
|---|
| 88 | and their positions will not be reset by the animation routines. Note |
|---|
| 89 | that you should also make sure that there are no AnimationTrack objects |
|---|
| 90 | referencing this bone, or if there are, you should disable them using |
|---|
| 91 | pAnimation->destroyTrack(pBone->getHandle()); |
|---|
| 92 | */ |
|---|
| 93 | void setManuallyControlled(bool manuallyControlled); |
|---|
| 94 | |
|---|
| 95 | /** Getter for mManuallyControlled Flag */ |
|---|
| 96 | bool isManuallyControlled() const; |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | /** Gets the transform which takes bone space to current from the binding pose. |
|---|
| 100 | @remarks |
|---|
| 101 | Internal use only. |
|---|
| 102 | */ |
|---|
| 103 | void _getOffsetTransform(Matrix4& m) const; |
|---|
| 104 | |
|---|
| 105 | /** Gets the inverted binding pose scale. */ |
|---|
| 106 | const Vector3& _getBindingPoseInverseScale(void) const { return mBindDerivedInverseScale; } |
|---|
| 107 | /** Gets the inverted binding pose position. */ |
|---|
| 108 | const Vector3& _getBindingPoseInversePosition(void) const { return mBindDerivedInversePosition; } |
|---|
| 109 | /** Gets the inverted binding pose orientation. */ |
|---|
| 110 | const Quaternion& _getBindingPoseInverseOrientation(void) const { return mBindDerivedInverseOrientation; } |
|---|
| 111 | |
|---|
| 112 | /// @see Node::needUpdate |
|---|
| 113 | void needUpdate(bool forceParentUpdate = false); |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | protected: |
|---|
| 117 | /// The numeric handle of this bone |
|---|
| 118 | unsigned short mHandle; |
|---|
| 119 | |
|---|
| 120 | /** Bones set as manuallyControlled are not reseted in Skeleton::reset() */ |
|---|
| 121 | bool mManuallyControlled; |
|---|
| 122 | |
|---|
| 123 | /** See Node. */ |
|---|
| 124 | Node* createChildImpl(void); |
|---|
| 125 | /** See Node. */ |
|---|
| 126 | Node* createChildImpl(const String& name); |
|---|
| 127 | |
|---|
| 128 | /// Pointer back to creator, for child creation (not smart ptr so child does not preserve parent) |
|---|
| 129 | Skeleton* mCreator; |
|---|
| 130 | |
|---|
| 131 | /// The inversed derived scale of the bone in the binding pose |
|---|
| 132 | Vector3 mBindDerivedInverseScale; |
|---|
| 133 | /// The inversed derived orientation of the bone in the binding pose |
|---|
| 134 | Quaternion mBindDerivedInverseOrientation; |
|---|
| 135 | /// The inversed derived position of the bone in the binding pose |
|---|
| 136 | Vector3 mBindDerivedInversePosition; |
|---|
| 137 | }; |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | #endif |
|---|