| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- namespace BansheeEngine
- {
- /** @addtogroup Physics
- * @{
- */
- /// <summary>
- /// Represents the most customizable type of joint. This joint type can be used to create all other built-in joint
- /// types, and to design your own custom ones, but is less intuitive to use. Allows a specification of a linear
- /// constraint (for example for slider), twist constraint(rotating around X) and swing constraint(rotating around Y and
- /// Z). It also allows you to constrain limits to only specific axes or completely lock specific axes.
- /// </summary>
- public sealed class D6Joint : Joint
- {
- [SerializeField]
- private SerializableData data = new SerializableData();
- /// <summary>
- /// Returns the current rotation of the joint around the X axis.
- /// </summary>
- public Radian Twist
- {
- get
- {
- if (Native != null)
- return Native.Twist;
- return new Radian(0.0f);
- }
- }
- /// <summary>
- /// Returns the current rotation of the joint around the Y axis.
- /// </summary>
- public Radian SwingY
- {
- get
- {
- if (Native != null)
- return Native.SwingY;
- return new Radian(0.0f);
- }
- }
- /// <summary>
- /// Returns the current rotation of the joint around the Z axis.
- /// </summary>
- public Radian SwingZ
- {
- get
- {
- if (Native != null)
- return Native.SwingZ;
- return new Radian(0.0f);
- }
- }
- /// <summary>
- /// Linear limit used for constraining translation degrees of freedom.
- /// </summary>
- public LimitLinear LimitLinear
- {
- get { return [email protected]; }
- set
- {
- if ([email protected] == value)
- return;
- [email protected] = value;
- if (Native != null)
- Native.LimitLinear = value;
- }
- }
- /// <summary>
- /// Angular limit used for constraining the twist (rotation around X) degree of freedom.
- /// </summary>
- public LimitAngularRange LimitTwist
- {
- get { return [email protected]; }
- set
- {
- if ([email protected] == value)
- return;
- [email protected] = value;
- if (Native != null)
- Native.LimitTwist = value;
- }
- }
- /// <summary>
- /// Cone limit used for constraining the swing (rotation around Y and Z) degree of freedom.
- /// </summary>
- public LimitConeRange LimitSwing
- {
- get { return [email protected]; }
- set
- {
- if ([email protected] == value)
- return;
- [email protected] = value;
- if (Native != null)
- Native.LimitSwing = value;
- }
- }
- /// <summary>
- /// Determines the drive's target position relative to the joint's first body. This is the position the drive will
- /// attempt to reach if enabled.
- /// </summary>
- public Vector3 DrivePosition
- {
- get { return [email protected]; }
- set
- {
- if ([email protected] == value)
- return;
- [email protected] = value;
- if (Native != null)
- Native.DrivePosition = value;
- }
- }
- /// <summary>
- /// Determines the drive's target orientation relative to the joint's first body. This is the orientation the drive
- /// will attempt to reach if enabled.
- /// </summary>
- public Quaternion DriveRotation
- {
- get { return [email protected]; }
- set
- {
- if ([email protected] == value)
- return;
- [email protected] = value;
- if (Native != null)
- Native.DriveRotation = value;
- }
- }
- /// <summary>
- /// Determines the drive's target linear velocity. This is the velocity the drive will attempt to reach if enabled.
- /// </summary>
- public Vector3 DriveLinearVelocity
- {
- get { return [email protected]; }
- set
- {
- if ([email protected] == value)
- return;
- [email protected] = value;
- if (Native != null)
- Native.DriveLinearVelocity = value;
- }
- }
- /// <summary>
- /// Determines the drive's target angular velocity. This is the velocity the drive will attempt to reach if enabled.
- /// </summary>
- public Vector3 DriveAngularVelocity
- {
- get { return [email protected]; }
- set
- {
- if ([email protected] == value)
- return;
- [email protected] = value;
- if (Native != null)
- Native.DriveAngularVelocity = value;
- }
- }
- /// <summary>
- /// Returns the type of motion constrain for the specified axis.
- /// </summary>
- /// <param name="axis">Axis to retrieve the motion constrain for.</param>
- /// <returns>Motion constrain type for the axis.</returns>
- public D6JointMotion GetMotion(D6JointAxis axis)
- {
- return [email protected][(int) axis];
- }
- /// <summary>
- /// Allows you to constrain motion of the specified axis. Be aware that when setting drives for a specific axis
- /// you must also take care not to constrain its motion in a conflicting way(for example you cannot add a drive
- /// that moves the joint on X axis, and then lock the X axis).
- ///
- /// Unlocking translations degrees of freedom allows the bodies to move along the subset of the unlocked axes.
- /// (for example unlocking just one translational axis is the equivalent of a slider joint.)
- ///
- /// Angular degrees of freedom are partitioned as twist(around X axis) and swing(around Y and Z axes). Different
- /// effects can be achieves by unlocking their various combinations:
- /// - If a single degree of angular freedom is unlocked it should be the twist degree as it has extra options for
- /// that case (for example for a hinge joint).
- /// - If both swing degrees are unlocked but twist is locked the result is a zero-twist joint.
- /// - If one swing and one twist degree of freedom are unlocked the result is a zero-swing joint (for example an
- /// arm attached at the elbow)
- /// - If all angular degrees of freedom are unlocked the result is the same as the spherical joint.
- /// </summary>
- /// <param name="axis">Axis to change the motion type for.</param>
- /// <param name="motion">Type of motion for the axis.</param>
- public void SetMotion(D6JointAxis axis, D6JointMotion motion)
- {
- if ([email protected][(int)axis] == motion)
- return;
- [email protected][(int)axis] = motion;
- if (Native != null)
- Native.SetMotion(axis, motion);
- }
- /// <summary>
- /// Returns properties for the specified drive type.
- /// </summary>
- /// <param name="type">Type of drive to retrieve properties for.</param>
- /// <returns>Properties for the requested drive type.</returns>
- public D6JointDrive GetDrive(D6JointDriveType type)
- {
- return [email protected][(int) type];
- }
- /// <summary>
- /// Sets a drive that will attempt to move the specified degree(s) of freedom to the wanted position and velocity.
- /// </summary>
- /// <param name="type">Type of the drive.</param>
- /// <param name="drive">Drive properties.</param>
- public void SetDrive(D6JointDriveType type, D6JointDrive drive)
- {
- if ([email protected][(int)type] == drive)
- return;
- [email protected][(int)type] = drive;
- if (Native != null)
- Native.SetDrive(type, drive);
- }
- /// <summary>
- /// Returns the native joint wrapped by this component.
- /// </summary>
- private NativeD6Joint Native
- {
- get { return (NativeD6Joint)native; }
- }
- /// <inheritdoc/>
- internal override NativeJoint CreateNative()
- {
- NativeD6Joint joint = new NativeD6Joint(commonData.@internal, data.@internal);
- return joint;
- }
- /// <summary>
- /// Holds all data the joint component needs to persist through serialization.
- /// </summary>
- [SerializeObject]
- internal new class SerializableData
- {
- public ScriptD6JointData @internal;
- public SerializableData()
- {
- @internal.linearLimit = new LimitLinear();
- @internal.twistLimit = new LimitAngularRange();
- @internal.swingLimit = new LimitConeRange();
- @internal.motion = new D6JointMotion[(int)D6JointAxis.Count];
- @internal.drives = new D6JointDrive[(int)D6JointDriveType.Count];
- @internal.drivePosition = Vector3.Zero;
- @internal.driveRotation = Quaternion.Identity;
- @internal.driveLinearVelocity = Vector3.Zero;
- @internal.driveAngularVelocity = Vector3.Zero;
- for (int i = 0; i < (int) D6JointAxis.Count; i++)
- @internal.drives[i] = new D6JointDrive();
- }
- }
- }
- /** @} */
- }
|