Joint.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "Base.h"
  2. #include "Joint.h"
  3. #include "MeshSkin.h"
  4. namespace gameplay
  5. {
  6. Joint::Joint(const char* id)
  7. : Node(id), _jointMatrixDirty(true), _skinCount(0)
  8. {
  9. }
  10. Joint::~Joint()
  11. {
  12. }
  13. Joint* Joint::create(const char* id)
  14. {
  15. return new Joint(id);
  16. }
  17. Node* Joint::cloneSingleNode(NodeCloneContext &context) const
  18. {
  19. Joint* copy = Joint::create(getId());
  20. context.registerClonedNode(this, copy);
  21. copy->_bindPose = _bindPose;
  22. copy->_skinCount = _skinCount;
  23. Node::cloneInto(copy, context);
  24. return copy;
  25. }
  26. Node::Type Joint::getType() const
  27. {
  28. return Node::JOINT;
  29. }
  30. void Joint::transformChanged()
  31. {
  32. Node::transformChanged();
  33. _jointMatrixDirty = true;
  34. }
  35. void Joint::updateJointMatrix(const Matrix& bindShape, Vector4* matrixPalette)
  36. {
  37. // Note: If more than one MeshSkin influences this Joint, we need to skip
  38. // the _jointMatrixDirty optimization since updateJointMatrix() may be
  39. // called multiple times a frame with different bindShape matrices (and
  40. // different matrixPallete pointers).
  41. if (_skinCount > 1 || _jointMatrixDirty)
  42. {
  43. _jointMatrixDirty = false;
  44. static Matrix t;
  45. Matrix::multiply(Node::getWorldMatrix(), getInverseBindPose(), &t);
  46. Matrix::multiply(t, bindShape, &t);
  47. matrixPalette[0].set(t.m[0], t.m[4], t.m[8], t.m[12]);
  48. matrixPalette[1].set(t.m[1], t.m[5], t.m[9], t.m[13]);
  49. matrixPalette[2].set(t.m[2], t.m[6], t.m[10], t.m[14]);
  50. }
  51. }
  52. const Matrix& Joint::getInverseBindPose() const
  53. {
  54. return _bindPose;
  55. }
  56. void Joint::setInverseBindPose(const Matrix& m)
  57. {
  58. _bindPose = m;
  59. _jointMatrixDirty = true;
  60. }
  61. }