CRigidbody.generated.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;
  4. namespace BansheeEngine
  5. {
  6. /** @addtogroup Physics
  7. * @{
  8. */
  9. /// <summary>
  10. /// Rigidbody is a dynamic physics object that can be moved using forces (or directly). It will interact with other static
  11. /// and dynamic physics objects in the scene accordingly (it will push other non-kinematic rigidbodies, and collide with
  12. /// static objects).
  13. ///
  14. /// The shape and mass of a rigidbody is governed by its colliders. You must attach at least one collider for the
  15. /// rigidbody to be valid.
  16. /// </summary>
  17. public partial class Rigidbody : Component
  18. {
  19. private Rigidbody(bool __dummy0) { }
  20. protected Rigidbody() { }
  21. /// <summary>
  22. /// Determines the mass of the object and all of its collider shapes. Only relevant if RigidbodyFlag::AutoMass or
  23. /// RigidbodyFlag::AutoTensors is turned off. Value of zero means the object is immovable (but can be rotated).
  24. /// </summary>
  25. [ShowInInspector]
  26. public float Mass
  27. {
  28. get { return Internal_getMass(mCachedPtr); }
  29. set { Internal_setMass(mCachedPtr, value); }
  30. }
  31. /// <summary>
  32. /// Determines if the body is kinematic. Kinematic body will not move in response to external forces (for example
  33. /// gravity, or another object pushing it), essentially behaving like collider. Unlike a collider though, you can still
  34. /// move the object and have other dynamic objects respond correctly (meaning it will push other objects).
  35. /// </summary>
  36. [ShowInInspector]
  37. public bool IsKinematic
  38. {
  39. get { return Internal_getIsKinematic(mCachedPtr); }
  40. set { Internal_setIsKinematic(mCachedPtr, value); }
  41. }
  42. /// <summary>
  43. /// Checks if the body is sleeping. Objects that aren't moved/rotated for a while are put to sleep to reduce load on the
  44. /// physics system.
  45. /// </summary>
  46. [ShowInInspector]
  47. public bool IsSleeping
  48. {
  49. get { return Internal_isSleeping(mCachedPtr); }
  50. }
  51. /// <summary>
  52. /// Determines a threshold of force and torque under which the object will be considered to be put to sleep.
  53. /// </summary>
  54. [ShowInInspector]
  55. public float SleepThreshold
  56. {
  57. get { return Internal_getSleepThreshold(mCachedPtr); }
  58. set { Internal_setSleepThreshold(mCachedPtr, value); }
  59. }
  60. /// <summary>Determines whether or not the rigidbody will have the global gravity force applied to it.</summary>
  61. [ShowInInspector]
  62. public bool UseGravity
  63. {
  64. get { return Internal_getUseGravity(mCachedPtr); }
  65. set { Internal_setUseGravity(mCachedPtr, value); }
  66. }
  67. /// <summary>Determines the linear velocity of the body.</summary>
  68. [ShowInInspector]
  69. public Vector3 Velocity
  70. {
  71. get
  72. {
  73. Vector3 temp;
  74. Internal_getVelocity(mCachedPtr, out temp);
  75. return temp;
  76. }
  77. set { Internal_setVelocity(mCachedPtr, ref value); }
  78. }
  79. /// <summary>Determines the angular velocity of the body.</summary>
  80. [ShowInInspector]
  81. public Vector3 AngularVelocity
  82. {
  83. get
  84. {
  85. Vector3 temp;
  86. Internal_getAngularVelocity(mCachedPtr, out temp);
  87. return temp;
  88. }
  89. set { Internal_setAngularVelocity(mCachedPtr, ref value); }
  90. }
  91. /// <summary>
  92. /// Determines the linear drag of the body. Higher drag values means the object resists linear movement more.
  93. /// </summary>
  94. [ShowInInspector]
  95. public float Drag
  96. {
  97. get { return Internal_getDrag(mCachedPtr); }
  98. set { Internal_setDrag(mCachedPtr, value); }
  99. }
  100. /// <summary>
  101. /// Determines the angular drag of the body. Higher drag values means the object resists angular movement more.
  102. /// </summary>
  103. [ShowInInspector]
  104. public float AngularDrag
  105. {
  106. get { return Internal_getAngularDrag(mCachedPtr); }
  107. set { Internal_setAngularDrag(mCachedPtr, value); }
  108. }
  109. /// <summary>
  110. /// Determines the inertia tensor in local mass space. Inertia tensor determines how difficult is to rotate the object.
  111. /// Values of zero in the inertia tensor mean the object will be unable to rotate around a specific axis. Only relevant
  112. /// if RigidbodyFlag::AutoTensors is turned off.
  113. /// </summary>
  114. [ShowInInspector]
  115. public Vector3 InertiaTensor
  116. {
  117. get
  118. {
  119. Vector3 temp;
  120. Internal_getInertiaTensor(mCachedPtr, out temp);
  121. return temp;
  122. }
  123. set { Internal_setInertiaTensor(mCachedPtr, ref value); }
  124. }
  125. /// <summary>Determines the maximum angular velocity of the rigidbody. Velocity will be clamped to this value.</summary>
  126. [ShowInInspector]
  127. public float MaxAngularVelocity
  128. {
  129. get { return Internal_getMaxAngularVelocity(mCachedPtr); }
  130. set { Internal_setMaxAngularVelocity(mCachedPtr, value); }
  131. }
  132. /// <summary>
  133. /// Determines the rigidbody's center of mass position. Only relevant if RigibodyFlag::AutoTensors is turned off.
  134. /// </summary>
  135. [ShowInInspector]
  136. public Vector3 CenterOfMassPosition
  137. {
  138. get
  139. {
  140. Vector3 temp;
  141. Internal_getCenterOfMassPosition(mCachedPtr, out temp);
  142. return temp;
  143. }
  144. set { Internal_setCenterOfMassPosition(mCachedPtr, ref value); }
  145. }
  146. /// <summary>
  147. /// Determines the rigidbody's center of mass rotation. Only relevant if RigibodyFlag::AutoTensors is turned off.
  148. /// </summary>
  149. [ShowInInspector]
  150. public Quaternion CenterOfMassRotation
  151. {
  152. get
  153. {
  154. Quaternion temp;
  155. Internal_getCenterOfMassRotation(mCachedPtr, out temp);
  156. return temp;
  157. }
  158. set { Internal_setCenterOfMassRotation(mCachedPtr, ref value); }
  159. }
  160. /// <summary>
  161. /// Determines the number of iterations to use when solving for position. Higher values can improve precision and
  162. /// numerical stability of the simulation.
  163. /// </summary>
  164. [ShowInInspector]
  165. public uint PositionSolverCount
  166. {
  167. get { return Internal_getPositionSolverCount(mCachedPtr); }
  168. set { Internal_setPositionSolverCount(mCachedPtr, value); }
  169. }
  170. /// <summary>
  171. /// Determines the number of iterations to use when solving for velocity. Higher values can improve precision and
  172. /// numerical stability of the simulation.
  173. /// </summary>
  174. [ShowInInspector]
  175. public uint VelocitySolverCount
  176. {
  177. get { return Internal_getVelocitySolverCount(mCachedPtr); }
  178. set { Internal_setVelocitySolverCount(mCachedPtr, value); }
  179. }
  180. /// <summary>Sets a value that determines which (if any) collision events are reported.</summary>
  181. [ShowInInspector]
  182. public CollisionReportMode CollisionReportMode
  183. {
  184. get { return Internal_getCollisionReportMode(mCachedPtr); }
  185. set { Internal_setCollisionReportMode(mCachedPtr, value); }
  186. }
  187. /// <summary>Flags that control the behaviour of the rigidbody.</summary>
  188. [ShowInInspector]
  189. public RigidbodyFlag Flags
  190. {
  191. get { return Internal_getFlags(mCachedPtr); }
  192. set { Internal_setFlags(mCachedPtr, value); }
  193. }
  194. /// <summary>Triggered when one of the colliders owned by the rigidbody starts colliding with another object.</summary>
  195. public event Action<CollisionData> OnCollisionBegin;
  196. /// <summary>Triggered when a previously colliding collider stays in collision. Triggered once per frame.</summary>
  197. public event Action<CollisionData> OnCollisionStay;
  198. /// <summary>Triggered when one of the colliders owned by the rigidbody stops colliding with another object.</summary>
  199. public event Action<CollisionData> OnCollisionEnd;
  200. /// <summary>
  201. /// Moves the rigidbody to a specific position. This method will ensure physically correct movement, meaning the body
  202. /// will collide with other objects along the way.
  203. /// </summary>
  204. public void Move(Vector3 position)
  205. {
  206. Internal_move(mCachedPtr, ref position);
  207. }
  208. /// <summary>
  209. /// Rotates the rigidbody. This method will ensure physically correct rotation, meaning the body will collide with other
  210. /// objects along the way.
  211. /// </summary>
  212. public void Rotate(Quaternion rotation)
  213. {
  214. Internal_rotate(mCachedPtr, ref rotation);
  215. }
  216. /// <summary>
  217. /// Forces the object to sleep. Useful if you know the object will not move in any significant way for a while.
  218. /// </summary>
  219. public void Sleep()
  220. {
  221. Internal_sleep(mCachedPtr);
  222. }
  223. /// <summary>
  224. /// Wakes an object up. Useful if you modified properties of this object, and potentially surrounding objects which might
  225. /// result in the object being moved by physics (although the physics system will automatically wake the object up for
  226. /// majority of such cases).
  227. /// </summary>
  228. public void WakeUp()
  229. {
  230. Internal_wakeUp(mCachedPtr);
  231. }
  232. /// <summary>Applies a force to the center of the mass of the rigidbody. This will produce linear momentum.</summary>
  233. /// <param name="force">Force to apply.</param>
  234. /// <param name="mode">Determines what is the type of <paramref name="force"/>.</param>
  235. public void AddForce(Vector3 force, ForceMode mode = ForceMode.Force)
  236. {
  237. Internal_addForce(mCachedPtr, ref force, mode);
  238. }
  239. /// <summary>Applies a torque to the rigidbody. This will produce angular momentum.</summary>
  240. /// <param name="torque">Torque to apply.</param>
  241. /// <param name="mode">Determines what is the type of <paramref name="torque"/>.</param>
  242. public void AddTorque(Vector3 torque, ForceMode mode = ForceMode.Force)
  243. {
  244. Internal_addTorque(mCachedPtr, ref torque, mode);
  245. }
  246. /// <summary>
  247. /// Applies a force to a specific point on the rigidbody. This will in most cases produce both linear and angular
  248. /// momentum.
  249. /// </summary>
  250. /// <param name="force">Force to apply.</param>
  251. /// <param name="position">World position to apply the force at.</param>
  252. /// <param name="mode">Determines what is the type of <paramref name="force"/>.</param>
  253. public void AddForceAtPoint(Vector3 force, Vector3 position, PointForceMode mode = PointForceMode.Force)
  254. {
  255. Internal_addForceAtPoint(mCachedPtr, ref force, ref position, mode);
  256. }
  257. /// <summary>Returns the total (linear + angular) velocity at a specific point.</summary>
  258. /// <param name="point">Point in world space.</param>
  259. /// <returns>Total velocity of the point.</returns>
  260. public Vector3 GetVelocityAtPoint(Vector3 point)
  261. {
  262. Vector3 temp;
  263. Internal_getVelocityAtPoint(mCachedPtr, ref point, out temp);
  264. return temp;
  265. }
  266. [MethodImpl(MethodImplOptions.InternalCall)]
  267. private static extern void Internal_move(IntPtr thisPtr, ref Vector3 position);
  268. [MethodImpl(MethodImplOptions.InternalCall)]
  269. private static extern void Internal_rotate(IntPtr thisPtr, ref Quaternion rotation);
  270. [MethodImpl(MethodImplOptions.InternalCall)]
  271. private static extern void Internal_setMass(IntPtr thisPtr, float mass);
  272. [MethodImpl(MethodImplOptions.InternalCall)]
  273. private static extern float Internal_getMass(IntPtr thisPtr);
  274. [MethodImpl(MethodImplOptions.InternalCall)]
  275. private static extern void Internal_setIsKinematic(IntPtr thisPtr, bool kinematic);
  276. [MethodImpl(MethodImplOptions.InternalCall)]
  277. private static extern bool Internal_getIsKinematic(IntPtr thisPtr);
  278. [MethodImpl(MethodImplOptions.InternalCall)]
  279. private static extern bool Internal_isSleeping(IntPtr thisPtr);
  280. [MethodImpl(MethodImplOptions.InternalCall)]
  281. private static extern void Internal_sleep(IntPtr thisPtr);
  282. [MethodImpl(MethodImplOptions.InternalCall)]
  283. private static extern void Internal_wakeUp(IntPtr thisPtr);
  284. [MethodImpl(MethodImplOptions.InternalCall)]
  285. private static extern void Internal_setSleepThreshold(IntPtr thisPtr, float threshold);
  286. [MethodImpl(MethodImplOptions.InternalCall)]
  287. private static extern float Internal_getSleepThreshold(IntPtr thisPtr);
  288. [MethodImpl(MethodImplOptions.InternalCall)]
  289. private static extern void Internal_setUseGravity(IntPtr thisPtr, bool gravity);
  290. [MethodImpl(MethodImplOptions.InternalCall)]
  291. private static extern bool Internal_getUseGravity(IntPtr thisPtr);
  292. [MethodImpl(MethodImplOptions.InternalCall)]
  293. private static extern void Internal_setVelocity(IntPtr thisPtr, ref Vector3 velocity);
  294. [MethodImpl(MethodImplOptions.InternalCall)]
  295. private static extern void Internal_getVelocity(IntPtr thisPtr, out Vector3 __output);
  296. [MethodImpl(MethodImplOptions.InternalCall)]
  297. private static extern void Internal_setAngularVelocity(IntPtr thisPtr, ref Vector3 velocity);
  298. [MethodImpl(MethodImplOptions.InternalCall)]
  299. private static extern void Internal_getAngularVelocity(IntPtr thisPtr, out Vector3 __output);
  300. [MethodImpl(MethodImplOptions.InternalCall)]
  301. private static extern void Internal_setDrag(IntPtr thisPtr, float drag);
  302. [MethodImpl(MethodImplOptions.InternalCall)]
  303. private static extern float Internal_getDrag(IntPtr thisPtr);
  304. [MethodImpl(MethodImplOptions.InternalCall)]
  305. private static extern void Internal_setAngularDrag(IntPtr thisPtr, float drag);
  306. [MethodImpl(MethodImplOptions.InternalCall)]
  307. private static extern float Internal_getAngularDrag(IntPtr thisPtr);
  308. [MethodImpl(MethodImplOptions.InternalCall)]
  309. private static extern void Internal_setInertiaTensor(IntPtr thisPtr, ref Vector3 tensor);
  310. [MethodImpl(MethodImplOptions.InternalCall)]
  311. private static extern void Internal_getInertiaTensor(IntPtr thisPtr, out Vector3 __output);
  312. [MethodImpl(MethodImplOptions.InternalCall)]
  313. private static extern void Internal_setMaxAngularVelocity(IntPtr thisPtr, float maxVelocity);
  314. [MethodImpl(MethodImplOptions.InternalCall)]
  315. private static extern float Internal_getMaxAngularVelocity(IntPtr thisPtr);
  316. [MethodImpl(MethodImplOptions.InternalCall)]
  317. private static extern void Internal_setCenterOfMassPosition(IntPtr thisPtr, ref Vector3 position);
  318. [MethodImpl(MethodImplOptions.InternalCall)]
  319. private static extern void Internal_getCenterOfMassPosition(IntPtr thisPtr, out Vector3 __output);
  320. [MethodImpl(MethodImplOptions.InternalCall)]
  321. private static extern void Internal_setCenterOfMassRotation(IntPtr thisPtr, ref Quaternion rotation);
  322. [MethodImpl(MethodImplOptions.InternalCall)]
  323. private static extern void Internal_getCenterOfMassRotation(IntPtr thisPtr, out Quaternion __output);
  324. [MethodImpl(MethodImplOptions.InternalCall)]
  325. private static extern void Internal_setPositionSolverCount(IntPtr thisPtr, uint count);
  326. [MethodImpl(MethodImplOptions.InternalCall)]
  327. private static extern uint Internal_getPositionSolverCount(IntPtr thisPtr);
  328. [MethodImpl(MethodImplOptions.InternalCall)]
  329. private static extern void Internal_setVelocitySolverCount(IntPtr thisPtr, uint count);
  330. [MethodImpl(MethodImplOptions.InternalCall)]
  331. private static extern uint Internal_getVelocitySolverCount(IntPtr thisPtr);
  332. [MethodImpl(MethodImplOptions.InternalCall)]
  333. private static extern void Internal_setCollisionReportMode(IntPtr thisPtr, CollisionReportMode mode);
  334. [MethodImpl(MethodImplOptions.InternalCall)]
  335. private static extern CollisionReportMode Internal_getCollisionReportMode(IntPtr thisPtr);
  336. [MethodImpl(MethodImplOptions.InternalCall)]
  337. private static extern void Internal_setFlags(IntPtr thisPtr, RigidbodyFlag flags);
  338. [MethodImpl(MethodImplOptions.InternalCall)]
  339. private static extern RigidbodyFlag Internal_getFlags(IntPtr thisPtr);
  340. [MethodImpl(MethodImplOptions.InternalCall)]
  341. private static extern void Internal_addForce(IntPtr thisPtr, ref Vector3 force, ForceMode mode);
  342. [MethodImpl(MethodImplOptions.InternalCall)]
  343. private static extern void Internal_addTorque(IntPtr thisPtr, ref Vector3 torque, ForceMode mode);
  344. [MethodImpl(MethodImplOptions.InternalCall)]
  345. private static extern void Internal_addForceAtPoint(IntPtr thisPtr, ref Vector3 force, ref Vector3 position, PointForceMode mode);
  346. [MethodImpl(MethodImplOptions.InternalCall)]
  347. private static extern void Internal_getVelocityAtPoint(IntPtr thisPtr, ref Vector3 point, out Vector3 __output);
  348. private void Internal_onCollisionBegin(ref CollisionData p0)
  349. {
  350. OnCollisionBegin?.Invoke(p0);
  351. }
  352. private void Internal_onCollisionStay(ref CollisionData p0)
  353. {
  354. OnCollisionStay?.Invoke(p0);
  355. }
  356. private void Internal_onCollisionEnd(ref CollisionData p0)
  357. {
  358. OnCollisionEnd?.Invoke(p0);
  359. }
  360. }
  361. /** @} */
  362. }