Joint.cs 49 KB

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