Joint.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  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. 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.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. /// Constructor for deserialization only.
  509. /// </summary>
  510. private D6JointDrive()
  511. { }
  512. /// <summary>
  513. /// Constructs a new D6 joint drive.
  514. /// </summary>
  515. /// <param name="stiffness"><see cref="Stiffness"/></param>
  516. /// <param name="damping"><see cref="Damping"/></param>
  517. /// <param name="forceLimit"><see cref="ForceLimit"/></param>
  518. /// <param name="acceleration"><see cref="Acceleration"/></param>
  519. public D6JointDrive(float stiffness = 0.0f, float damping = 0.0f, float forceLimit = float.MaxValue,
  520. bool acceleration = false)
  521. {
  522. data.stiffness = stiffness;
  523. data.damping = damping;
  524. data.forceLimit = forceLimit;
  525. data.acceleration = acceleration;
  526. }
  527. /// <summary>
  528. /// Constructs a new D6 joint drive.
  529. /// </summary>
  530. /// <param name="data">Properties to initialize the drive with.</param>
  531. public D6JointDrive(D6JointDriveData data)
  532. {
  533. this.data = data;
  534. }
  535. /// <inheritdoc/>
  536. public override bool Equals(object rhs)
  537. {
  538. if (rhs is D6JointDrive)
  539. {
  540. D6JointDrive other = (D6JointDrive)rhs;
  541. return Stiffness == other.Stiffness && Damping == other.Damping && ForceLimit == other.ForceLimit
  542. && Acceleration == other.Acceleration;
  543. }
  544. return false;
  545. }
  546. /// <inheritdoc/>
  547. public override int GetHashCode()
  548. {
  549. return base.GetHashCode();
  550. }
  551. public static bool operator ==(D6JointDrive a, D6JointDrive b)
  552. {
  553. return a.Equals(b);
  554. }
  555. public static bool operator !=(D6JointDrive a, D6JointDrive b)
  556. {
  557. return !(a == b);
  558. }
  559. /// <summary>
  560. /// Used for accessing drive data from native code.
  561. /// </summary>
  562. /// <returns>Native readable drive structure.</returns>
  563. private D6JointDriveData Internal_GetNative()
  564. {
  565. return data;
  566. }
  567. }
  568. /// <summary>
  569. /// Properties of a drive that drives the hinge joint's angular velocity towards a paricular value.
  570. /// </summary>
  571. [SerializeObject]
  572. public class HingeJointDrive
  573. {
  574. [SerializeField]
  575. private HingeJointDriveData data;
  576. /// <summary>
  577. /// Target speed of the joint.
  578. /// </summary>
  579. public float Speed { get { return data.speed; } }
  580. /// <summary>
  581. /// Maximum torque the drive is allowed to apply.
  582. /// </summary>
  583. public float ForceLimit { get { return data.forceLimit; } }
  584. /// <summary>
  585. /// Scales the velocity of the first body, and its response to drive torque is scaled down.
  586. /// </summary>
  587. public float GearRatio { get { return data.gearRatio; } }
  588. /// <summary>
  589. /// If the joint is moving faster than the drive's target speed, the drive will try to break. If you don't want
  590. /// the breaking to happen set this to true.
  591. /// </summary>
  592. public bool FreeSpin { get { return data.freeSpin; } }
  593. /// <summary>
  594. /// Gets drive properties.
  595. /// </summary>
  596. public HingeJointDriveData Data
  597. {
  598. get { return data; }
  599. }
  600. /// <summary>
  601. /// Constructor for deserialization only.
  602. /// </summary>
  603. private HingeJointDrive()
  604. { }
  605. /// <summary>
  606. /// Constructs a new hinge joint drive.
  607. /// </summary>
  608. /// <param name="speed"><see cref="Speed"/></param>
  609. /// <param name="forceLimit"><see cref="ForceLimit"/></param>
  610. /// <param name="gearRatio"><see cref="GearRatio"/></param>
  611. /// <param name="freeSpin"><see cref="FreeSpin"/></param>
  612. public HingeJointDrive(float speed = 0.0f, float forceLimit = float.MaxValue,
  613. float gearRatio = 1.0f, bool freeSpin = false)
  614. {
  615. data.speed = speed;
  616. data.forceLimit = forceLimit;
  617. data.gearRatio = gearRatio;
  618. data.freeSpin = freeSpin;
  619. }
  620. /// <summary>
  621. /// Constructs a new hinge joint drive.
  622. /// </summary>
  623. /// <param name="data">Properties to initialize the drive with.</param>
  624. public HingeJointDrive(HingeJointDriveData data)
  625. {
  626. this.data = data;
  627. }
  628. /// <inheritdoc/>
  629. public override bool Equals(object rhs)
  630. {
  631. if (rhs is HingeJointDrive)
  632. {
  633. HingeJointDrive other = (HingeJointDrive)rhs;
  634. return data.speed == other.data.speed && data.gearRatio == other.data.gearRatio &&
  635. data.forceLimit == other.data.forceLimit && data.freeSpin == other.data.freeSpin;
  636. }
  637. return false;
  638. }
  639. /// <inheritdoc/>
  640. public override int GetHashCode()
  641. {
  642. return base.GetHashCode();
  643. }
  644. public static bool operator ==(HingeJointDrive a, HingeJointDrive b)
  645. {
  646. return a.Equals(b);
  647. }
  648. public static bool operator !=(HingeJointDrive a, HingeJointDrive b)
  649. {
  650. return !(a == b);
  651. }
  652. /// <summary>
  653. /// Used for accessing drive data from native code.
  654. /// </summary>
  655. /// <returns>Native readable drive structure.</returns>
  656. private HingeJointDriveData Internal_GetNative()
  657. {
  658. return data;
  659. }
  660. };
  661. /// <summary>
  662. /// Contains common values used by all Joint limit types.
  663. /// </summary>
  664. [SerializeObject]
  665. public class LimitCommon
  666. {
  667. [SerializeField]
  668. private LimitCommonData data;
  669. /// <summary>
  670. /// Distance from the limit at which it becomes active. Allows the solver to activate earlier than the limit is
  671. /// reached to avoid breaking the limit.
  672. /// </summary>
  673. public float ContactDist { get { return data.contactDist; } }
  674. /// <summary>
  675. /// Controls how do objects react when the limit is reached, values closer to zero specify non-ellastic collision,
  676. /// while those closer to one specify more ellastic(i.e bouncy) collision.Must be in [0, 1] range.
  677. /// </summary>
  678. public float Restitution { get { return data.restitution; } }
  679. /// <summary>
  680. /// Spring that controls how are the bodies pulled back towards the limit when they breach it.
  681. /// </summary>
  682. public Spring Spring { get { return data.spring; } }
  683. /// <summary>
  684. /// Gets properties common to all limit types.
  685. /// </summary>
  686. public LimitCommonData CommonData
  687. {
  688. get { return data; }
  689. }
  690. protected LimitCommon(float contactDist = -1.0f)
  691. {
  692. data.contactDist = contactDist;
  693. data.restitution = 0.0f;
  694. data.spring = new Spring();
  695. }
  696. protected LimitCommon(Spring spring, float restitution = 0.0f)
  697. {
  698. data.contactDist = -1.0f;
  699. data.restitution = restitution;
  700. data.spring = spring;
  701. }
  702. protected LimitCommon(LimitCommonData data)
  703. {
  704. this.data = data;
  705. }
  706. /// <inheritdoc/>
  707. public override bool Equals(object rhs)
  708. {
  709. if (rhs is LimitCommon)
  710. {
  711. LimitCommon other = (LimitCommon)rhs;
  712. return ContactDist == other.ContactDist && Restitution == other.Restitution && Spring == other.Spring;
  713. }
  714. return false;
  715. }
  716. /// <inheritdoc/>
  717. public override int GetHashCode()
  718. {
  719. return base.GetHashCode();
  720. }
  721. public static bool operator ==(LimitCommon a, LimitCommon b)
  722. {
  723. return a.Equals(b);
  724. }
  725. public static bool operator !=(LimitCommon a, LimitCommon b)
  726. {
  727. return !(a == b);
  728. }
  729. }
  730. /// <summary>
  731. /// Represents a joint limit between two distance values. Lower value must be less than the upper value.
  732. /// </summary>
  733. [SerializeObject]
  734. public class LimitLinearRange : LimitCommon
  735. {
  736. [SerializeField]
  737. private LimitLinearRangeData data;
  738. /// <summary>
  739. /// Lower distance of the limit. Must be less than <see cref="Upper"/>.
  740. /// </summary>
  741. public float Lower { get { return data.lower; } }
  742. /// <summary>
  743. /// Upper distance of the limit. Must be greater than <see cref="Lower"/>.
  744. /// </summary>
  745. public float Upper { get { return data.upper; } }
  746. /// <summary>
  747. /// Gets properties of the linear limit range.
  748. /// </summary>
  749. public LimitLinearRangeData Data
  750. {
  751. get { return data; }
  752. }
  753. /// <summary>
  754. /// Constructs an empty limit.
  755. /// </summary>
  756. public LimitLinearRange()
  757. { }
  758. /// <summary>
  759. /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
  760. /// </summary>
  761. /// <param name="lower"><see cref="Lower"/></param>
  762. /// <param name="upper"><see cref="Upper"/></param>
  763. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  764. public LimitLinearRange(float lower, float upper, float contactDist = -1.0f)
  765. :base(contactDist)
  766. {
  767. data.lower = lower;
  768. data.upper = upper;
  769. }
  770. /// <summary>
  771. /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
  772. /// parameter and will be pulled back towards the limit by the provided spring.
  773. /// </summary>
  774. /// <param name="lower"><see cref="Lower"/></param>
  775. /// <param name="upper"><see cref="Upper"/></param>
  776. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  777. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  778. public LimitLinearRange(float lower, float upper, Spring spring, float restitution = 0.0f)
  779. :base(spring, restitution)
  780. {
  781. data.lower = lower;
  782. data.upper = upper;
  783. }
  784. /// <summary>
  785. /// Constructs a new limit from the provided properties.
  786. /// </summary>
  787. /// <param name="limitData">Linear range specific properties.</param>
  788. /// <param name="commonData">Properties common to all limit types.</param>
  789. public LimitLinearRange(LimitLinearRangeData limitData, LimitCommonData commonData)
  790. :base(commonData)
  791. {
  792. this.data = limitData;
  793. }
  794. /// <inheritdoc/>
  795. public override bool Equals(object rhs)
  796. {
  797. if (rhs is LimitLinearRange)
  798. {
  799. LimitLinearRange other = (LimitLinearRange)rhs;
  800. return base.Equals(rhs) && Lower == other.Lower && Upper == other.Upper;
  801. }
  802. return false;
  803. }
  804. /// <inheritdoc/>
  805. public override int GetHashCode()
  806. {
  807. return base.GetHashCode();
  808. }
  809. public static bool operator ==(LimitLinearRange a, LimitLinearRange b)
  810. {
  811. return a.Equals(b);
  812. }
  813. public static bool operator !=(LimitLinearRange a, LimitLinearRange b)
  814. {
  815. return !(a == b);
  816. }
  817. /// <summary>
  818. /// Used for accessing limit data from native code.
  819. /// </summary>
  820. /// <returns>Native readable limit structure.</returns>
  821. private ScriptLimitLinearRange Internal_GetNative()
  822. {
  823. ScriptLimitLinearRange output;
  824. output.contactDist = ContactDist;
  825. output.restitution = Restitution;
  826. output.spring = Spring;
  827. output.lower = Lower;
  828. output.upper = Upper;
  829. return output;
  830. }
  831. }
  832. /// <summary>
  833. /// Represents a joint limit between zero a single distance value.
  834. /// </summary>
  835. [SerializeObject]
  836. public class LimitLinear : LimitCommon
  837. {
  838. [SerializeField]
  839. private LimitLinearData data;
  840. /// <summary>
  841. /// Distance at which the limit becomes active.
  842. /// </summary>
  843. public float Extent { get { return data.extent; } }
  844. /// <summary>
  845. /// Gets properties of the linear limit.
  846. /// </summary>
  847. public LimitLinearData Data
  848. {
  849. get { return data; }
  850. }
  851. /// <summary>
  852. /// Constructs an empty limit.
  853. /// </summary>
  854. public LimitLinear()
  855. { }
  856. /// <summary>
  857. /// Constructs a hard limit.Once the limit is reached the movement of the attached bodies will come to a stop.
  858. /// </summary>
  859. /// <param name="extent"><see cref="Extent"/></param>
  860. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  861. public LimitLinear(float extent, float contactDist = -1.0f)
  862. :base(contactDist)
  863. {
  864. data.extent = extent;
  865. }
  866. /// <summary>
  867. /// Constructs a soft limit.Once the limit is reached the bodies will bounce back according to the resitution
  868. /// parameter and will be pulled back towards the limit by the provided spring.
  869. /// </summary>
  870. /// <param name="extent"><see cref="Extent"/></param>
  871. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  872. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  873. public LimitLinear(float extent, Spring spring, float restitution = 0.0f)
  874. :base(spring, restitution)
  875. {
  876. data.extent = extent;
  877. }
  878. /// <summary>
  879. /// Constructs a new limit from the provided properties.
  880. /// </summary>
  881. /// <param name="limitData">Linear limit specific properties.</param>
  882. /// <param name="commonData">Properties common to all limit types.</param>
  883. public LimitLinear(LimitLinearData limitData, LimitCommonData commonData)
  884. :base(commonData)
  885. {
  886. this.data = limitData;
  887. }
  888. /// <inheritdoc/>
  889. public override bool Equals(object rhs)
  890. {
  891. if (rhs is LimitLinear)
  892. {
  893. LimitLinear other = (LimitLinear)rhs;
  894. return base.Equals(rhs) && Extent == other.Extent;
  895. }
  896. return false;
  897. }
  898. /// <inheritdoc/>
  899. public override int GetHashCode()
  900. {
  901. return base.GetHashCode();
  902. }
  903. public static bool operator ==(LimitLinear a, LimitLinear b)
  904. {
  905. return a.Equals(b);
  906. }
  907. public static bool operator !=(LimitLinear a, LimitLinear b)
  908. {
  909. return !(a == b);
  910. }
  911. /// <summary>
  912. /// Used for accessing limit data from native code.
  913. /// </summary>
  914. /// <returns>Native readable limit structure.</returns>
  915. private ScriptLimitLinear Internal_GetNative()
  916. {
  917. ScriptLimitLinear output;
  918. output.contactDist = ContactDist;
  919. output.restitution = Restitution;
  920. output.spring = Spring;
  921. output.extent = Extent;
  922. return output;
  923. }
  924. }
  925. /// <summary>
  926. /// Represents a joint limit between two angles.
  927. /// </summary>
  928. [SerializeObject]
  929. public class LimitAngularRange : LimitCommon
  930. {
  931. [SerializeField]
  932. private LimitAngularRangeData data;
  933. /// <summary>
  934. /// Lower angle of the limit. Must be less than <see cref="Upper"/>.
  935. /// </summary>
  936. public Radian Lower { get { return data.lower; } }
  937. /// <summary>
  938. /// Upper angle of the limit. Must be greater than <see cref="Lower"/>.
  939. /// </summary>
  940. public Radian Upper { get { return data.upper; } }
  941. /// <summary>
  942. /// Gets properties of the angular limit range.
  943. /// </summary>
  944. public LimitAngularRangeData Data
  945. {
  946. get { return data; }
  947. }
  948. /// <summary>
  949. /// Constructs an empty limit.
  950. /// </summary>
  951. public LimitAngularRange()
  952. { }
  953. /// <summary>
  954. /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
  955. /// </summary>
  956. /// <param name="lower"><see cref="Lower"/></param>
  957. /// <param name="upper"><see cref="Upper"/></param>
  958. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  959. public LimitAngularRange(Radian lower, Radian upper, float contactDist = -1.0f)
  960. : base(contactDist)
  961. {
  962. data.lower = lower;
  963. data.upper = upper;
  964. }
  965. /// <summary>
  966. /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
  967. /// parameter and will be pulled back towards the limit by the provided spring.
  968. /// </summary>
  969. /// <param name="lower"><see cref="Lower"/></param>
  970. /// <param name="upper"><see cref="Upper"/></param>
  971. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  972. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  973. public LimitAngularRange(Radian lower, Radian upper, Spring spring, float restitution = 0.0f)
  974. : base(spring, restitution)
  975. {
  976. data.lower = lower;
  977. data.upper = upper;
  978. }
  979. /// <summary>
  980. /// Constructs a new limit from the provided properties.
  981. /// </summary>
  982. /// <param name="limitData">Angular limit range specific properties.</param>
  983. /// <param name="commonData">Properties common to all limit types.</param>
  984. public LimitAngularRange(LimitAngularRangeData limitData, LimitCommonData commonData)
  985. :base(commonData)
  986. {
  987. this.data = limitData;
  988. }
  989. /// <inheritdoc/>
  990. public override bool Equals(object rhs)
  991. {
  992. if (rhs is LimitAngularRange)
  993. {
  994. LimitAngularRange other = (LimitAngularRange)rhs;
  995. return base.Equals(rhs) && Lower == other.Lower && Upper == other.Upper;
  996. }
  997. return false;
  998. }
  999. /// <inheritdoc/>
  1000. public override int GetHashCode()
  1001. {
  1002. return base.GetHashCode();
  1003. }
  1004. public static bool operator ==(LimitAngularRange a, LimitAngularRange b)
  1005. {
  1006. return a.Equals(b);
  1007. }
  1008. public static bool operator !=(LimitAngularRange a, LimitAngularRange b)
  1009. {
  1010. return !(a == b);
  1011. }
  1012. /// <summary>
  1013. /// Used for accessing limit data from native code.
  1014. /// </summary>
  1015. /// <returns>Native readable limit structure.</returns>
  1016. private ScriptLimitAngularRange Internal_GetNative()
  1017. {
  1018. ScriptLimitAngularRange output;
  1019. output.contactDist = ContactDist;
  1020. output.restitution = Restitution;
  1021. output.spring = Spring;
  1022. output.lower = Lower;
  1023. output.upper = Upper;
  1024. return output;
  1025. }
  1026. }
  1027. /// <summary>
  1028. /// Represents a joint limit that contraints movement to within an elliptical cone.
  1029. /// </summary>
  1030. [SerializeObject]
  1031. public class LimitConeRange : LimitCommon
  1032. {
  1033. [SerializeField]
  1034. private LimitConeRangeData data;
  1035. /// <summary>
  1036. /// Y angle of the cone. Movement is constrainted between 0 and this angle on the Y axis.
  1037. /// </summary>
  1038. public Radian YLimitAngle { get { return data.yLimitAngle; } }
  1039. /// <summary>
  1040. /// Z angle of the cone. Movement is constrainted between 0 and this angle on the Z axis.
  1041. /// </summary>
  1042. public Radian ZLimitAngle { get { return data.zLimitAngle; } }
  1043. /// <summary>
  1044. /// Gets properties of the cone limit range.
  1045. /// </summary>
  1046. public LimitConeRangeData Data
  1047. {
  1048. get { return data; }
  1049. }
  1050. /// <summary>
  1051. /// Constructs a limit with a 45 degree cone.
  1052. /// </summary>
  1053. public LimitConeRange()
  1054. {
  1055. data.yLimitAngle = new Radian(MathEx.Pi * 0.5f);
  1056. data.zLimitAngle = new Radian(MathEx.Pi * 0.5f);
  1057. }
  1058. /// <summary>
  1059. /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
  1060. /// </summary>
  1061. /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
  1062. /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
  1063. /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
  1064. public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, float contactDist = -1.0f)
  1065. : base(contactDist)
  1066. {
  1067. data.yLimitAngle = yLimitAngle;
  1068. data.zLimitAngle = zLimitAngle;
  1069. }
  1070. /// <summary>
  1071. /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
  1072. /// parameter and will be pulled back towards the limit by the provided spring.
  1073. /// </summary>
  1074. /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
  1075. /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
  1076. /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
  1077. /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
  1078. public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, Spring spring, float restitution = 0.0f)
  1079. : base(spring, restitution)
  1080. {
  1081. data.yLimitAngle = yLimitAngle;
  1082. data.zLimitAngle = zLimitAngle;
  1083. }
  1084. /// <summary>
  1085. /// Constructs a new limit from the provided properties.
  1086. /// </summary>
  1087. /// <param name="limitData">Cone limit range specific properties.</param>
  1088. /// <param name="commonData">Properties common to all limit types.</param>
  1089. public LimitConeRange(LimitConeRangeData limitData, LimitCommonData commonData)
  1090. :base(commonData)
  1091. {
  1092. this.data = limitData;
  1093. }
  1094. /// <inheritdoc/>
  1095. public override bool Equals(object rhs)
  1096. {
  1097. if (rhs is LimitConeRange)
  1098. {
  1099. LimitConeRange other = (LimitConeRange)rhs;
  1100. return base.Equals(rhs) && YLimitAngle == other.YLimitAngle && ZLimitAngle == other.ZLimitAngle;
  1101. }
  1102. return false;
  1103. }
  1104. /// <inheritdoc/>
  1105. public override int GetHashCode()
  1106. {
  1107. return base.GetHashCode();
  1108. }
  1109. public static bool operator ==(LimitConeRange a, LimitConeRange b)
  1110. {
  1111. return a.Equals(b);
  1112. }
  1113. public static bool operator !=(LimitConeRange a, LimitConeRange b)
  1114. {
  1115. return !(a == b);
  1116. }
  1117. /// <summary>
  1118. /// Used for accessing limit data from native code.
  1119. /// </summary>
  1120. /// <returns>Native readable limit structure.</returns>
  1121. private ScriptLimitConeRange Internal_GetNative()
  1122. {
  1123. ScriptLimitConeRange output;
  1124. output.contactDist = ContactDist;
  1125. output.restitution = Restitution;
  1126. output.spring = Spring;
  1127. output.yLimitAngle = YLimitAngle;
  1128. output.zLimitAngle = ZLimitAngle;
  1129. return output;
  1130. }
  1131. }
  1132. /// <summary>
  1133. /// Contains data used by HingeJointDrive.
  1134. /// </summary>
  1135. [StructLayout(LayoutKind.Sequential), SerializeObject]
  1136. public struct HingeJointDriveData // Note: Must match C++ struct HingeJoint::Drive
  1137. {
  1138. /// <summary>
  1139. /// <see cref="HingeJointDrive.Speed"/>
  1140. /// </summary>
  1141. public float speed;
  1142. /// <summary>
  1143. /// <see cref="HingeJointDrive.ForceLimit"/>
  1144. /// </summary>
  1145. public float forceLimit;
  1146. /// <summary>
  1147. /// <see cref="HingeJointDrive.GearRatio"/>
  1148. /// </summary>
  1149. public float gearRatio;
  1150. /// <summary>
  1151. /// <see cref="HingeJointDrive.FreeSpin"/>
  1152. /// </summary>
  1153. public bool freeSpin;
  1154. }
  1155. /// <summary>
  1156. /// Contains data used by D6JointDrive.
  1157. /// </summary>
  1158. [StructLayout(LayoutKind.Sequential), SerializeObject]
  1159. public struct D6JointDriveData // Note: Must match C++ struct D6Joint::Drive
  1160. {
  1161. /// <summary>
  1162. /// <see cref="D6JointDrive.Stiffness"/>
  1163. /// </summary>
  1164. public float stiffness;
  1165. /// <summary>
  1166. /// <see cref="D6JointDrive.Damping"/>
  1167. /// </summary>
  1168. public float damping;
  1169. /// <summary>
  1170. /// <see cref="D6JointDrive.ForceLimit"/>
  1171. /// </summary>
  1172. public float forceLimit;
  1173. /// <summary>
  1174. /// <see cref="D6JointDrive.Acceleration"/>
  1175. /// </summary>
  1176. public bool acceleration;
  1177. }
  1178. /// <summary>
  1179. /// Contains data used by LimitCommon.
  1180. /// </summary>
  1181. [SerializeObject]
  1182. public struct LimitCommonData
  1183. {
  1184. /// <summary>
  1185. /// <see cref="LimitCommon.ContactDist"/>
  1186. /// </summary>
  1187. public float contactDist;
  1188. /// <summary>
  1189. /// <see cref="LimitCommon.Restitution"/>
  1190. /// </summary>
  1191. public float restitution;
  1192. /// <summary>
  1193. /// <see cref="LimitCommon.Spring"/>
  1194. /// </summary>
  1195. public Spring spring;
  1196. }
  1197. /// <summary>
  1198. /// Contains data used by LimitLinearRange.
  1199. /// </summary>
  1200. [SerializeObject]
  1201. public struct LimitLinearRangeData
  1202. {
  1203. /// <summary>
  1204. /// <see cref="LimitLinearRange.Lower"/>
  1205. /// </summary>
  1206. public float lower;
  1207. /// <summary>
  1208. /// <see cref="LimitLinearRange.Upper"/>
  1209. /// </summary>
  1210. public float upper;
  1211. }
  1212. /// <summary>
  1213. /// Contains data used by LimitLinear.
  1214. /// </summary>
  1215. [SerializeObject]
  1216. public struct LimitLinearData
  1217. {
  1218. /// <summary>
  1219. /// <see cref="LimitLinearRange.Extent"/>
  1220. /// </summary>
  1221. public float extent;
  1222. }
  1223. /// <summary>
  1224. /// Contains data used by LimitAngularRange.
  1225. /// </summary>
  1226. [SerializeObject]
  1227. public struct LimitAngularRangeData
  1228. {
  1229. /// <summary>
  1230. /// <see cref="LimitAngularRange.Lower"/>
  1231. /// </summary>
  1232. public Radian lower;
  1233. /// <summary>
  1234. /// <see cref="LimitAngularRange.Upper"/>
  1235. /// </summary>
  1236. public Radian upper;
  1237. }
  1238. /// <summary>
  1239. /// Contains data used by LimitConeRange.
  1240. /// </summary>
  1241. [SerializeObject]
  1242. public struct LimitConeRangeData
  1243. {
  1244. /// <summary>
  1245. /// <see cref="LimitConeRange.YLimitAngle"/>
  1246. /// </summary>
  1247. public Radian yLimitAngle;
  1248. /// <summary>
  1249. /// <see cref="LimitConeRange.ZLimitAngle"/>
  1250. /// </summary>
  1251. public Radian zLimitAngle;
  1252. }
  1253. /// <summary>
  1254. /// Used for passing LimitLinearRange data between native and managed code.
  1255. /// </summary>
  1256. [StructLayout(LayoutKind.Sequential)]
  1257. internal struct ScriptLimitLinearRange // Note: Must match C++ struct LimitLinearRange
  1258. {
  1259. public float contactDist;
  1260. public float restitution;
  1261. public Spring spring;
  1262. public float lower;
  1263. public float upper;
  1264. }
  1265. /// <summary>
  1266. /// Used for passing LimitLinear data between native and managed code.
  1267. /// </summary>
  1268. [StructLayout(LayoutKind.Sequential)]
  1269. internal struct ScriptLimitLinear // Note: Must match C++ struct LimitLinear
  1270. {
  1271. public float contactDist;
  1272. public float restitution;
  1273. public Spring spring;
  1274. public float extent;
  1275. }
  1276. /// <summary>
  1277. /// Used for passing LimitAngularRange data between native and managed code.
  1278. /// </summary>
  1279. [StructLayout(LayoutKind.Sequential)]
  1280. internal struct ScriptLimitAngularRange // Note: Must match C++ struct LimitAngularRange
  1281. {
  1282. public float contactDist;
  1283. public float restitution;
  1284. public Spring spring;
  1285. public Radian lower;
  1286. public Radian upper;
  1287. }
  1288. /// <summary>
  1289. /// Used for passing LimitConeRange data between native and managed code.
  1290. /// </summary>
  1291. [StructLayout(LayoutKind.Sequential)]
  1292. internal struct ScriptLimitConeRange // Note: Must match C++ struct LimitConeRange
  1293. {
  1294. public float contactDist;
  1295. public float restitution;
  1296. public Spring spring;
  1297. public Radian yLimitAngle;
  1298. public Radian zLimitAngle;
  1299. }
  1300. /** @} */
  1301. }