Joint.cs 49 KB

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