SphericalJoint.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /** @addtogroup Physics
  7. * @{
  8. */
  9. /// <summary>
  10. /// A spherical joint removes all translational degrees of freedom but allows all rotational degrees of freedom.
  11. /// Essentially this ensures that the anchor points of the two bodies are always coincident. Bodies are allowed to
  12. /// rotate around the anchor points, and their rotatation can be limited by an elliptical cone.
  13. /// </summary>
  14. public sealed class SphericalJoint : Joint
  15. {
  16. [SerializeField]
  17. private SerializableData data = new SerializableData();
  18. /// <summary>
  19. /// Determines the limit that clamps the rotation of the joint inside an eliptical angular cone. You must enable
  20. /// <see cref="EnableLimit"/> for this to be enforced.
  21. /// </summary>
  22. public LimitConeRange Limit
  23. {
  24. get { return [email protected]; }
  25. set
  26. {
  27. if ([email protected] == value)
  28. return;
  29. [email protected] = value;
  30. if (Native != null)
  31. Native.Limit = value;
  32. }
  33. }
  34. /// <summary>
  35. /// Enables or disables the limit that clamps the rotation of the joint.
  36. /// </summary>
  37. public bool EnableLimit
  38. {
  39. get { return [email protected]; }
  40. set
  41. {
  42. if ([email protected] == value)
  43. return;
  44. [email protected] = value;
  45. if (Native != null)
  46. Native.EnableLimit = value;
  47. }
  48. }
  49. /// <summary>
  50. /// Returns the native joint wrapped by this component.
  51. /// </summary>
  52. private NativeSphericalJoint Native
  53. {
  54. get { return (NativeSphericalJoint)native; }
  55. }
  56. /// <inheritdoc/>
  57. internal override NativeJoint CreateNative()
  58. {
  59. NativeSphericalJoint joint = new NativeSphericalJoint(commonData.@internal, data.@internal);
  60. return joint;
  61. }
  62. /// <summary>
  63. /// Holds all data the joint component needs to persist through serialization.
  64. /// </summary>
  65. [SerializeObject]
  66. internal new class SerializableData
  67. {
  68. public ScriptSphericalJointData @internal;
  69. public SerializableData()
  70. {
  71. @internal.limit = new LimitConeRange();
  72. @internal.enableLimit = false;
  73. }
  74. }
  75. }
  76. /** @} */
  77. }