SphericalJoint.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 SerializableData data = new SerializableData();
  15. /// <summary>
  16. /// Determines the limit that clamps the rotation of the joint inside an eliptical angular cone. You must enable
  17. /// <see cref="EnableLimit"/> for this to be enforced.
  18. /// </summary>
  19. public LimitConeRange Limit
  20. {
  21. get { return [email protected]; }
  22. set
  23. {
  24. if ([email protected] == value)
  25. return;
  26. [email protected] = value;
  27. if (Native != null)
  28. Native.Limit = value;
  29. }
  30. }
  31. /// <summary>
  32. /// Enables or disables the limit that clamps the rotation of the joint.
  33. /// </summary>
  34. public bool EnableLimit
  35. {
  36. get { return [email protected]; }
  37. set
  38. {
  39. if ([email protected] == value)
  40. return;
  41. [email protected] = value;
  42. if (Native != null)
  43. Native.EnableLimit = value;
  44. }
  45. }
  46. /// <summary>
  47. /// Returns the native joint wrapped by this component.
  48. /// </summary>
  49. private NativeSphericalJoint Native
  50. {
  51. get { return (NativeSphericalJoint)native; }
  52. }
  53. /// <inheritdoc/>
  54. internal override NativeJoint CreateNative()
  55. {
  56. NativeSphericalJoint joint = new NativeSphericalJoint(commonData.@internal, data.@internal);
  57. return joint;
  58. }
  59. /// <summary>
  60. /// Holds all data the joint component needs to persist through serialization.
  61. /// </summary>
  62. [SerializeObject]
  63. internal new class SerializableData
  64. {
  65. public ScriptSphericalJointData @internal;
  66. public SerializableData()
  67. {
  68. @internal.limit = new LimitConeRange();
  69. @internal.enableLimit = false;
  70. }
  71. }
  72. }
  73. }