NativeJoint.cs 3.5 KB

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