Joint.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  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. // Make sure to always create a new instance of this array, as IntPtrs don't get serialized
  229. [email protected] = new []{ IntPtr.Zero, 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. protected virtual 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 not 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.positions = new Vector3[2] { Vector3.Zero, Vector3.Zero };
  315. @internal.rotations = new Quaternion[2] { Quaternion.Identity, Quaternion.Identity };
  316. @internal.breakForce = float.MaxValue;
  317. @internal.breakTorque = float.MaxValue;
  318. @internal.enableCollision = false;
  319. }
  320. public Rigidbody[] bodies = new Rigidbody[2];
  321. public Vector3[] positions = new Vector3[2] { Vector3.Zero, Vector3.Zero };
  322. public Quaternion[] rotations = new Quaternion[2] { Quaternion.Identity, Quaternion.Identity };
  323. }
  324. }
  325. /// <summary>
  326. /// Controls spring parameters for a physics joint limits. If a limit is soft (body bounces back due to restitution when
  327. /// the limit is reached) the spring will pull the body back towards the limit using the specified parameters.
  328. /// </summary>
  329. [StructLayout(LayoutKind.Sequential), SerializeObject]
  330. public struct Spring // Note: Must match C++ struct Spring
  331. {
  332. /// <summary>
  333. /// Constructs a spring.
  334. /// </summary>
  335. /// <param name="stiffness">Spring strength.Force proportional to the position error.</param>
  336. /// <param name="damping">Damping strength. Force propertional to the velocity error.</param>
  337. public Spring(float stiffness, float damping)
  338. {
  339. this.stiffness = stiffness;
  340. this.damping = damping;
  341. }
  342. /// <inheritdoc/>
  343. public override bool Equals(object rhs)
  344. {
  345. if (rhs is Spring)
  346. {
  347. Spring other = (Spring)rhs;
  348. return stiffness == other.stiffness && damping == other.damping;
  349. }
  350. return false;
  351. }
  352. /// <inheritdoc/>
  353. public override int GetHashCode()
  354. {
  355. return base.GetHashCode();
  356. }
  357. public static bool operator ==(Spring a, Spring b)
  358. {
  359. return a.Equals(b);
  360. }
  361. public static bool operator !=(Spring a, Spring b)
  362. {
  363. return !(a == b);
  364. }
  365. /// <summary>
  366. /// Spring strength. Force proportional to the position error.
  367. /// </summary>
  368. public float stiffness;
  369. /// <summary>
  370. /// Damping strength. Force propertional to the velocity error.
  371. /// </summary>
  372. public float damping;
  373. }
  374. /// <summary>
  375. /// Specifies first or second body referenced by a Joint.
  376. /// </summary>
  377. public enum JointBody
  378. {
  379. /// <summary>
  380. /// Body the joint is influencing.
  381. /// </summary>
  382. Target,
  383. /// <summary>
  384. /// Body to which the joint is attached to (if any).
  385. /// </summary>
  386. Anchor
  387. };
  388. /// <summary>
  389. /// Specifies axes that the D6 joint can constrain motion on.
  390. /// </summary>
  391. public enum D6JointAxis
  392. {
  393. /// <summary>
  394. /// Movement on the X axis.
  395. /// </summary>
  396. X,
  397. /// <summary>
  398. /// Movement on the Y axis.
  399. /// </summary>
  400. Y,
  401. /// <summary>
  402. /// Movement on the Z axis.
  403. /// </summary>
  404. Z,
  405. /// <summary>
  406. /// Rotation around the X axis.
  407. /// </summary>
  408. Twist,
  409. /// <summary>
  410. /// Rotation around the Y axis.
  411. /// </summary>
  412. SwingY,
  413. /// <summary>
  414. /// Rotation around the Z axis.
  415. /// </summary>
  416. SwingZ,
  417. Count
  418. }
  419. /// <summary>
  420. /// Specifies type of constraint placed on a specific axis of a D6 joint.
  421. /// </summary>
  422. public enum D6JointMotion
  423. {
  424. /// <summary>
  425. /// Axis is immovable.
  426. /// </summary>
  427. Locked,
  428. /// <summary>
  429. /// Axis will be constrained by the specified limits.
  430. /// </summary>
  431. Limited,
  432. /// <summary>
  433. /// Axis will not be constrained.
  434. /// </summary>
  435. Free,
  436. Count
  437. }
  438. /// <summary>
  439. /// Type of drives that can be used for moving or rotating bodies attached to the D6 joint.
  440. /// </summary>
  441. public enum D6JointDriveType
  442. {
  443. /// <summary>
  444. /// Linear movement on the X axis using the linear drive model.
  445. /// </summary>
  446. X,
  447. /// <summary>
  448. /// Linear movement on the Y axis using the linear drive model.
  449. /// </summary>
  450. Y,
  451. /// <summary>
  452. /// Linear movement on the Z axis using the linear drive model.
  453. /// </summary>
  454. Z,
  455. /// <summary>
  456. /// Rotation around the Y axis using the twist/swing angular drive model. Should not be used together with
  457. /// SLERP mode.
  458. /// </summary>
  459. Swing,
  460. /// <summary>
  461. /// Rotation around the Z axis using the twist/swing angular drive model. Should not be used together with
  462. /// SLERP mode.
  463. /// </summary>
  464. Twist,
  465. /// <summary>
  466. /// Rotation using spherical linear interpolation. Uses the SLERP angular drive mode which performs rotation
  467. /// by interpolating the quaternion values directly over the shortest path (applies to all three axes, which
  468. /// they all must be unlocked).
  469. /// </summary>
  470. SLERP,
  471. Count
  472. }
  473. /// <summary>
  474. /// Specifies parameters for a drive that will attempt to move the D6 joint bodies to the specified drive position and
  475. /// velocity.
  476. /// </summary>
  477. [SerializeObject]
  478. public class D6JointDrive
  479. {
  480. [SerializeField]
  481. private D6JointDriveData data;
  482. /// <summary>
  483. /// Spring strength. Force proportional to the position error.
  484. /// </summary>
  485. public float Stiffness { get { return data.stiffness; } }
  486. /// <summary>
  487. /// Damping strength. Force propertional to the velocity error.
  488. /// </summary>
  489. public float Damping { get { return data.damping; } }
  490. /// <summary>
  491. /// Maximum force the drive can apply.
  492. /// </summary>
  493. public float ForceLimit { get { return data.forceLimit; } }
  494. /// <summary>
  495. /// If true the drive will generate acceleration instead of forces. Acceleration drives are easier to tune as
  496. /// they account for the masses of the actors to which the joint is attached.
  497. /// </summary>
  498. public bool Acceleration { get { return data.acceleration; } }
  499. /// <summary>
  500. /// Gets drive properties.
  501. /// </summary>
  502. public D6JointDriveData Data
  503. {
  504. get { return data; }
  505. }
  506. /// <summary>
  507. /// Constructor for deserialization only.
  508. /// </summary>
  509. private D6JointDrive()
  510. { }
  511. /// <summary>
  512. /// Constructs a new D6 joint drive.
  513. /// </summary>
  514. /// <param name="stiffness"><see cref="Stiffness"/></param>
  515. /// <param name="damping"><see cref="Damping"/></param>
  516. /// <param name="forceLimit"><see cref="ForceLimit"/></param>
  517. /// <param name="acceleration"><see cref="Acceleration"/></param>
  518. public D6JointDrive(float stiffness = 0.0f, float damping = 0.0f, float forceLimit = float.MaxValue,
  519. bool acceleration = false)
  520. {
  521. data.stiffness = stiffness;
  522. data.damping = damping;
  523. data.forceLimit = forceLimit;
  524. data.acceleration = acceleration;
  525. }
  526. /// <summary>
  527. /// Constructs a new D6 joint drive.
  528. /// </summary>
  529. /// <param name="data">Properties to initialize the drive with.</param>
  530. public D6JointDrive(D6JointDriveData data)
  531. {
  532. this.data = data;
  533. }
  534. /// <inheritdoc/>
  535. public override bool Equals(object rhs)
  536. {
  537. if (rhs is D6JointDrive)
  538. {
  539. D6JointDrive other = (D6JointDrive)rhs;
  540. return Stiffness == other.Stiffness && Damping == other.Damping && ForceLimit == other.ForceLimit
  541. && Acceleration == other.Acceleration;
  542. }
  543. return false;
  544. }
  545. /// <inheritdoc/>
  546. public override int GetHashCode()
  547. {
  548. return base.GetHashCode();
  549. }
  550. public static bool operator ==(D6JointDrive a, D6JointDrive b)
  551. {
  552. return a.Equals(b);
  553. }
  554. public static bool operator !=(D6JointDrive a, D6JointDrive b)
  555. {
  556. return !(a == b);
  557. }
  558. /// <summary>
  559. /// Used for accessing drive data from native code.
  560. /// </summary>
  561. /// <returns>Native readable drive structure.</returns>
  562. private D6JointDriveData Internal_GetNative()
  563. {
  564. return data;
  565. }
  566. }
  567. /// <summary>
  568. /// Properties of a drive that drives the hinge joint's angular velocity towards a paricular value.
  569. /// </summary>
  570. [SerializeObject]
  571. public class HingeJointDrive
  572. {
  573. [SerializeField]
  574. private HingeJointDriveData data;
  575. /// <summary>
  576. /// Target speed of the joint.
  577. /// </summary>
  578. public float Speed { get { return data.speed; } }
  579. /// <summary>
  580. /// Maximum torque the drive is allowed to apply.
  581. /// </summary>
  582. public float ForceLimit { get { return data.forceLimit; } }
  583. /// <summary>
  584. /// Scales the velocity of the first body, and its response to drive torque is scaled down.
  585. /// </summary>
  586. public float GearRatio { get { return data.gearRatio; } }
  587. /// <summary>
  588. /// If the joint is moving faster than the drive's target speed, the drive will try to break. If you don't want
  589. /// the breaking to happen set this to true.
  590. /// </summary>
  591. public bool FreeSpin { get { return data.freeSpin; } }
  592. /// <summary>
  593. /// Gets drive properties.
  594. /// </summary>
  595. public HingeJointDriveData Data
  596. {
  597. get { return data; }
  598. }
  599. /// <summary>
  600. /// Constructor for deserialization only.
  601. /// </summary>
  602. private HingeJointDrive()
  603. { }
  604. /// <summary>
  605. /// Constructs a new hinge joint drive.
  606. /// </summary>
  607. /// <param name="speed"><see cref="Speed"/></param>
  608. /// <param name="forceLimit"><see cref="ForceLimit"/></param>
  609. /// <param name="gearRatio"><see cref="GearRatio"/></param>
  610. /// <param name="freeSpin"><see cref="FreeSpin"/></param>
  611. public HingeJointDrive(float speed = 0.0f, float forceLimit = float.MaxValue,
  612. float gearRatio = 1.0f, bool freeSpin = false)
  613. {
  614. data.speed = speed;
  615. data.forceLimit = forceLimit;
  616. data.gearRatio = gearRatio;
  617. data.freeSpin = freeSpin;
  618. }
  619. /// <summary>
  620. /// Constructs a new hinge joint drive.
  621. /// </summary>
  622. /// <param name="data">Properties to initialize the drive with.</param>
  623. public HingeJointDrive(HingeJointDriveData data)
  624. {
  625. this.data = data;
  626. }
  627. /// <inheritdoc/>
  628. public override bool Equals(object rhs)
  629. {
  630. if (rhs is HingeJointDrive)
  631. {
  632. HingeJointDrive other = (HingeJointDrive)rhs;
  633. return data.speed == other.data.speed && data.gearRatio == other.data.gearRatio &&
  634. data.forceLimit == other.data.forceLimit && data.freeSpin == other.data.freeSpin;
  635. }
  636. return false;
  637. }
  638. /// <inheritdoc/>
  639. public override int GetHashCode()
  640. {
  641. return base.GetHashCode();
  642. }
  643. public static bool operator ==(HingeJointDrive a, HingeJointDrive b)
  644. {
  645. return a.Equals(b);
  646. }
  647. public static bool operator !=(HingeJointDrive a, HingeJointDrive b)
  648. {
  649. return !(a == b);
  650. }
  651. /// <summary>
  652. /// Used for accessing drive data from native code.
  653. /// </summary>
  654. /// <returns>Native readable drive structure.</returns>
  655. private HingeJointDriveData Internal_GetNative()
  656. {
  657. return data;
  658. }
  659. };
  660. /// <summary>
  661. /// Contains common values used by all Joint limit types.
  662. /// </summary>
  663. [SerializeObject]
  664. public class LimitCommon
  665. {
  666. [SerializeField]
  667. private LimitCommonData data;
  668. /// <summary>
  669. /// Distance from the limit at which it becomes active. Allows the solver to activate earlier than the limit is
  670. /// reached to avoid breaking the limit.
  671. /// </summary>
  672. public float ContactDist { get { return data.contactDist; } }
  673. /// <summary>
  674. /// Controls how do objects react when the limit is reached, values closer to zero specify non-ellastic collision,
  675. /// while those closer to one specify more ellastic(i.e bouncy) collision.Must be in [0, 1] range.
  676. /// </summary>
  677. public float Restitution { get { return data.restitution; } }
  678. /// <summary>
  679. /// Spring that controls how are the bodies pulled back towards the limit when they breach it.
  680. /// </summary>
  681. public Spring Spring { get { return data.spring; } }
  682. /// <summary>
  683. /// Gets properties common to all limit types.
  684. /// </summary>
  685. public LimitCommonData CommonData
  686. {
  687. get { return data; }
  688. }
  689. protected LimitCommon(float contactDist = -1.0f)
  690. {
  691. data.contactDist = contactDist;
  692. data.restitution = 0.0f;
  693. data.spring = new Spring();
  694. }
  695. protected LimitCommon(Spring spring, float restitution = 0.0f)
  696. {
  697. data.contactDist = -1.0f;
  698. data.restitution = restitution;
  699. data.spring = spring;
  700. }
  701. protected LimitCommon(LimitCommonData data)
  702. {
  703. this.data = data;
  704. }
  705. /// <inheritdoc/>
  706. public override bool Equals(object rhs)
  707. {
  708. if (rhs is LimitCommon)
  709. {
  710. LimitCommon other = (LimitCommon)rhs;
  711. return ContactDist == other.ContactDist && Restitution == other.Restitution && Spring == other.Spring;
  712. }
  713. return false;
  714. }
  715. /// <inheritdoc/>
  716. public override int GetHashCode()
  717. {
  718. return base.GetHashCode();
  719. }
  720. public static bool operator ==(LimitCommon a, LimitCommon b)
  721. {
  722. return a.Equals(b);
  723. }
  724. public static bool operator !=(LimitCommon a, LimitCommon b)
  725. {
  726. return !(a == b);
  727. }
  728. }
  729. /// <summary>
  730. /// Represents a joint limit between two distance values. Lower value must be less than the upper value.
  731. /// </summary>
  732. [SerializeObject]
  733. public class LimitLinearRange : LimitCommon
  734. {
  735. [SerializeField]
  736. private LimitLinearRangeData data;
  737. /// <summary>
  738. /// Lower distance of the limit. Must be less than <see cref="Upper"/>.
  739. /// </summary>
  740. public float Lower { get { return data.lower; } }
  741. /// <summary>
  742. /// Upper distance of the limit. Must be greater than <see cref="Lower"/>.
  743. /// </summary>
  744. public float Upper { get { return data.upper; } }
  745. /// <summary>
  746. /// Gets properties of the linear limit range.
  747. /// </summary>
  748. public LimitLinearRangeData Data
  749. {
  750. get { return data; }
  751. }
  752. /// <summary>
  753. /// Constructs an empty limit.
  754. /// </summary>
  755. public LimitLinearRange()
  756. { }
  757. /// <summary>
  758. /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
  759. /// </summary>
  760. /// <param name="lower"><see cref="Lower"/></param>
  761. /// <param name="upper"><see cref="Upper"/></param>
  762. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  763. public LimitLinearRange(float lower, float upper, float contactDist = -1.0f)
  764. :base(contactDist)
  765. {
  766. data.lower = lower;
  767. data.upper = upper;
  768. }
  769. /// <summary>
  770. /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
  771. /// parameter and will be pulled back towards the limit by the provided spring.
  772. /// </summary>
  773. /// <param name="lower"><see cref="Lower"/></param>
  774. /// <param name="upper"><see cref="Upper"/></param>
  775. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  776. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  777. public LimitLinearRange(float lower, float upper, Spring spring, float restitution = 0.0f)
  778. :base(spring, restitution)
  779. {
  780. data.lower = lower;
  781. data.upper = upper;
  782. }
  783. /// <summary>
  784. /// Constructs a new limit from the provided properties.
  785. /// </summary>
  786. /// <param name="limitData">Linear range specific properties.</param>
  787. /// <param name="commonData">Properties common to all limit types.</param>
  788. public LimitLinearRange(LimitLinearRangeData limitData, LimitCommonData commonData)
  789. :base(commonData)
  790. {
  791. this.data = limitData;
  792. }
  793. /// <inheritdoc/>
  794. public override bool Equals(object rhs)
  795. {
  796. if (rhs is LimitLinearRange)
  797. {
  798. LimitLinearRange other = (LimitLinearRange)rhs;
  799. return base.Equals(rhs) && Lower == other.Lower && Upper == other.Upper;
  800. }
  801. return false;
  802. }
  803. /// <inheritdoc/>
  804. public override int GetHashCode()
  805. {
  806. return base.GetHashCode();
  807. }
  808. public static bool operator ==(LimitLinearRange a, LimitLinearRange b)
  809. {
  810. return a.Equals(b);
  811. }
  812. public static bool operator !=(LimitLinearRange a, LimitLinearRange b)
  813. {
  814. return !(a == b);
  815. }
  816. /// <summary>
  817. /// Used for accessing limit data from native code.
  818. /// </summary>
  819. /// <returns>Native readable limit structure.</returns>
  820. private ScriptLimitLinearRange Internal_GetNative()
  821. {
  822. ScriptLimitLinearRange output;
  823. output.contactDist = ContactDist;
  824. output.restitution = Restitution;
  825. output.spring = Spring;
  826. output.lower = Lower;
  827. output.upper = Upper;
  828. return output;
  829. }
  830. }
  831. /// <summary>
  832. /// Represents a joint limit between zero a single distance value.
  833. /// </summary>
  834. [SerializeObject]
  835. public class LimitLinear : LimitCommon
  836. {
  837. [SerializeField]
  838. private LimitLinearData data;
  839. /// <summary>
  840. /// Distance at which the limit becomes active.
  841. /// </summary>
  842. public float Extent { get { return data.extent; } }
  843. /// <summary>
  844. /// Gets properties of the linear limit.
  845. /// </summary>
  846. public LimitLinearData Data
  847. {
  848. get { return data; }
  849. }
  850. /// <summary>
  851. /// Constructs an empty limit.
  852. /// </summary>
  853. public LimitLinear()
  854. { }
  855. /// <summary>
  856. /// Constructs a hard limit.Once the limit is reached the movement of the attached bodies will come to a stop.
  857. /// </summary>
  858. /// <param name="extent"><see cref="Extent"/></param>
  859. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  860. public LimitLinear(float extent, float contactDist = -1.0f)
  861. :base(contactDist)
  862. {
  863. data.extent = extent;
  864. }
  865. /// <summary>
  866. /// Constructs a soft limit.Once the limit is reached the bodies will bounce back according to the resitution
  867. /// parameter and will be pulled back towards the limit by the provided spring.
  868. /// </summary>
  869. /// <param name="extent"><see cref="Extent"/></param>
  870. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  871. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  872. public LimitLinear(float extent, Spring spring, float restitution = 0.0f)
  873. :base(spring, restitution)
  874. {
  875. data.extent = extent;
  876. }
  877. /// <summary>
  878. /// Constructs a new limit from the provided properties.
  879. /// </summary>
  880. /// <param name="limitData">Linear limit specific properties.</param>
  881. /// <param name="commonData">Properties common to all limit types.</param>
  882. public LimitLinear(LimitLinearData limitData, LimitCommonData commonData)
  883. :base(commonData)
  884. {
  885. this.data = limitData;
  886. }
  887. /// <inheritdoc/>
  888. public override bool Equals(object rhs)
  889. {
  890. if (rhs is LimitLinear)
  891. {
  892. LimitLinear other = (LimitLinear)rhs;
  893. return base.Equals(rhs) && Extent == other.Extent;
  894. }
  895. return false;
  896. }
  897. /// <inheritdoc/>
  898. public override int GetHashCode()
  899. {
  900. return base.GetHashCode();
  901. }
  902. public static bool operator ==(LimitLinear a, LimitLinear b)
  903. {
  904. return a.Equals(b);
  905. }
  906. public static bool operator !=(LimitLinear a, LimitLinear b)
  907. {
  908. return !(a == b);
  909. }
  910. /// <summary>
  911. /// Used for accessing limit data from native code.
  912. /// </summary>
  913. /// <returns>Native readable limit structure.</returns>
  914. private ScriptLimitLinear Internal_GetNative()
  915. {
  916. ScriptLimitLinear output;
  917. output.contactDist = ContactDist;
  918. output.restitution = Restitution;
  919. output.spring = Spring;
  920. output.extent = Extent;
  921. return output;
  922. }
  923. }
  924. /// <summary>
  925. /// Represents a joint limit between two angles.
  926. /// </summary>
  927. [SerializeObject]
  928. public class LimitAngularRange : LimitCommon
  929. {
  930. [SerializeField]
  931. private LimitAngularRangeData data;
  932. /// <summary>
  933. /// Lower angle of the limit. Must be less than <see cref="Upper"/>.
  934. /// </summary>
  935. public Radian Lower { get { return data.lower; } }
  936. /// <summary>
  937. /// Upper angle of the limit. Must be greater than <see cref="Lower"/>.
  938. /// </summary>
  939. public Radian Upper { get { return data.upper; } }
  940. /// <summary>
  941. /// Gets properties of the angular limit range.
  942. /// </summary>
  943. public LimitAngularRangeData Data
  944. {
  945. get { return data; }
  946. }
  947. /// <summary>
  948. /// Constructs an empty limit.
  949. /// </summary>
  950. public LimitAngularRange()
  951. { }
  952. /// <summary>
  953. /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
  954. /// </summary>
  955. /// <param name="lower"><see cref="Lower"/></param>
  956. /// <param name="upper"><see cref="Upper"/></param>
  957. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  958. public LimitAngularRange(Radian lower, Radian upper, float contactDist = -1.0f)
  959. : base(contactDist)
  960. {
  961. data.lower = lower;
  962. data.upper = upper;
  963. }
  964. /// <summary>
  965. /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
  966. /// parameter and will be pulled back towards the limit by the provided spring.
  967. /// </summary>
  968. /// <param name="lower"><see cref="Lower"/></param>
  969. /// <param name="upper"><see cref="Upper"/></param>
  970. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  971. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  972. public LimitAngularRange(Radian lower, Radian upper, Spring spring, float restitution = 0.0f)
  973. : base(spring, restitution)
  974. {
  975. data.lower = lower;
  976. data.upper = upper;
  977. }
  978. /// <summary>
  979. /// Constructs a new limit from the provided properties.
  980. /// </summary>
  981. /// <param name="limitData">Angular limit range specific properties.</param>
  982. /// <param name="commonData">Properties common to all limit types.</param>
  983. public LimitAngularRange(LimitAngularRangeData limitData, LimitCommonData commonData)
  984. :base(commonData)
  985. {
  986. this.data = limitData;
  987. }
  988. /// <inheritdoc/>
  989. public override bool Equals(object rhs)
  990. {
  991. if (rhs is LimitAngularRange)
  992. {
  993. LimitAngularRange other = (LimitAngularRange)rhs;
  994. return base.Equals(rhs) && Lower == other.Lower && Upper == other.Upper;
  995. }
  996. return false;
  997. }
  998. /// <inheritdoc/>
  999. public override int GetHashCode()
  1000. {
  1001. return base.GetHashCode();
  1002. }
  1003. public static bool operator ==(LimitAngularRange a, LimitAngularRange b)
  1004. {
  1005. return a.Equals(b);
  1006. }
  1007. public static bool operator !=(LimitAngularRange a, LimitAngularRange b)
  1008. {
  1009. return !(a == b);
  1010. }
  1011. /// <summary>
  1012. /// Used for accessing limit data from native code.
  1013. /// </summary>
  1014. /// <returns>Native readable limit structure.</returns>
  1015. private ScriptLimitAngularRange Internal_GetNative()
  1016. {
  1017. ScriptLimitAngularRange output;
  1018. output.contactDist = ContactDist;
  1019. output.restitution = Restitution;
  1020. output.spring = Spring;
  1021. output.lower = Lower;
  1022. output.upper = Upper;
  1023. return output;
  1024. }
  1025. }
  1026. /// <summary>
  1027. /// Represents a joint limit that contraints movement to within an elliptical cone.
  1028. /// </summary>
  1029. [SerializeObject]
  1030. public class LimitConeRange : LimitCommon
  1031. {
  1032. [SerializeField]
  1033. private LimitConeRangeData data;
  1034. /// <summary>
  1035. /// Y angle of the cone. Movement is constrainted between 0 and this angle on the Y axis.
  1036. /// </summary>
  1037. public Radian YLimitAngle { get { return data.yLimitAngle; } }
  1038. /// <summary>
  1039. /// Z angle of the cone. Movement is constrainted between 0 and this angle on the Z axis.
  1040. /// </summary>
  1041. public Radian ZLimitAngle { get { return data.zLimitAngle; } }
  1042. /// <summary>
  1043. /// Gets properties of the cone limit range.
  1044. /// </summary>
  1045. public LimitConeRangeData Data
  1046. {
  1047. get { return data; }
  1048. }
  1049. /// <summary>
  1050. /// Constructs a limit with a 45 degree cone.
  1051. /// </summary>
  1052. public LimitConeRange()
  1053. {
  1054. data.yLimitAngle = new Radian(MathEx.Pi * 0.5f);
  1055. data.zLimitAngle = new Radian(MathEx.Pi * 0.5f);
  1056. }
  1057. /// <summary>
  1058. /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
  1059. /// </summary>
  1060. /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
  1061. /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
  1062. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  1063. public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, float contactDist = -1.0f)
  1064. : base(contactDist)
  1065. {
  1066. data.yLimitAngle = yLimitAngle;
  1067. data.zLimitAngle = zLimitAngle;
  1068. }
  1069. /// <summary>
  1070. /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
  1071. /// parameter and will be pulled back towards the limit by the provided spring.
  1072. /// </summary>
  1073. /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
  1074. /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
  1075. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  1076. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  1077. public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, Spring spring, float restitution = 0.0f)
  1078. : base(spring, restitution)
  1079. {
  1080. data.yLimitAngle = yLimitAngle;
  1081. data.zLimitAngle = zLimitAngle;
  1082. }
  1083. /// <summary>
  1084. /// Constructs a new limit from the provided properties.
  1085. /// </summary>
  1086. /// <param name="limitData">Cone limit range specific properties.</param>
  1087. /// <param name="commonData">Properties common to all limit types.</param>
  1088. public LimitConeRange(LimitConeRangeData limitData, LimitCommonData commonData)
  1089. :base(commonData)
  1090. {
  1091. this.data = limitData;
  1092. }
  1093. /// <inheritdoc/>
  1094. public override bool Equals(object rhs)
  1095. {
  1096. if (rhs is LimitConeRange)
  1097. {
  1098. LimitConeRange other = (LimitConeRange)rhs;
  1099. return base.Equals(rhs) && YLimitAngle == other.YLimitAngle && ZLimitAngle == other.ZLimitAngle;
  1100. }
  1101. return false;
  1102. }
  1103. /// <inheritdoc/>
  1104. public override int GetHashCode()
  1105. {
  1106. return base.GetHashCode();
  1107. }
  1108. public static bool operator ==(LimitConeRange a, LimitConeRange b)
  1109. {
  1110. return a.Equals(b);
  1111. }
  1112. public static bool operator !=(LimitConeRange a, LimitConeRange b)
  1113. {
  1114. return !(a == b);
  1115. }
  1116. /// <summary>
  1117. /// Used for accessing limit data from native code.
  1118. /// </summary>
  1119. /// <returns>Native readable limit structure.</returns>
  1120. private ScriptLimitConeRange Internal_GetNative()
  1121. {
  1122. ScriptLimitConeRange output;
  1123. output.contactDist = ContactDist;
  1124. output.restitution = Restitution;
  1125. output.spring = Spring;
  1126. output.yLimitAngle = YLimitAngle;
  1127. output.zLimitAngle = ZLimitAngle;
  1128. return output;
  1129. }
  1130. }
  1131. /// <summary>
  1132. /// Contains data used by HingeJointDrive.
  1133. /// </summary>
  1134. [StructLayout(LayoutKind.Sequential), SerializeObject]
  1135. public struct HingeJointDriveData // Note: Must match C++ struct HingeJoint::Drive
  1136. {
  1137. /// <summary>
  1138. /// <see cref="HingeJointDrive.Speed"/>
  1139. /// </summary>
  1140. public float speed;
  1141. /// <summary>
  1142. /// <see cref="HingeJointDrive.ForceLimit"/>
  1143. /// </summary>
  1144. public float forceLimit;
  1145. /// <summary>
  1146. /// <see cref="HingeJointDrive.GearRatio"/>
  1147. /// </summary>
  1148. public float gearRatio;
  1149. /// <summary>
  1150. /// <see cref="HingeJointDrive.FreeSpin"/>
  1151. /// </summary>
  1152. public bool freeSpin;
  1153. }
  1154. /// <summary>
  1155. /// Contains data used by D6JointDrive.
  1156. /// </summary>
  1157. [StructLayout(LayoutKind.Sequential), SerializeObject]
  1158. public struct D6JointDriveData // Note: Must match C++ struct D6Joint::Drive
  1159. {
  1160. /// <summary>
  1161. /// <see cref="D6JointDrive.Stiffness"/>
  1162. /// </summary>
  1163. public float stiffness;
  1164. /// <summary>
  1165. /// <see cref="D6JointDrive.Damping"/>
  1166. /// </summary>
  1167. public float damping;
  1168. /// <summary>
  1169. /// <see cref="D6JointDrive.ForceLimit"/>
  1170. /// </summary>
  1171. public float forceLimit;
  1172. /// <summary>
  1173. /// <see cref="D6JointDrive.Acceleration"/>
  1174. /// </summary>
  1175. public bool acceleration;
  1176. }
  1177. /// <summary>
  1178. /// Contains data used by LimitCommon.
  1179. /// </summary>
  1180. [SerializeObject]
  1181. public struct LimitCommonData
  1182. {
  1183. /// <summary>
  1184. /// <see cref="LimitCommon.ContactDist"/>
  1185. /// </summary>
  1186. public float contactDist;
  1187. /// <summary>
  1188. /// <see cref="LimitCommon.Restitution"/>
  1189. /// </summary>
  1190. public float restitution;
  1191. /// <summary>
  1192. /// <see cref="LimitCommon.Spring"/>
  1193. /// </summary>
  1194. public Spring spring;
  1195. }
  1196. /// <summary>
  1197. /// Contains data used by LimitLinearRange.
  1198. /// </summary>
  1199. [SerializeObject]
  1200. public struct LimitLinearRangeData
  1201. {
  1202. /// <summary>
  1203. /// <see cref="LimitLinearRange.Lower"/>
  1204. /// </summary>
  1205. public float lower;
  1206. /// <summary>
  1207. /// <see cref="LimitLinearRange.Upper"/>
  1208. /// </summary>
  1209. public float upper;
  1210. }
  1211. /// <summary>
  1212. /// Contains data used by LimitLinear.
  1213. /// </summary>
  1214. [SerializeObject]
  1215. public struct LimitLinearData
  1216. {
  1217. /// <summary>
  1218. /// <see cref="LimitLinearRange.Extent"/>
  1219. /// </summary>
  1220. public float extent;
  1221. }
  1222. /// <summary>
  1223. /// Contains data used by LimitAngularRange.
  1224. /// </summary>
  1225. [SerializeObject]
  1226. public struct LimitAngularRangeData
  1227. {
  1228. /// <summary>
  1229. /// <see cref="LimitAngularRange.Lower"/>
  1230. /// </summary>
  1231. public Radian lower;
  1232. /// <summary>
  1233. /// <see cref="LimitAngularRange.Upper"/>
  1234. /// </summary>
  1235. public Radian upper;
  1236. }
  1237. /// <summary>
  1238. /// Contains data used by LimitConeRange.
  1239. /// </summary>
  1240. [SerializeObject]
  1241. public struct LimitConeRangeData
  1242. {
  1243. /// <summary>
  1244. /// <see cref="LimitConeRange.YLimitAngle"/>
  1245. /// </summary>
  1246. public Radian yLimitAngle;
  1247. /// <summary>
  1248. /// <see cref="LimitConeRange.ZLimitAngle"/>
  1249. /// </summary>
  1250. public Radian zLimitAngle;
  1251. }
  1252. /// <summary>
  1253. /// Used for passing LimitLinearRange data between native and managed code.
  1254. /// </summary>
  1255. [StructLayout(LayoutKind.Sequential)]
  1256. internal struct ScriptLimitLinearRange // Note: Must match C++ struct LimitLinearRange
  1257. {
  1258. public float contactDist;
  1259. public float restitution;
  1260. public Spring spring;
  1261. public float lower;
  1262. public float upper;
  1263. }
  1264. /// <summary>
  1265. /// Used for passing LimitLinear data between native and managed code.
  1266. /// </summary>
  1267. [StructLayout(LayoutKind.Sequential)]
  1268. internal struct ScriptLimitLinear // Note: Must match C++ struct LimitLinear
  1269. {
  1270. public float contactDist;
  1271. public float restitution;
  1272. public Spring spring;
  1273. public float extent;
  1274. }
  1275. /// <summary>
  1276. /// Used for passing LimitAngularRange data between native and managed code.
  1277. /// </summary>
  1278. [StructLayout(LayoutKind.Sequential)]
  1279. internal struct ScriptLimitAngularRange // Note: Must match C++ struct LimitAngularRange
  1280. {
  1281. public float contactDist;
  1282. public float restitution;
  1283. public Spring spring;
  1284. public Radian lower;
  1285. public Radian upper;
  1286. }
  1287. /// <summary>
  1288. /// Used for passing LimitConeRange data between native and managed code.
  1289. /// </summary>
  1290. [StructLayout(LayoutKind.Sequential)]
  1291. internal struct ScriptLimitConeRange // Note: Must match C++ struct LimitConeRange
  1292. {
  1293. public float contactDist;
  1294. public float restitution;
  1295. public Spring spring;
  1296. public Radian yLimitAngle;
  1297. public Radian zLimitAngle;
  1298. }
  1299. /** @} */
  1300. }