FixedJoint.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. namespace BansheeEngine
  4. {
  5. /** @addtogroup Physics
  6. * @{
  7. */
  8. /// <summary>
  9. /// Physics joint that will maintain a fixed distance and orientation between its two attached bodies.
  10. /// </summary>
  11. public sealed class FixedJoint : Joint
  12. {
  13. /// <inheritdoc/>
  14. protected override void GetLocalTransform(JointBody body, out Vector3 position, out Quaternion rotation)
  15. {
  16. position = commonData.positions[(int)body];
  17. rotation = commonData.rotations[(int)body];
  18. Rigidbody rigidbody = commonData.bodies[(int)body];
  19. if (rigidbody == null) // Get world space transform if not relative to any body
  20. {
  21. Quaternion worldRot = SceneObject.Rotation;
  22. rotation = worldRot * rotation;
  23. position = worldRot.Rotate(position) + SceneObject.Position;
  24. }
  25. else // Get transform of the object relative to the joint
  26. {
  27. // Find world space transform
  28. Quaternion worldRot = rigidbody.SceneObject.Rotation;
  29. rotation = worldRot * rotation;
  30. position = worldRot.Rotate(position) + rigidbody.SceneObject.Position;
  31. // Get transform of the joint local to the object
  32. Quaternion invRotation = rotation.Inverse;
  33. position = invRotation.Rotate(SceneObject.Position - position);
  34. rotation = invRotation * SceneObject.Rotation;
  35. }
  36. }
  37. /// <inheritdoc/>
  38. internal override NativeJoint CreateNative()
  39. {
  40. NativeFixedJoint joint = new NativeFixedJoint(commonData.@internal);
  41. return joint;
  42. }
  43. }
  44. /** @} */
  45. }