SphericalJoint.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. namespace BansheeEngine
  5. {
  6. /// <summary>
  7. /// A spherical joint removes all translational degrees of freedom but allows all rotational degrees of freedom.
  8. /// Essentially this ensures that the anchor points of the two bodies are always coincident. Bodies are allowed to
  9. /// rotate around the anchor points, and their rotatation can be limited by an elliptical cone.
  10. /// </summary>
  11. public sealed class SphericalJoint : Joint
  12. {
  13. [SerializeField]
  14. private LimitConeRange limit = new LimitConeRange();
  15. [SerializeField]
  16. private bool enableLimit;
  17. /// <summary>
  18. /// Determines the limit that clamps the rotation of the joint inside an eliptical angular cone. You must enable
  19. /// <see cref="EnableLimit"/> for this to be enforced.
  20. /// </summary>
  21. public LimitConeRange Limit
  22. {
  23. get { return limit; }
  24. set
  25. {
  26. if (limit == value)
  27. return;
  28. limit = value;
  29. if (Native != null)
  30. Native.Limit = value;
  31. }
  32. }
  33. /// <summary>
  34. /// Enables or disables the limit that clamps the rotation of the joint.
  35. /// </summary>
  36. public bool EnableLimit
  37. {
  38. get { return enableLimit; }
  39. set
  40. {
  41. if (enableLimit == value)
  42. return;
  43. enableLimit = value;
  44. if (Native != null)
  45. Native.EnableLimit = value;
  46. }
  47. }
  48. /// <summary>
  49. /// Returns the native joint wrapped by this component.
  50. /// </summary>
  51. private NativeSphericalJoint Native
  52. {
  53. get { return (NativeSphericalJoint)native; }
  54. }
  55. /// <inheritdoc/>
  56. internal override NativeJoint CreateNative()
  57. {
  58. NativeSphericalJoint joint = new NativeSphericalJoint();
  59. // TODO - Apply this all at once to avoid all the individual interop function calls
  60. joint.Limit = limit;
  61. joint.EnableLimit = enableLimit;
  62. return joint;
  63. }
  64. }
  65. }