Bone.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "Bone.h"
  25. #include "DebugNew.h"
  26. Bone::Bone(Bone* rootBone, const std::string& name) :
  27. Node(NODE_BONE, name),
  28. mRootBone(rootBone),
  29. mInitialPosition(Vector3::sZero),
  30. mInitialRotation(Quaternion::sIdentity),
  31. mInitialScale(Vector3::sUnity),
  32. mOffsetMatrix(Matrix4x3::sIdentity),
  33. mCollisionMask(BONECOLLISION_NONE),
  34. mRadius(0.0f),
  35. mAnimationEnabled(true),
  36. mSkinningDirty(true)
  37. {
  38. if (!mRootBone)
  39. mRootBone = this;
  40. }
  41. Bone::~Bone()
  42. {
  43. }
  44. void Bone::setRootBone(Bone* rootBone)
  45. {
  46. if (rootBone == 0)
  47. rootBone = this;
  48. if (rootBone != mRootBone)
  49. {
  50. mRootBone = rootBone;
  51. markDirty();
  52. }
  53. }
  54. void Bone::setInitialTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale)
  55. {
  56. mInitialPosition = position;
  57. mInitialRotation = rotation;
  58. mInitialScale = scale;
  59. }
  60. void Bone::setOffsetMatrix(const Matrix4x3& offset)
  61. {
  62. mOffsetMatrix = offset;
  63. }
  64. void Bone::setRadius(float radius)
  65. {
  66. mRadius = radius;
  67. mCollisionMask |= BONECOLLISION_SPHERE;
  68. }
  69. void Bone::setBoundingBox(const BoundingBox& box)
  70. {
  71. mBoundingBox = box;
  72. mCollisionMask |= BONECOLLISION_BOX;
  73. }
  74. void Bone::setAnimationEnabled(bool enable)
  75. {
  76. mAnimationEnabled = enable;
  77. }
  78. void Bone::reset(bool force)
  79. {
  80. if ((force) || (mAnimationEnabled))
  81. setTransform(mInitialPosition, mInitialRotation, mInitialScale);
  82. }
  83. void Bone::onMarkedDirty()
  84. {
  85. mSkinningDirty = true;
  86. // Dirty also the skinning flag of root bone for faster checking of whether any bones have changed in the skeleton
  87. mRootBone->mSkinningDirty = true;
  88. }