NativeJoint.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. using System.Runtime.InteropServices;
  6. namespace BansheeEngine
  7. {
  8. /** @cond INTEROP */
  9. /** @addtogroup Interop
  10. * @{
  11. */
  12. /// <summary>
  13. /// Wrapper around the native Joint class.
  14. /// <see cref="Joint"/>
  15. /// </summary>
  16. internal class NativeJoint : ScriptObject
  17. {
  18. private Joint component;
  19. /// <summary>
  20. /// Component that owns the native joint object.
  21. /// </summary>
  22. public Joint Component
  23. {
  24. get { return component; }
  25. set { component = value; }
  26. }
  27. public float BreakForce
  28. {
  29. set { Internal_SetBreakForce(mCachedPtr, value); }
  30. }
  31. public float BreakTorque
  32. {
  33. set { Internal_SetBreakTorque(mCachedPtr, value); }
  34. }
  35. public bool EnableCollision
  36. {
  37. set { Internal_SetEnableCollision(mCachedPtr, value); }
  38. }
  39. public void SetRigidbody(JointBody body, Rigidbody rigidbody)
  40. {
  41. IntPtr rigidbodyPtr = IntPtr.Zero;
  42. if (rigidbody != null)
  43. rigidbodyPtr = rigidbody.native.GetCachedPtr();
  44. Internal_SetBody(mCachedPtr, body, rigidbodyPtr);
  45. }
  46. public void SetPosition(JointBody body, Vector3 position)
  47. {
  48. Internal_SetPosition(mCachedPtr, body, ref position);
  49. }
  50. public void SetRotation(JointBody body, Quaternion rotation)
  51. {
  52. Internal_SetRotation(mCachedPtr, body, ref rotation);
  53. }
  54. public void Destroy()
  55. {
  56. Internal_Destroy(mCachedPtr);
  57. }
  58. private void Internal_DoOnJointBreak()
  59. {
  60. Component.DoOnJointBreak();
  61. }
  62. [MethodImpl(MethodImplOptions.InternalCall)]
  63. private static extern void Internal_Destroy(IntPtr thisPtr);
  64. [MethodImpl(MethodImplOptions.InternalCall)]
  65. private static extern void Internal_SetBody(IntPtr thisPtr, JointBody body, IntPtr rigidbody);
  66. [MethodImpl(MethodImplOptions.InternalCall)]
  67. private static extern void Internal_SetPosition(IntPtr thisPtr, JointBody body, ref Vector3 position);
  68. [MethodImpl(MethodImplOptions.InternalCall)]
  69. private static extern void Internal_SetRotation(IntPtr thisPtr, JointBody body, ref Quaternion rotation);
  70. [MethodImpl(MethodImplOptions.InternalCall)]
  71. private static extern void Internal_SetBreakForce(IntPtr thisPtr, float force);
  72. [MethodImpl(MethodImplOptions.InternalCall)]
  73. private static extern void Internal_SetBreakTorque(IntPtr thisPtr, float torque);
  74. [MethodImpl(MethodImplOptions.InternalCall)]
  75. private static extern void Internal_SetEnableCollision(IntPtr thisPtr, bool value);
  76. }
  77. /// <summary>
  78. /// Used for passing common Joint initialization data between native and managed code.
  79. /// </summary>
  80. [StructLayout(LayoutKind.Sequential), SerializeObject]
  81. internal struct ScriptCommonJointData // Note: Must match C++ struct ScriptCommonJointData
  82. {
  83. public IntPtr[] bodies;
  84. public Vector3[] positions;
  85. public Quaternion[] rotations;
  86. public float breakForce;
  87. public float breakTorque;
  88. public bool enableCollision;
  89. }
  90. /** @} */
  91. /** @endcond */
  92. }