CRigidbody.generated.cs 16 KB

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