NativeJoint.cs 3.5 KB

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