Joint.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.InteropServices;
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup Physics
  8. * @{
  9. */
  10. /// <summary>
  11. /// Base class for all Joint types. Joints constrain how two rigidbodies move relative to one another (for example a
  12. /// door hinge). One of the bodies in the joint must always be movable (that is non-kinematic).
  13. /// </summary>
  14. public abstract class Joint : Component
  15. {
  16. internal NativeJoint native;
  17. [SerializeField]
  18. internal SerializableData commonData = new SerializableData();
  19. /// <summary>
  20. /// Triggered when the joint's break force or torque is exceeded.
  21. /// </summary>
  22. public event Action OnJointBreak;
  23. /// <summary>
  24. /// Maximum force the joint can apply before breaking. Broken joints no longer participate in physics simulation.
  25. /// </summary>
  26. public float BreakForce
  27. {
  28. get { return [email protected]; }
  29. set
  30. {
  31. if ([email protected] == value)
  32. return;
  33. [email protected] = value;
  34. if (native != null)
  35. native.BreakForce = value;
  36. }
  37. }
  38. /// <summary>
  39. /// Sets the maximum force the joint can apply before breaking. Broken joints no longer participate in physics
  40. /// simulation.
  41. /// </summary>
  42. public float BreakTorque
  43. {
  44. get { return [email protected]; }
  45. set
  46. {
  47. if ([email protected] == value)
  48. return;
  49. [email protected] = value;
  50. if (native != null)
  51. native.BreakTorque = value;
  52. }
  53. }
  54. /// <summary>
  55. /// Determines whether collisions between the two bodies managed by the joint are enabled.
  56. /// </summary>
  57. public bool EnableCollision
  58. {
  59. get { return [email protected]; }
  60. set
  61. {
  62. if ([email protected] == value)
  63. return;
  64. [email protected] = value;
  65. if (native != null)
  66. native.EnableCollision = value;
  67. }
  68. }
  69. /// <summary>
  70. /// Returns one of the bodies managed by the joint.
  71. /// </summary>
  72. /// <param name="body">Which of the rigidbodies to return.</param>
  73. /// <returns>Rigidbody managed by the joint, or null if none.</returns>
  74. public Rigidbody GetRigidbody(JointBody body)
  75. {
  76. return commonData.bodies[(int) body];
  77. }
  78. /// <summary>
  79. /// Sets a body managed by the joint. One of the bodies must be movable (non-kinematic).
  80. /// </summary>
  81. /// <param name="body">Which of the rigidbodies to set.</param>
  82. /// <param name="rigidbody">Rigidbody to managed by the joint, or null. If one of the bodies is null the other
  83. /// one will be anchored globally to the position/rotation set by <see cref="SetPosition"/>
  84. /// and <see cref="SetRotation"/>.</param>
  85. public void SetRigidbody(JointBody body, Rigidbody rigidbody)
  86. {
  87. if (commonData.bodies[(int)body] == rigidbody)
  88. return;
  89. if (commonData.bodies[(int)body] != null)
  90. commonData.bodies[(int)body].SetJoint(null);
  91. commonData.bodies[(int)body] = rigidbody;
  92. if (rigidbody != null)
  93. commonData.bodies[(int)body].SetJoint(this);
  94. // If joint already exists, destroy it if we removed all bodies, otherwise update its transform
  95. if (native != null)
  96. {
  97. if (!IsBodyValid(commonData.bodies[0]) && !IsBodyValid(commonData.bodies[0]))
  98. DestroyNative();
  99. else
  100. {
  101. native.SetRigidbody(body, rigidbody);
  102. UpdateTransform(body);
  103. }
  104. }
  105. else // If joint doesn't exist, check if we can create it
  106. {
  107. // Must be an active component and at least one of the bodies must be non-null
  108. if (SceneObject.Active && (IsBodyValid(commonData.bodies[0]) || IsBodyValid(commonData.bodies[0])))
  109. {
  110. RestoreNative();
  111. }
  112. }
  113. }
  114. /// <summary>
  115. /// Returns the position at which the body is anchored to the joint.
  116. /// </summary>
  117. /// <param name="body">Which body to retrieve position for.</param>
  118. /// <returns>Position relative to the body.</returns>
  119. public Vector3 GetPosition(JointBody body)
  120. {
  121. return commonData.positions[(int)body];
  122. }
  123. /// <summary>
  124. /// Sets the position at which the body is anchored to the joint.
  125. /// </summary>
  126. /// <param name="body">Which body set the position for.</param>
  127. /// <param name="position">Position relative to the body.</param>
  128. public void SetPosition(JointBody body, Vector3 position)
  129. {
  130. if (commonData.positions[(int)body] == position)
  131. return;
  132. commonData.positions[(int) body] = position;
  133. if (native != null)
  134. UpdateTransform(body);
  135. }
  136. /// <summary>
  137. /// Returns the rotation at which the body is anchored to the joint.
  138. /// </summary>
  139. /// <param name="body">Which body to retrieve rotation for.</param>
  140. /// <returns>Rotation relative to the body.</returns>
  141. public Quaternion GetRotation(JointBody body)
  142. {
  143. return commonData.rotations[(int)body];
  144. }
  145. /// <summary>
  146. /// Sets the rotation at which the body is anchored to the joint.
  147. /// </summary>
  148. /// <param name="body">Which body set the rotation for.</param>
  149. /// <param name="rotation">Rotation relative to the body.</param>
  150. public void SetRotation(JointBody body, Quaternion rotation)
  151. {
  152. if (commonData.rotations[(int)body] == rotation)
  153. return;
  154. commonData.rotations[(int)body] = rotation;
  155. if (native != null)
  156. UpdateTransform(body);
  157. }
  158. /// <summary>
  159. /// Triggered when the joint breaks.
  160. /// </summary>
  161. internal void DoOnJointBreak()
  162. {
  163. if (OnJointBreak != null)
  164. OnJointBreak();
  165. }
  166. /// <summary>
  167. /// Notifies the joint that one of the attached rigidbodies moved and that its transform needs updating.
  168. /// </summary>
  169. /// <param name="body">Rigidbody that moved.</param>
  170. internal void NotifyRigidbodyMoved(Rigidbody body)
  171. {
  172. if (native == null)
  173. return;
  174. // If physics update is in progress do nothing, as its the joint itself that's probably moving the body
  175. if (Physics.IsUpdateInProgress)
  176. return;
  177. if (commonData.bodies[0] == body)
  178. UpdateTransform(JointBody.Target);
  179. else if (commonData.bodies[1] == body)
  180. UpdateTransform(JointBody.Anchor);
  181. }
  182. /// <summary>
  183. /// Creates the internal representation of the Joint for use by the component.
  184. /// </summary>
  185. /// <returns>New native joint object.</returns>
  186. internal abstract NativeJoint CreateNative();
  187. private void OnInitialize()
  188. {
  189. NotifyFlags = TransformChangedFlags.Transform | TransformChangedFlags.Parent;
  190. }
  191. private void OnEnable()
  192. {
  193. if(IsBodyValid(commonData.bodies[0]) || IsBodyValid(commonData.bodies[1]))
  194. RestoreNative();
  195. }
  196. private void OnDisable()
  197. {
  198. DestroyNative();
  199. }
  200. private void OnDestroy()
  201. {
  202. if (commonData.bodies[0] != null)
  203. commonData.bodies[0].SetJoint(null);
  204. if (commonData.bodies[1] != null)
  205. commonData.bodies[1].SetJoint(null);
  206. DestroyNative();
  207. }
  208. private void OnTransformChanged(TransformChangedFlags flags)
  209. {
  210. if (native == null)
  211. return;
  212. // We're ignoring this during physics update because it would cause problems if the joint itself was moved by physics
  213. // Note: This isn't particularily correct because if the joint is being moved by physics but the rigidbodies
  214. // themselves are not parented to the joint, the transform will need updating. However I'm leaving it up to the
  215. // user to ensure rigidbodies are always parented to the joint in such a case (It's an unlikely situation that
  216. // I can't think of an use for - joint transform will almost always be set as an initialization step and not a
  217. // physics response).
  218. if (Physics.IsUpdateInProgress)
  219. return;
  220. UpdateTransform(JointBody.Target);
  221. UpdateTransform(JointBody.Anchor);
  222. }
  223. /// <summary>
  224. /// Creates the internal representation of the Joint and restores the values saved by the Component.
  225. /// </summary>
  226. private void RestoreNative()
  227. {
  228. [email protected][0] = IntPtr.Zero;
  229. [email protected][1] = IntPtr.Zero;
  230. if (commonData.bodies[0] != null)
  231. {
  232. NativeRigidbody nativeBody = commonData.bodies[0].native;
  233. if (nativeBody != null)
  234. [email protected][0] = nativeBody.GetCachedPtr();
  235. }
  236. if (commonData.bodies[1] != null)
  237. {
  238. NativeRigidbody nativeBody = commonData.bodies[1].native;
  239. if (nativeBody != null)
  240. [email protected][1] = nativeBody.GetCachedPtr();
  241. }
  242. GetLocalTransform(JointBody.Target, out [email protected][0], out [email protected][0]);
  243. GetLocalTransform(JointBody.Anchor, out [email protected][1], out [email protected][1]);
  244. native = CreateNative();
  245. native.Component = this;
  246. }
  247. /// <summary>
  248. /// Destroys the internal joint representation.
  249. /// </summary>
  250. private void DestroyNative()
  251. {
  252. if (native != null)
  253. {
  254. native.Destroy();
  255. native = null;
  256. }
  257. }
  258. /// <summary>
  259. /// Checks can the provided rigidbody be used for initializing the joint.
  260. /// </summary>
  261. /// <param name="body">Body to check.</param>
  262. /// <returns>True if the body can be used for initializing the joint, false otherwise.</returns>
  263. private bool IsBodyValid(Rigidbody body)
  264. {
  265. if (body == null)
  266. return false;
  267. if (body.native == null)
  268. return false;
  269. return true;
  270. }
  271. /// <summary>
  272. /// Calculates the local position/rotation that needs to be applied to the particular joint body.
  273. /// </summary>
  274. /// <param name="body">Body to calculate the transform for.</param>
  275. /// <param name="position">Output position for the body.</param>
  276. /// <param name="rotation">Output rotation for the body.</param>
  277. private void GetLocalTransform(JointBody body, out Vector3 position, out Quaternion rotation)
  278. {
  279. position = commonData.positions[(int)body];
  280. rotation = commonData.rotations[(int)body];
  281. Rigidbody rigidbody = commonData.bodies[(int)body];
  282. if (rigidbody == null) // Get world space transform if no relative to any body
  283. {
  284. Quaternion worldRot = SceneObject.Rotation;
  285. rotation = worldRot*rotation;
  286. position = worldRot.Rotate(position) + SceneObject.Position;
  287. }
  288. else
  289. {
  290. position = rotation.Rotate(position);
  291. }
  292. }
  293. /// <summary>
  294. /// Updates the local transform for the specified body attached to the joint.
  295. /// </summary>
  296. /// <param name="body">Body to update.</param>
  297. private void UpdateTransform(JointBody body)
  298. {
  299. Vector3 localPos;
  300. Quaternion localRot;
  301. GetLocalTransform(body, out localPos, out localRot);
  302. native.SetPosition(body, localPos);
  303. native.SetRotation(body, localRot);
  304. }
  305. /// <summary>
  306. /// Holds all data the joint component needs to persist through serialization.
  307. /// </summary>
  308. [SerializeObject]
  309. internal class SerializableData
  310. {
  311. public ScriptCommonJointData @internal;
  312. public SerializableData()
  313. {
  314. @internal.bodies = new IntPtr[2];
  315. @internal.positions = new Vector3[2] { Vector3.Zero, Vector3.Zero };
  316. @internal.rotations = new Quaternion[2] { Quaternion.Identity, Quaternion.Identity };
  317. @internal.breakForce = float.MaxValue;
  318. @internal.breakTorque = float.MaxValue;
  319. @internal.enableCollision = false;
  320. }
  321. public Rigidbody[] bodies = new Rigidbody[2];
  322. public Vector3[] positions = new Vector3[2] { Vector3.Zero, Vector3.Zero };
  323. public Quaternion[] rotations = new Quaternion[2] { Quaternion.Identity, Quaternion.Identity };
  324. }
  325. }
  326. /// <summary>
  327. /// Controls spring parameters for a physics joint limits. If a limit is soft (body bounces back due to restitution when
  328. /// the limit is reached) the spring will pull the body back towards the limit using the specified parameters.
  329. /// </summary>
  330. [StructLayout(LayoutKind.Sequential), SerializeObject]
  331. public struct Spring // Note: Must match C++ struct Spring
  332. {
  333. /// <summary>
  334. /// Constructs a spring.
  335. /// </summary>
  336. /// <param name="stiffness">Spring strength.Force proportional to the position error.</param>
  337. /// <param name="damping">Damping strength. Force propertional to the velocity error.</param>
  338. public Spring(float stiffness, float damping)
  339. {
  340. this.stiffness = stiffness;
  341. this.damping = damping;
  342. }
  343. /// <inheritdoc/>
  344. public override bool Equals(object rhs)
  345. {
  346. if (rhs is Spring)
  347. {
  348. Spring other = (Spring)rhs;
  349. return stiffness == other.stiffness && damping == other.damping;
  350. }
  351. return false;
  352. }
  353. /// <inheritdoc/>
  354. public override int GetHashCode()
  355. {
  356. return base.GetHashCode();
  357. }
  358. public static bool operator ==(Spring a, Spring b)
  359. {
  360. return a.Equals(b);
  361. }
  362. public static bool operator !=(Spring a, Spring b)
  363. {
  364. return !(a == b);
  365. }
  366. /// <summary>
  367. /// Spring strength. Force proportional to the position error.
  368. /// </summary>
  369. public float stiffness;
  370. /// <summary>
  371. /// Damping strength. Force propertional to the velocity error.
  372. /// </summary>
  373. public float damping;
  374. }
  375. /// <summary>
  376. /// Specifies first or second body referenced by a Joint.
  377. /// </summary>
  378. public enum JointBody
  379. {
  380. /// <summary>
  381. /// Body the joint is influencing.
  382. /// </summary>
  383. Target,
  384. /// <summary>
  385. /// Body to which the joint is attached to (if any).
  386. /// </summary>
  387. Anchor
  388. };
  389. /// <summary>
  390. /// Specifies axes that the D6 joint can constrain motion on.
  391. /// </summary>
  392. public enum D6JointAxis
  393. {
  394. /// <summary>
  395. /// Movement on the X axis.
  396. /// </summary>
  397. X,
  398. /// <summary>
  399. /// Movement on the Y axis.
  400. /// </summary>
  401. Y,
  402. /// <summary>
  403. /// Movement on the Z axis.
  404. /// </summary>
  405. Z,
  406. /// <summary>
  407. /// Rotation around the X axis.
  408. /// </summary>
  409. Twist,
  410. /// <summary>
  411. /// Rotation around the Y axis.
  412. /// </summary>
  413. SwingY,
  414. /// <summary>
  415. /// Rotation around the Z axis.
  416. /// </summary>
  417. SwingZ,
  418. Count
  419. }
  420. /// <summary>
  421. /// Specifies type of constraint placed on a specific axis of a D6 joint.
  422. /// </summary>
  423. public enum D6JointMotion
  424. {
  425. /// <summary>
  426. /// Axis is immovable.
  427. /// </summary>
  428. Locked,
  429. /// <summary>
  430. /// Axis will be constrained by the specified limits.
  431. /// </summary>
  432. Limited,
  433. /// <summary>
  434. /// Axis will not be constrained.
  435. /// </summary>
  436. Free,
  437. Count
  438. }
  439. /// <summary>
  440. /// Type of drives that can be used for moving or rotating bodies attached to the D6 joint.
  441. /// </summary>
  442. public enum D6JointDriveType
  443. {
  444. /// <summary>
  445. /// Linear movement on the X axis using the linear drive model.
  446. /// </summary>
  447. X,
  448. /// <summary>
  449. /// Linear movement on the Y axis using the linear drive model.
  450. /// </summary>
  451. Y,
  452. /// <summary>
  453. /// Linear movement on the Z axis using the linear drive model.
  454. /// </summary>
  455. Z,
  456. /// <summary>
  457. /// Rotation around the Y axis using the twist/swing angular drive model. Should not be used together with
  458. /// SLERP mode.
  459. /// </summary>
  460. Swing,
  461. /// <summary>
  462. /// Rotation around the Z axis using the twist/swing angular drive model. Should not be used together with
  463. /// SLERP mode.
  464. /// </summary>
  465. Twist,
  466. /// <summary>
  467. /// Rotation using spherical linear interpolation. Uses the SLERP angular drive mode which performs rotation
  468. /// by interpolating the quaternion values directly over the shortest path (applies to all three axes, which
  469. /// they all must be unlocked).
  470. /// </summary>
  471. SLERP,
  472. Count
  473. }
  474. /// <summary>
  475. /// Specifies parameters for a drive that will attempt to move the D6 joint bodies to the specified drive position and
  476. /// velocity.
  477. /// </summary>
  478. [SerializeObject]
  479. public class D6JointDrive
  480. {
  481. [SerializeField]
  482. private D6JointDriveData data;
  483. /// <summary>
  484. /// Spring strength. Force proportional to the position error.
  485. /// </summary>
  486. public float Stiffness { get { return data.stiffness; } }
  487. /// <summary>
  488. /// Damping strength. Force propertional to the velocity error.
  489. /// </summary>
  490. public float Damping { get { return data.damping; } }
  491. /// <summary>
  492. /// Maximum force the drive can apply.
  493. /// </summary>
  494. public float ForceLimit { get { return data.forceLimit; } }
  495. /// <summary>
  496. /// If true the drive will generate acceleration instead of forces. Acceleration drives are easier to tune as
  497. /// they account for the masses of the actors to which the joint is attached.
  498. /// </summary>
  499. public bool Acceleration { get { return data.acceleration; } }
  500. /// <summary>
  501. /// Gets drive properties.
  502. /// </summary>
  503. public D6JointDriveData Data
  504. {
  505. get { return data; }
  506. }
  507. /// <summary>
  508. /// Constructs a new D6 joint drive.
  509. /// </summary>
  510. /// <param name="stiffness"><see cref="Stiffness"/></param>
  511. /// <param name="damping"><see cref="Damping"/></param>
  512. /// <param name="forceLimit"><see cref="ForceLimit"/></param>
  513. /// <param name="acceleration"><see cref="Acceleration"/></param>
  514. public D6JointDrive(float stiffness = 0.0f, float damping = 0.0f, float forceLimit = float.MaxValue,
  515. bool acceleration = false)
  516. {
  517. data.stiffness = stiffness;
  518. data.damping = damping;
  519. data.forceLimit = forceLimit;
  520. data.acceleration = acceleration;
  521. }
  522. /// <summary>
  523. /// Constructs a new D6 joint drive.
  524. /// </summary>
  525. /// <param name="data">Properties to initialize the drive with.</param>
  526. public D6JointDrive(D6JointDriveData data)
  527. {
  528. this.data = data;
  529. }
  530. /// <inheritdoc/>
  531. public override bool Equals(object rhs)
  532. {
  533. if (rhs is D6JointDrive)
  534. {
  535. D6JointDrive other = (D6JointDrive)rhs;
  536. return Stiffness == other.Stiffness && Damping == other.Damping && ForceLimit == other.ForceLimit
  537. && Acceleration == other.Acceleration;
  538. }
  539. return false;
  540. }
  541. /// <inheritdoc/>
  542. public override int GetHashCode()
  543. {
  544. return base.GetHashCode();
  545. }
  546. public static bool operator ==(D6JointDrive a, D6JointDrive b)
  547. {
  548. return a.Equals(b);
  549. }
  550. public static bool operator !=(D6JointDrive a, D6JointDrive b)
  551. {
  552. return !(a == b);
  553. }
  554. /// <summary>
  555. /// Used for accessing drive data from native code.
  556. /// </summary>
  557. /// <returns>Native readable drive structure.</returns>
  558. private D6JointDriveData Internal_GetNative()
  559. {
  560. return data;
  561. }
  562. }
  563. /// <summary>
  564. /// Properties of a drive that drives the hinge joint's angular velocity towards a paricular value.
  565. /// </summary>
  566. [SerializeObject]
  567. public class HingeJointDrive
  568. {
  569. [SerializeField]
  570. private HingeJointDriveData data;
  571. /// <summary>
  572. /// Target speed of the joint.
  573. /// </summary>
  574. public float Speed { get { return data.speed; } }
  575. /// <summary>
  576. /// Maximum torque the drive is allowed to apply.
  577. /// </summary>
  578. public float ForceLimit { get { return data.forceLimit; } }
  579. /// <summary>
  580. /// Scales the velocity of the first body, and its response to drive torque is scaled down.
  581. /// </summary>
  582. public float GearRatio { get { return data.gearRatio; } }
  583. /// <summary>
  584. /// If the joint is moving faster than the drive's target speed, the drive will try to break. If you don't want
  585. /// the breaking to happen set this to true.
  586. /// </summary>
  587. public bool FreeSpin { get { return data.freeSpin; } }
  588. /// <summary>
  589. /// Gets drive properties.
  590. /// </summary>
  591. public HingeJointDriveData Data
  592. {
  593. get { return data; }
  594. }
  595. /// <summary>
  596. /// Constructs a new hinge joint drive.
  597. /// </summary>
  598. /// <param name="speed"><see cref="Speed"/></param>
  599. /// <param name="forceLimit"><see cref="ForceLimit"/></param>
  600. /// <param name="gearRatio"><see cref="GearRatio"/></param>
  601. /// <param name="freeSpin"><see cref="FreeSpin"/></param>
  602. public HingeJointDrive(float speed = 0.0f, float forceLimit = float.MaxValue,
  603. float gearRatio = 1.0f, bool freeSpin = false)
  604. {
  605. data.speed = speed;
  606. data.forceLimit = forceLimit;
  607. data.gearRatio = gearRatio;
  608. data.freeSpin = freeSpin;
  609. }
  610. /// <summary>
  611. /// Constructs a new hinge joint drive.
  612. /// </summary>
  613. /// <param name="data">Properties to initialize the drive with.</param>
  614. public HingeJointDrive(HingeJointDriveData data)
  615. {
  616. this.data = data;
  617. }
  618. /// <inheritdoc/>
  619. public override bool Equals(object rhs)
  620. {
  621. if (rhs is HingeJointDrive)
  622. {
  623. HingeJointDrive other = (HingeJointDrive)rhs;
  624. return data.speed == other.data.speed && data.gearRatio == other.data.gearRatio &&
  625. data.forceLimit == other.data.forceLimit && data.freeSpin == other.data.freeSpin;
  626. }
  627. return false;
  628. }
  629. /// <inheritdoc/>
  630. public override int GetHashCode()
  631. {
  632. return base.GetHashCode();
  633. }
  634. public static bool operator ==(HingeJointDrive a, HingeJointDrive b)
  635. {
  636. return a.Equals(b);
  637. }
  638. public static bool operator !=(HingeJointDrive a, HingeJointDrive b)
  639. {
  640. return !(a == b);
  641. }
  642. /// <summary>
  643. /// Used for accessing drive data from native code.
  644. /// </summary>
  645. /// <returns>Native readable drive structure.</returns>
  646. private HingeJointDriveData Internal_GetNative()
  647. {
  648. return data;
  649. }
  650. };
  651. /// <summary>
  652. /// Contains common values used by all Joint limit types.
  653. /// </summary>
  654. [SerializeObject]
  655. public class LimitCommon
  656. {
  657. private LimitCommonData data;
  658. /// <summary>
  659. /// Distance from the limit at which it becomes active. Allows the solver to activate earlier than the limit is
  660. /// reached to avoid breaking the limit.
  661. /// </summary>
  662. public float ContactDist { get { return data.contactDist; } }
  663. /// <summary>
  664. /// Controls how do objects react when the limit is reached, values closer to zero specify non-ellastic collision,
  665. /// while those closer to one specify more ellastic(i.e bouncy) collision.Must be in [0, 1] range.
  666. /// </summary>
  667. public float Restitution { get { return data.restitution; } }
  668. /// <summary>
  669. /// Spring that controls how are the bodies pulled back towards the limit when they breach it.
  670. /// </summary>
  671. public Spring Spring { get { return data.spring; } }
  672. /// <summary>
  673. /// Gets properties common to all limit types.
  674. /// </summary>
  675. public LimitCommonData CommonData
  676. {
  677. get { return data; }
  678. }
  679. protected LimitCommon(float contactDist = -1.0f)
  680. {
  681. data.contactDist = contactDist;
  682. data.restitution = 0.0f;
  683. data.spring = new Spring();
  684. }
  685. protected LimitCommon(Spring spring, float restitution = 0.0f)
  686. {
  687. data.contactDist = -1.0f;
  688. data.restitution = restitution;
  689. data.spring = spring;
  690. }
  691. protected LimitCommon(LimitCommonData data)
  692. {
  693. this.data = data;
  694. }
  695. /// <inheritdoc/>
  696. public override bool Equals(object rhs)
  697. {
  698. if (rhs is LimitCommon)
  699. {
  700. LimitCommon other = (LimitCommon)rhs;
  701. return ContactDist == other.ContactDist && Restitution == other.Restitution && Spring == other.Spring;
  702. }
  703. return false;
  704. }
  705. /// <inheritdoc/>
  706. public override int GetHashCode()
  707. {
  708. return base.GetHashCode();
  709. }
  710. public static bool operator ==(LimitCommon a, LimitCommon b)
  711. {
  712. return a.Equals(b);
  713. }
  714. public static bool operator !=(LimitCommon a, LimitCommon b)
  715. {
  716. return !(a == b);
  717. }
  718. }
  719. /// <summary>
  720. /// Represents a joint limit between two distance values. Lower value must be less than the upper value.
  721. /// </summary>
  722. [SerializeObject]
  723. public class LimitLinearRange : LimitCommon
  724. {
  725. private LimitLinearRangeData data;
  726. /// <summary>
  727. /// Lower distance of the limit. Must be less than <see cref="Upper"/>.
  728. /// </summary>
  729. public float Lower { get { return data.lower; } }
  730. /// <summary>
  731. /// Upper distance of the limit. Must be greater than <see cref="Lower"/>.
  732. /// </summary>
  733. public float Upper { get { return data.upper; } }
  734. /// <summary>
  735. /// Gets properties of the linear limit range.
  736. /// </summary>
  737. public LimitLinearRangeData Data
  738. {
  739. get { return data; }
  740. }
  741. /// <summary>
  742. /// Constructs an empty limit.
  743. /// </summary>
  744. public LimitLinearRange()
  745. { }
  746. /// <summary>
  747. /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
  748. /// </summary>
  749. /// <param name="lower"><see cref="Lower"/></param>
  750. /// <param name="upper"><see cref="Upper"/></param>
  751. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  752. public LimitLinearRange(float lower, float upper, float contactDist = -1.0f)
  753. :base(contactDist)
  754. {
  755. data.lower = lower;
  756. data.upper = upper;
  757. }
  758. /// <summary>
  759. /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
  760. /// parameter and will be pulled back towards the limit by the provided spring.
  761. /// </summary>
  762. /// <param name="lower"><see cref="Lower"/></param>
  763. /// <param name="upper"><see cref="Upper"/></param>
  764. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  765. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  766. public LimitLinearRange(float lower, float upper, Spring spring, float restitution = 0.0f)
  767. :base(spring, restitution)
  768. {
  769. data.lower = lower;
  770. data.upper = upper;
  771. }
  772. /// <summary>
  773. /// Constructs a new limit from the provided properties.
  774. /// </summary>
  775. /// <param name="limitData">Linear range specific properties.</param>
  776. /// <param name="commonData">Properties common to all limit types.</param>
  777. public LimitLinearRange(LimitLinearRangeData limitData, LimitCommonData commonData)
  778. :base(commonData)
  779. {
  780. this.data = limitData;
  781. }
  782. /// <inheritdoc/>
  783. public override bool Equals(object rhs)
  784. {
  785. if (rhs is LimitLinearRange)
  786. {
  787. LimitLinearRange other = (LimitLinearRange)rhs;
  788. return base.Equals(rhs) && Lower == other.Lower && Upper == other.Upper;
  789. }
  790. return false;
  791. }
  792. /// <inheritdoc/>
  793. public override int GetHashCode()
  794. {
  795. return base.GetHashCode();
  796. }
  797. public static bool operator ==(LimitLinearRange a, LimitLinearRange b)
  798. {
  799. return a.Equals(b);
  800. }
  801. public static bool operator !=(LimitLinearRange a, LimitLinearRange b)
  802. {
  803. return !(a == b);
  804. }
  805. /// <summary>
  806. /// Used for accessing limit data from native code.
  807. /// </summary>
  808. /// <returns>Native readable limit structure.</returns>
  809. private ScriptLimitLinearRange Internal_GetNative()
  810. {
  811. ScriptLimitLinearRange output;
  812. output.contactDist = ContactDist;
  813. output.restitution = Restitution;
  814. output.spring = Spring;
  815. output.lower = Lower;
  816. output.upper = Upper;
  817. return output;
  818. }
  819. }
  820. /// <summary>
  821. /// Represents a joint limit between zero a single distance value.
  822. /// </summary>
  823. [SerializeObject]
  824. public class LimitLinear : LimitCommon
  825. {
  826. private LimitLinearData data;
  827. /// <summary>
  828. /// Distance at which the limit becomes active.
  829. /// </summary>
  830. public float Extent { get { return data.extent; } }
  831. /// <summary>
  832. /// Gets properties of the linear limit.
  833. /// </summary>
  834. public LimitLinearData Data
  835. {
  836. get { return data; }
  837. }
  838. /// <summary>
  839. /// Constructs an empty limit.
  840. /// </summary>
  841. public LimitLinear()
  842. { }
  843. /// <summary>
  844. /// Constructs a hard limit.Once the limit is reached the movement of the attached bodies will come to a stop.
  845. /// </summary>
  846. /// <param name="extent"><see cref="Extent"/></param>
  847. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  848. public LimitLinear(float extent, float contactDist = -1.0f)
  849. :base(contactDist)
  850. {
  851. data.extent = extent;
  852. }
  853. /// <summary>
  854. /// Constructs a soft limit.Once the limit is reached the bodies will bounce back according to the resitution
  855. /// parameter and will be pulled back towards the limit by the provided spring.
  856. /// </summary>
  857. /// <param name="extent"><see cref="Extent"/></param>
  858. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  859. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  860. public LimitLinear(float extent, Spring spring, float restitution = 0.0f)
  861. :base(spring, restitution)
  862. {
  863. data.extent = extent;
  864. }
  865. /// <summary>
  866. /// Constructs a new limit from the provided properties.
  867. /// </summary>
  868. /// <param name="limitData">Linear limit specific properties.</param>
  869. /// <param name="commonData">Properties common to all limit types.</param>
  870. public LimitLinear(LimitLinearData limitData, LimitCommonData commonData)
  871. :base(commonData)
  872. {
  873. this.data = limitData;
  874. }
  875. /// <inheritdoc/>
  876. public override bool Equals(object rhs)
  877. {
  878. if (rhs is LimitLinear)
  879. {
  880. LimitLinear other = (LimitLinear)rhs;
  881. return base.Equals(rhs) && Extent == other.Extent;
  882. }
  883. return false;
  884. }
  885. /// <inheritdoc/>
  886. public override int GetHashCode()
  887. {
  888. return base.GetHashCode();
  889. }
  890. public static bool operator ==(LimitLinear a, LimitLinear b)
  891. {
  892. return a.Equals(b);
  893. }
  894. public static bool operator !=(LimitLinear a, LimitLinear b)
  895. {
  896. return !(a == b);
  897. }
  898. /// <summary>
  899. /// Used for accessing limit data from native code.
  900. /// </summary>
  901. /// <returns>Native readable limit structure.</returns>
  902. private ScriptLimitLinear Internal_GetNative()
  903. {
  904. ScriptLimitLinear output;
  905. output.contactDist = ContactDist;
  906. output.restitution = Restitution;
  907. output.spring = Spring;
  908. output.extent = Extent;
  909. return output;
  910. }
  911. }
  912. /// <summary>
  913. /// Represents a joint limit between two angles.
  914. /// </summary>
  915. [SerializeObject]
  916. public class LimitAngularRange : LimitCommon
  917. {
  918. private LimitAngularRangeData data;
  919. /// <summary>
  920. /// Lower angle of the limit. Must be less than <see cref="Upper"/>.
  921. /// </summary>
  922. public Radian Lower { get { return data.lower; } }
  923. /// <summary>
  924. /// Upper angle of the limit. Must be greater than <see cref="Lower"/>.
  925. /// </summary>
  926. public Radian Upper { get { return data.upper; } }
  927. /// <summary>
  928. /// Gets properties of the angular limit range.
  929. /// </summary>
  930. public LimitAngularRangeData Data
  931. {
  932. get { return data; }
  933. }
  934. /// <summary>
  935. /// Constructs an empty limit.
  936. /// </summary>
  937. public LimitAngularRange()
  938. { }
  939. /// <summary>
  940. /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
  941. /// </summary>
  942. /// <param name="lower"><see cref="Lower"/></param>
  943. /// <param name="upper"><see cref="Upper"/></param>
  944. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  945. public LimitAngularRange(Radian lower, Radian upper, float contactDist = -1.0f)
  946. : base(contactDist)
  947. {
  948. data.lower = lower;
  949. data.upper = upper;
  950. }
  951. /// <summary>
  952. /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
  953. /// parameter and will be pulled back towards the limit by the provided spring.
  954. /// </summary>
  955. /// <param name="lower"><see cref="Lower"/></param>
  956. /// <param name="upper"><see cref="Upper"/></param>
  957. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  958. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  959. public LimitAngularRange(Radian lower, Radian upper, Spring spring, float restitution = 0.0f)
  960. : base(spring, restitution)
  961. {
  962. data.lower = lower;
  963. data.upper = upper;
  964. }
  965. /// <summary>
  966. /// Constructs a new limit from the provided properties.
  967. /// </summary>
  968. /// <param name="limitData">Angular limit range specific properties.</param>
  969. /// <param name="commonData">Properties common to all limit types.</param>
  970. public LimitAngularRange(LimitAngularRangeData limitData, LimitCommonData commonData)
  971. :base(commonData)
  972. {
  973. this.data = limitData;
  974. }
  975. /// <inheritdoc/>
  976. public override bool Equals(object rhs)
  977. {
  978. if (rhs is LimitAngularRange)
  979. {
  980. LimitAngularRange other = (LimitAngularRange)rhs;
  981. return base.Equals(rhs) && Lower == other.Lower && Upper == other.Upper;
  982. }
  983. return false;
  984. }
  985. /// <inheritdoc/>
  986. public override int GetHashCode()
  987. {
  988. return base.GetHashCode();
  989. }
  990. public static bool operator ==(LimitAngularRange a, LimitAngularRange b)
  991. {
  992. return a.Equals(b);
  993. }
  994. public static bool operator !=(LimitAngularRange a, LimitAngularRange b)
  995. {
  996. return !(a == b);
  997. }
  998. /// <summary>
  999. /// Used for accessing limit data from native code.
  1000. /// </summary>
  1001. /// <returns>Native readable limit structure.</returns>
  1002. private ScriptLimitAngularRange Internal_GetNative()
  1003. {
  1004. ScriptLimitAngularRange output;
  1005. output.contactDist = ContactDist;
  1006. output.restitution = Restitution;
  1007. output.spring = Spring;
  1008. output.lower = Lower;
  1009. output.upper = Upper;
  1010. return output;
  1011. }
  1012. }
  1013. /// <summary>
  1014. /// Represents a joint limit that contraints movement to within an elliptical cone.
  1015. /// </summary>
  1016. [SerializeObject]
  1017. public class LimitConeRange : LimitCommon
  1018. {
  1019. private LimitConeRangeData data;
  1020. /// <summary>
  1021. /// Y angle of the cone. Movement is constrainted between 0 and this angle on the Y axis.
  1022. /// </summary>
  1023. public Radian YLimitAngle { get { return data.yLimitAngle; } }
  1024. /// <summary>
  1025. /// Z angle of the cone. Movement is constrainted between 0 and this angle on the Z axis.
  1026. /// </summary>
  1027. public Radian ZLimitAngle { get { return data.zLimitAngle; } }
  1028. /// <summary>
  1029. /// Gets properties of the cone limit range.
  1030. /// </summary>
  1031. public LimitConeRangeData Data
  1032. {
  1033. get { return data; }
  1034. }
  1035. /// <summary>
  1036. /// Constructs a limit with a 45 degree cone.
  1037. /// </summary>
  1038. public LimitConeRange()
  1039. {
  1040. data.yLimitAngle = new Radian(MathEx.Pi * 0.5f);
  1041. data.zLimitAngle = new Radian(MathEx.Pi * 0.5f);
  1042. }
  1043. /// <summary>
  1044. /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
  1045. /// </summary>
  1046. /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
  1047. /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
  1048. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  1049. public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, float contactDist = -1.0f)
  1050. : base(contactDist)
  1051. {
  1052. data.yLimitAngle = yLimitAngle;
  1053. data.zLimitAngle = zLimitAngle;
  1054. }
  1055. /// <summary>
  1056. /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
  1057. /// parameter and will be pulled back towards the limit by the provided spring.
  1058. /// </summary>
  1059. /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
  1060. /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
  1061. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  1062. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  1063. public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, Spring spring, float restitution = 0.0f)
  1064. : base(spring, restitution)
  1065. {
  1066. data.yLimitAngle = yLimitAngle;
  1067. data.zLimitAngle = zLimitAngle;
  1068. }
  1069. /// <summary>
  1070. /// Constructs a new limit from the provided properties.
  1071. /// </summary>
  1072. /// <param name="limitData">Cone limit range specific properties.</param>
  1073. /// <param name="commonData">Properties common to all limit types.</param>
  1074. public LimitConeRange(LimitConeRangeData limitData, LimitCommonData commonData)
  1075. :base(commonData)
  1076. {
  1077. this.data = limitData;
  1078. }
  1079. /// <inheritdoc/>
  1080. public override bool Equals(object rhs)
  1081. {
  1082. if (rhs is LimitConeRange)
  1083. {
  1084. LimitConeRange other = (LimitConeRange)rhs;
  1085. return base.Equals(rhs) && YLimitAngle == other.YLimitAngle && ZLimitAngle == other.ZLimitAngle;
  1086. }
  1087. return false;
  1088. }
  1089. /// <inheritdoc/>
  1090. public override int GetHashCode()
  1091. {
  1092. return base.GetHashCode();
  1093. }
  1094. public static bool operator ==(LimitConeRange a, LimitConeRange b)
  1095. {
  1096. return a.Equals(b);
  1097. }
  1098. public static bool operator !=(LimitConeRange a, LimitConeRange b)
  1099. {
  1100. return !(a == b);
  1101. }
  1102. /// <summary>
  1103. /// Used for accessing limit data from native code.
  1104. /// </summary>
  1105. /// <returns>Native readable limit structure.</returns>
  1106. private ScriptLimitConeRange Internal_GetNative()
  1107. {
  1108. ScriptLimitConeRange output;
  1109. output.contactDist = ContactDist;
  1110. output.restitution = Restitution;
  1111. output.spring = Spring;
  1112. output.yLimitAngle = YLimitAngle;
  1113. output.zLimitAngle = ZLimitAngle;
  1114. return output;
  1115. }
  1116. }
  1117. /// <summary>
  1118. /// Contains data used by HingeJointDrive.
  1119. /// </summary>
  1120. [StructLayout(LayoutKind.Sequential)]
  1121. public struct HingeJointDriveData // Note: Must match C++ struct HingeJoint::Drive
  1122. {
  1123. /// <summary>
  1124. /// <see cref="HingeJointDrive.Speed"/>
  1125. /// </summary>
  1126. public float speed;
  1127. /// <summary>
  1128. /// <see cref="HingeJointDrive.ForceLimit"/>
  1129. /// </summary>
  1130. public float forceLimit;
  1131. /// <summary>
  1132. /// <see cref="HingeJointDrive.GearRatio"/>
  1133. /// </summary>
  1134. public float gearRatio;
  1135. /// <summary>
  1136. /// <see cref="HingeJointDrive.FreeSpin"/>
  1137. /// </summary>
  1138. public bool freeSpin;
  1139. }
  1140. /// <summary>
  1141. /// Contains data used by D6JointDrive.
  1142. /// </summary>
  1143. [StructLayout(LayoutKind.Sequential)]
  1144. public struct D6JointDriveData // Note: Must match C++ struct D6Joint::Drive
  1145. {
  1146. /// <summary>
  1147. /// <see cref="D6JointDrive.Stiffness"/>
  1148. /// </summary>
  1149. public float stiffness;
  1150. /// <summary>
  1151. /// <see cref="D6JointDrive.Damping"/>
  1152. /// </summary>
  1153. public float damping;
  1154. /// <summary>
  1155. /// <see cref="D6JointDrive.ForceLimit"/>
  1156. /// </summary>
  1157. public float forceLimit;
  1158. /// <summary>
  1159. /// <see cref="D6JointDrive.Acceleration"/>
  1160. /// </summary>
  1161. public bool acceleration;
  1162. }
  1163. /// <summary>
  1164. /// Contains data used by LimitCommon.
  1165. /// </summary>
  1166. public struct LimitCommonData
  1167. {
  1168. /// <summary>
  1169. /// <see cref="LimitCommon.ContactDist"/>
  1170. /// </summary>
  1171. public float contactDist;
  1172. /// <summary>
  1173. /// <see cref="LimitCommon.Restitution"/>
  1174. /// </summary>
  1175. public float restitution;
  1176. /// <summary>
  1177. /// <see cref="LimitCommon.Spring"/>
  1178. /// </summary>
  1179. public Spring spring;
  1180. }
  1181. /// <summary>
  1182. /// Contains data used by LimitLinearRange.
  1183. /// </summary>
  1184. public struct LimitLinearRangeData
  1185. {
  1186. /// <summary>
  1187. /// <see cref="LimitLinearRange.Lower"/>
  1188. /// </summary>
  1189. public float lower;
  1190. /// <summary>
  1191. /// <see cref="LimitLinearRange.Upper"/>
  1192. /// </summary>
  1193. public float upper;
  1194. }
  1195. /// <summary>
  1196. /// Contains data used by LimitLinear.
  1197. /// </summary>
  1198. public struct LimitLinearData
  1199. {
  1200. /// <summary>
  1201. /// <see cref="LimitLinearRange.Extent"/>
  1202. /// </summary>
  1203. public float extent;
  1204. }
  1205. /// <summary>
  1206. /// Contains data used by LimitAngularRange.
  1207. /// </summary>
  1208. public struct LimitAngularRangeData
  1209. {
  1210. /// <summary>
  1211. /// <see cref="LimitAngularRange.Lower"/>
  1212. /// </summary>
  1213. public Radian lower;
  1214. /// <summary>
  1215. /// <see cref="LimitAngularRange.Upper"/>
  1216. /// </summary>
  1217. public Radian upper;
  1218. }
  1219. /// <summary>
  1220. /// Contains data used by LimitConeRange.
  1221. /// </summary>
  1222. public struct LimitConeRangeData
  1223. {
  1224. /// <summary>
  1225. /// <see cref="LimitConeRange.YLimitAngle"/>
  1226. /// </summary>
  1227. public Radian yLimitAngle;
  1228. /// <summary>
  1229. /// <see cref="LimitConeRange.ZLimitAngle"/>
  1230. /// </summary>
  1231. public Radian zLimitAngle;
  1232. }
  1233. /// <summary>
  1234. /// Used for passing LimitLinearRange data between native and managed code.
  1235. /// </summary>
  1236. [StructLayout(LayoutKind.Sequential)]
  1237. internal struct ScriptLimitLinearRange // Note: Must match C++ struct LimitLinearRange
  1238. {
  1239. public float contactDist;
  1240. public float restitution;
  1241. public Spring spring;
  1242. public float lower;
  1243. public float upper;
  1244. }
  1245. /// <summary>
  1246. /// Used for passing LimitLinear data between native and managed code.
  1247. /// </summary>
  1248. [StructLayout(LayoutKind.Sequential)]
  1249. internal struct ScriptLimitLinear // Note: Must match C++ struct LimitLinear
  1250. {
  1251. public float contactDist;
  1252. public float restitution;
  1253. public Spring spring;
  1254. public float extent;
  1255. }
  1256. /// <summary>
  1257. /// Used for passing LimitAngularRange data between native and managed code.
  1258. /// </summary>
  1259. [StructLayout(LayoutKind.Sequential)]
  1260. internal struct ScriptLimitAngularRange // Note: Must match C++ struct LimitAngularRange
  1261. {
  1262. public float contactDist;
  1263. public float restitution;
  1264. public Spring spring;
  1265. public Radian lower;
  1266. public Radian upper;
  1267. }
  1268. /// <summary>
  1269. /// Used for passing LimitConeRange data between native and managed code.
  1270. /// </summary>
  1271. [StructLayout(LayoutKind.Sequential)]
  1272. internal struct ScriptLimitConeRange // Note: Must match C++ struct LimitConeRange
  1273. {
  1274. public float contactDist;
  1275. public float restitution;
  1276. public Spring spring;
  1277. public Radian yLimitAngle;
  1278. public Radian zLimitAngle;
  1279. }
  1280. /** @} */
  1281. }