2
0

CRigidbody.generated.cs 16 KB

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