Joint.cs 49 KB

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