[148] | 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-2013 Torus Knot Software Ltd |
---|
| 8 | |
---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 10 | of this software and associated documentation files (the "Software"), to deal |
---|
| 11 | in the Software without restriction, including without limitation the rights |
---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 13 | copies of the Software, and to permit persons to whom the Software is |
---|
| 14 | furnished to do so, subject to the following conditions: |
---|
| 15 | |
---|
| 16 | The above copyright notice and this permission notice shall be included in |
---|
| 17 | all copies or substantial portions of the Software. |
---|
| 18 | |
---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 25 | THE SOFTWARE. |
---|
| 26 | ----------------------------------------------------------------------------- |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef __Bone_H__ |
---|
| 30 | #define __Bone_H__ |
---|
| 31 | |
---|
| 32 | #include "OgrePrerequisites.h" |
---|
| 33 | #include "OgreNode.h" |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | namespace Ogre |
---|
| 37 | { |
---|
| 38 | /** \addtogroup Core |
---|
| 39 | * @{ |
---|
| 40 | */ |
---|
| 41 | /** \addtogroup Animation |
---|
| 42 | * @{ |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | /** A bone in a skeleton. |
---|
| 46 | @remarks |
---|
| 47 | See Skeleton for more information about the principles behind skeletal animation. |
---|
| 48 | This class is a node in the joint hierarchy. Mesh vertices also have assignments |
---|
| 49 | to bones to define how they move in relation to the skeleton. |
---|
| 50 | */ |
---|
| 51 | class _OgreExport Bone : public Node |
---|
| 52 | { |
---|
| 53 | public: |
---|
| 54 | /** Constructor, not to be used directly (use Bone::createChild or Skeleton::createBone) */ |
---|
| 55 | Bone(unsigned short handle, Skeleton* creator); |
---|
| 56 | /** Constructor, not to be used directly (use Bone::createChild or Skeleton::createBone) */ |
---|
| 57 | Bone(const String& name, unsigned short handle, Skeleton* creator); |
---|
| 58 | ~Bone(); |
---|
| 59 | |
---|
| 60 | /** Creates a new Bone as a child of this bone. |
---|
| 61 | @remarks |
---|
| 62 | This method creates a new bone which will inherit the transforms of this |
---|
| 63 | bone, with the handle specified. |
---|
| 64 | @param |
---|
| 65 | handle The numeric handle to give the new bone; must be unique within the Skeleton. |
---|
| 66 | @param |
---|
| 67 | translate Initial translation offset of child relative to parent |
---|
| 68 | @param |
---|
| 69 | rotate Initial rotation relative to parent |
---|
| 70 | */ |
---|
| 71 | Bone* createChild(unsigned short handle, |
---|
| 72 | const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY); |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | /** Gets the numeric handle for this bone (unique within the skeleton). */ |
---|
| 76 | unsigned short getHandle(void) const; |
---|
| 77 | |
---|
| 78 | /** Sets the current position / orientation to be the 'binding pose' ie the layout in which |
---|
| 79 | bones were originally bound to a mesh. |
---|
| 80 | */ |
---|
| 81 | void setBindingPose(void); |
---|
| 82 | |
---|
| 83 | /** Resets the position and orientation of this Bone to the original binding position. |
---|
| 84 | @remarks |
---|
| 85 | Bones are bound to the mesh in a binding pose. They are then modified from this |
---|
| 86 | position during animation. This method returns the bone to it's original position and |
---|
| 87 | orientation. |
---|
| 88 | */ |
---|
| 89 | void reset(void); |
---|
| 90 | |
---|
| 91 | /** Sets whether or not this bone is manually controlled. |
---|
| 92 | @remarks |
---|
| 93 | Manually controlled bones can be altered by the application at runtime, |
---|
| 94 | and their positions will not be reset by the animation routines. Note |
---|
| 95 | that you should also make sure that there are no AnimationTrack objects |
---|
| 96 | referencing this bone, or if there are, you should disable them using |
---|
| 97 | pAnimation->destroyTrack(pBone->getHandle()); |
---|
| 98 | @par |
---|
| 99 | You can also use AnimationState::setBlendMask to mask out animation from |
---|
| 100 | chosen tracks if you want to prevent application of a scripted animation |
---|
| 101 | to a bone without altering the Animation definition. |
---|
| 102 | */ |
---|
| 103 | void setManuallyControlled(bool manuallyControlled); |
---|
| 104 | |
---|
| 105 | /** Getter for mManuallyControlled Flag */ |
---|
| 106 | bool isManuallyControlled() const; |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | /** Gets the transform which takes bone space to current from the binding pose. |
---|
| 110 | @remarks |
---|
| 111 | Internal use only. |
---|
| 112 | */ |
---|
| 113 | void _getOffsetTransform(Matrix4& m) const; |
---|
| 114 | |
---|
| 115 | /** Gets the inverted binding pose scale. */ |
---|
| 116 | const Vector3& _getBindingPoseInverseScale(void) const { return mBindDerivedInverseScale; } |
---|
| 117 | /** Gets the inverted binding pose position. */ |
---|
| 118 | const Vector3& _getBindingPoseInversePosition(void) const { return mBindDerivedInversePosition; } |
---|
| 119 | /** Gets the inverted binding pose orientation. */ |
---|
| 120 | const Quaternion& _getBindingPoseInverseOrientation(void) const { return mBindDerivedInverseOrientation; } |
---|
| 121 | |
---|
| 122 | /// @see Node::needUpdate |
---|
| 123 | void needUpdate(bool forceParentUpdate = false); |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | protected: |
---|
| 127 | /// The numeric handle of this bone |
---|
| 128 | unsigned short mHandle; |
---|
| 129 | |
---|
| 130 | /** Bones set as manuallyControlled are not reseted in Skeleton::reset() */ |
---|
| 131 | bool mManuallyControlled; |
---|
| 132 | |
---|
| 133 | /** See Node. */ |
---|
| 134 | Node* createChildImpl(void); |
---|
| 135 | /** See Node. */ |
---|
| 136 | Node* createChildImpl(const String& name); |
---|
| 137 | |
---|
| 138 | /// Pointer back to creator, for child creation (not smart ptr so child does not preserve parent) |
---|
| 139 | Skeleton* mCreator; |
---|
| 140 | |
---|
| 141 | /// The inversed derived scale of the bone in the binding pose |
---|
| 142 | Vector3 mBindDerivedInverseScale; |
---|
| 143 | /// The inversed derived orientation of the bone in the binding pose |
---|
| 144 | Quaternion mBindDerivedInverseOrientation; |
---|
| 145 | /// The inversed derived position of the bone in the binding pose |
---|
| 146 | Vector3 mBindDerivedInversePosition; |
---|
| 147 | }; |
---|
| 148 | |
---|
| 149 | /** @} */ |
---|
| 150 | /** @} */ |
---|
| 151 | |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | #endif |
---|