Joint.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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::Type Joint::getType() const
  18. {
  19. return Node::JOINT;
  20. }
  21. void Joint::transformChanged()
  22. {
  23. Node::transformChanged();
  24. _jointMatrixDirty = true;
  25. }
  26. void Joint::updateJointMatrix(const Matrix& bindShape, Vector4* matrixPalette)
  27. {
  28. // Note: If more than one MeshSkin influences this Joint, we need to skip
  29. // the _jointMatrixDirty optimization since updateJointMatrix() may be
  30. // called multiple times a frame with different bindShape matrices (and
  31. // different matrixPallete pointers).
  32. if (_skinCount > 1 || _jointMatrixDirty)
  33. {
  34. _jointMatrixDirty = false;
  35. static Matrix t;
  36. Matrix::multiply(Node::getWorldMatrix(), getInverseBindPose(), &t);
  37. Matrix::multiply(t, bindShape, &t);
  38. matrixPalette[0].set(t.m[0], t.m[4], t.m[8], t.m[12]);
  39. matrixPalette[1].set(t.m[1], t.m[5], t.m[9], t.m[13]);
  40. matrixPalette[2].set(t.m[2], t.m[6], t.m[10], t.m[14]);
  41. }
  42. }
  43. const Matrix& Joint::getInverseBindPose() const
  44. {
  45. return _bindPose;
  46. }
  47. void Joint::setInverseBindPose(const Matrix& m)
  48. {
  49. _bindPose = m;
  50. _jointMatrixDirty = true;
  51. }
  52. }