BsCFixedJoint.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Components/BsCFixedJoint.h"
  4. #include "Scene/BsSceneObject.h"
  5. #include "Components/BsCRigidbody.h"
  6. #include "RTTI/BsCFixedJointRTTI.h"
  7. namespace bs
  8. {
  9. CFixedJoint::CFixedJoint()
  10. :CJoint(mDesc)
  11. { }
  12. CFixedJoint::CFixedJoint(const HSceneObject& parent)
  13. : CJoint(parent, mDesc)
  14. {
  15. setName("FixedJoint");
  16. }
  17. SPtr<Joint> CFixedJoint::createInternal()
  18. {
  19. SPtr<Joint> joint = FixedJoint::create(mDesc);
  20. joint->_setOwner(PhysicsOwnerType::Component, this);
  21. return joint;
  22. }
  23. void CFixedJoint::getLocalTransform(JointBody body, Vector3& position, Quaternion& rotation)
  24. {
  25. position = mPositions[(int)body];
  26. rotation = mRotations[(int)body];
  27. HRigidbody rigidbody = mBodies[(int)body];
  28. if (rigidbody == nullptr) // Get world space transform if no relative to any body
  29. {
  30. Quaternion worldRot = SO()->getWorldRotation();
  31. rotation = worldRot*rotation;
  32. position = worldRot.rotate(position) + SO()->getWorldPosition();
  33. }
  34. else
  35. {
  36. // Find world space transform
  37. Quaternion worldRot = rigidbody->SO()->getWorldRotation();
  38. rotation = worldRot * rotation;
  39. position = worldRot.rotate(position) + rigidbody->SO()->getWorldPosition();
  40. // Get transform of the joint local to the object
  41. Quaternion invRotation = rotation.inverse();
  42. position = invRotation.rotate(SO()->getWorldPosition() - position);
  43. rotation = invRotation * SO()->getWorldRotation();
  44. }
  45. }
  46. RTTITypeBase* CFixedJoint::getRTTIStatic()
  47. {
  48. return CFixedJointRTTI::instance();
  49. }
  50. RTTITypeBase* CFixedJoint::getRTTI() const
  51. {
  52. return CFixedJoint::getRTTIStatic();
  53. }
  54. }