Beispiel #1
0
        /// <summary>Returns the position relative to the body, at which the body is anchored to the joint.</summary>
        public Vector3 GetPosition(JointBody body)
        {
            Vector3 temp;

            Internal_getPosition(mCachedPtr, body, out temp);
            return(temp);
        }
Beispiel #2
0
        /// <inheritdoc/>
        protected override void GetLocalTransform(JointBody body, out Vector3 position, out Quaternion rotation)
        {
            position = commonData.positions[(int)body];
            rotation = commonData.rotations[(int)body];

            Rigidbody rigidbody = commonData.bodies[(int)body];

            if (rigidbody == null) // Get world space transform if not relative to any body
            {
                Quaternion worldRot = SceneObject.Rotation;

                rotation = worldRot * rotation;
                position = worldRot.Rotate(position) + SceneObject.Position;
            }
            else // Get transform of the object relative to the joint
            {
                // Find world space transform
                Quaternion worldRot = rigidbody.SceneObject.Rotation;

                rotation = worldRot * rotation;
                position = worldRot.Rotate(position) + rigidbody.SceneObject.Position;

                // Get transform of the joint local to the object
                Quaternion invRotation = rotation.Inverse;

                position = invRotation.Rotate(SceneObject.Position - position);
                rotation = invRotation * SceneObject.Rotation;
            }
        }
Beispiel #3
0
        /// <summary>Returns the rotation relative to the body, at which the body is anchored to the joint.</summary>
        public Quaternion GetRotation(JointBody body)
        {
            Quaternion temp;

            Internal_getRotation(mCachedPtr, body, out temp);
            return(temp);
        }
Beispiel #4
0
        /// <inheritdoc/>
        protected override void GetLocalTransform(JointBody body, out Vector3 position, out Quaternion rotation)
        {
            position = commonData.positions[(int)body];
            rotation = commonData.rotations[(int)body];

            Rigidbody rigidbody = commonData.bodies[(int)body];
            if (rigidbody == null) // Get world space transform if not relative to any body
            {
                Quaternion worldRot = SceneObject.Rotation;

                rotation = worldRot * rotation;
                position = worldRot.Rotate(position) + SceneObject.Position;
            }
            else // Get transform of the object relative to the joint
            {
                // Find world space transform
                Quaternion worldRot = rigidbody.SceneObject.Rotation;

                rotation = worldRot * rotation;
                position = worldRot.Rotate(position) + rigidbody.SceneObject.Position;

                // Get transform of the joint local to the object
                Quaternion invRotation = rotation.Inverse;

                position = invRotation.Rotate(SceneObject.Position - position);
                rotation = invRotation * SceneObject.Rotation;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Updates the local transform for the specified body attached to the joint.
        /// </summary>
        /// <param name="body">Body to update.</param>
        private void UpdateTransform(JointBody body)
        {
            Vector3    localPos;
            Quaternion localRot;

            GetLocalTransform(body, out localPos, out localRot);

            native.SetPosition(body, localPos);
            native.SetRotation(body, localRot);
        }
Beispiel #6
0
        public void SetRigidbody(JointBody body, Rigidbody rigidbody)
        {
            IntPtr rigidbodyPtr = IntPtr.Zero;

            if (rigidbody != null)
            {
                rigidbodyPtr = rigidbody.native.GetCachedPtr();
            }

            Internal_SetBody(mCachedPtr, body, rigidbodyPtr);
        }
Beispiel #7
0
        /// <summary>
        /// Sets the position at which the body is anchored to the joint.
        /// </summary>
        /// <param name="body">Which body set the position for.</param>
        /// <param name="position">Position relative to the body.</param>
        public void SetPosition(JointBody body, Vector3 position)
        {
            if (commonData.positions[(int)body] == position)
            {
                return;
            }

            commonData.positions[(int)body] = position;

            if (native != null)
            {
                UpdateTransform(body);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Sets the rotation at which the body is anchored to the joint.
        /// </summary>
        /// <param name="body">Which body set the rotation for.</param>
        /// <param name="rotation">Rotation relative to the body.</param>
        public void SetRotation(JointBody body, Quaternion rotation)
        {
            if (commonData.rotations[(int)body] == rotation)
            {
                return;
            }

            commonData.rotations[(int)body] = rotation;

            if (native != null)
            {
                UpdateTransform(body);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Returns the anchor position for the specified joint body. Anchor represents the world position of the rigidbody
        /// added to the offset provided by the joint.
        /// </summary>
        /// <param name="joint">Joint from which to retrieve the body.</param>
        /// <param name="body">Body to retrieve the anchor for.</param>
        /// <returns>Anchor position in world space.</returns>
        private static Vector3 GetAnchor(Joint joint, JointBody body)
        {
            Rigidbody rigidbody = joint.GetBody(body);
            Vector3   anchor    = joint.GetPosition(body);

            if (rigidbody != null)
            {
                Quaternion worldRot = rigidbody.SceneObject.Rotation;
                anchor = worldRot.Rotate(anchor) + rigidbody.SceneObject.Position;
            }
            else
            {
                Quaternion worldRot = joint.SceneObject.Rotation;
                anchor = worldRot.Rotate(anchor) + joint.SceneObject.Position;
            }

            return(anchor);
        }
Beispiel #10
0
        /// <summary>
        /// Calculates the local position/rotation that needs to be applied to the particular joint body.
        /// </summary>
        /// <param name="body">Body to calculate the transform for.</param>
        /// <param name="position">Output position for the body.</param>
        /// <param name="rotation">Output rotation for the body.</param>
        protected virtual void GetLocalTransform(JointBody body, out Vector3 position, out Quaternion rotation)
        {
            position = commonData.positions[(int)body];
            rotation = commonData.rotations[(int)body];

            Rigidbody rigidbody = commonData.bodies[(int)body];

            if (rigidbody == null) // Get world space transform if not relative to any body
            {
                Quaternion worldRot = SceneObject.Rotation;

                rotation = worldRot * rotation;
                position = worldRot.Rotate(position) + SceneObject.Position;
            }
            else
            {
                position = rotation.Rotate(position);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Sets a body managed by the joint. One of the bodies must be movable (non-kinematic).
        /// </summary>
        /// <param name="body">Which of the rigidbodies to set.</param>
        /// <param name="rigidbody">Rigidbody to managed by the joint, or null. If one of the bodies is null the other
        ///                         one will be anchored globally to the position/rotation set by <see cref="SetPosition"/>
        ///                         and <see cref="SetRotation"/>.</param>
        public void SetRigidbody(JointBody body, Rigidbody rigidbody)
        {
            if (commonData.bodies[(int)body] == rigidbody)
            {
                return;
            }

            if (commonData.bodies[(int)body] != null)
            {
                commonData.bodies[(int)body].SetJoint(null);
            }

            commonData.bodies[(int)body] = rigidbody;

            if (rigidbody != null)
            {
                commonData.bodies[(int)body].SetJoint(this);
            }

            // If joint already exists, destroy it if we removed all bodies, otherwise update its transform
            if (native != null)
            {
                if (!IsBodyValid(commonData.bodies[0]) && !IsBodyValid(commonData.bodies[0]))
                {
                    DestroyNative();
                }
                else
                {
                    native.SetRigidbody(body, rigidbody);
                    UpdateTransform(body);
                }
            }
            else // If joint doesn't exist, check if we can create it
            {
                // Must be an active component and at least one of the bodies must be non-null
                if (SceneObject.Active && (IsBodyValid(commonData.bodies[0]) || IsBodyValid(commonData.bodies[0])))
                {
                    RestoreNative();
                }
            }
        }
Beispiel #12
0
        /// <inheritdoc/>
        protected override void GetLocalTransform(JointBody body, out Vector3 position, out Quaternion rotation)
        {
            position = commonData.positions[(int)body];
            rotation = commonData.rotations[(int)body];

            Rigidbody rigidbody = commonData.bodies[(int)body];
            if (rigidbody == null) // Get world space transform if not relative to any body
            {
                Quaternion worldRot = SceneObject.Rotation;

                rotation = worldRot * rotation;
                position = worldRot.Rotate(position) + SceneObject.Position;
            }
            else
            {
                // Use only the offset for positioning, but for rotation use both the offset and target SO rotation.
                // (Needed because we need to rotate the joint SO in order to orient the slider direction, so we need an
                // additional transform that allows us to orient the object)
                position = rotation.Rotate(position);
                rotation = (rigidbody.SceneObject.Rotation*rotation).Inverse*SceneObject.Rotation;
            }
        }
Beispiel #13
0
        /// <inheritdoc/>
        protected override void GetLocalTransform(JointBody body, out Vector3 position, out Quaternion rotation)
        {
            position = commonData.positions[(int)body];
            rotation = commonData.rotations[(int)body];

            Rigidbody rigidbody = commonData.bodies[(int)body];

            if (rigidbody == null) // Get world space transform if not relative to any body
            {
                Quaternion worldRot = SceneObject.Rotation;

                rotation = worldRot * rotation;
                position = worldRot.Rotate(position) + SceneObject.Position;
            }
            else
            {
                // Use only the offset for positioning, but for rotation use both the offset and target SO rotation.
                // (Needed because we need to rotate the joint SO in order to orient the slider direction, so we need an
                // additional transform that allows us to orient the object)
                position = rotation.Rotate(position);
                rotation = (rigidbody.SceneObject.Rotation * rotation).Inverse * SceneObject.Rotation;
            }
        }
Beispiel #14
0
        /// <summary>
        /// Sets the position at which the body is anchored to the joint.
        /// </summary>
        /// <param name="body">Which body set the position for.</param>
        /// <param name="position">Position relative to the body.</param>
        public void SetPosition(JointBody body, Vector3 position)
        {
            if (commonData.positions[(int)body] == position)
                return;

            commonData.positions[(int) body] = position;

            if (native != null)
                UpdateTransform(body);
        }
Beispiel #15
0
        /// <summary>
        /// Sets the rotation at which the body is anchored to the joint.
        /// </summary>
        /// <param name="body">Which body set the rotation for.</param>
        /// <param name="rotation">Rotation relative to the body.</param>
        public void SetRotation(JointBody body, Quaternion rotation)
        {
            if (commonData.rotations[(int)body] == rotation)
                return;

            commonData.rotations[(int)body] = rotation;

            if (native != null)
                UpdateTransform(body);
        }
Beispiel #16
0
 public void SetRotation(JointBody body, Quaternion rotation)
 {
     Internal_SetRotation(mCachedPtr, body, ref rotation);
 }
Beispiel #17
0
        /// <summary>
        /// Calculates the local position/rotation that needs to be applied to the particular joint body.
        /// </summary>
        /// <param name="body">Body to calculate the transform for.</param>
        /// <param name="position">Output position for the body.</param>
        /// <param name="rotation">Output rotation for the body.</param>
        protected virtual void GetLocalTransform(JointBody body, out Vector3 position, out Quaternion rotation)
        {
            position = commonData.positions[(int)body];
            rotation = commonData.rotations[(int)body];

            Rigidbody rigidbody = commonData.bodies[(int)body];
            if (rigidbody == null) // Get world space transform if not relative to any body
            {
                Quaternion worldRot = SceneObject.Rotation;

                rotation = worldRot * rotation;
                position = worldRot.Rotate(position) + SceneObject.Position;
            }
            else
            {
                position = rotation.Rotate(position);
            }
        }
Beispiel #18
0
        public void SetRigidbody(JointBody body, Rigidbody rigidbody)
        {
            IntPtr rigidbodyPtr = IntPtr.Zero;
            if (rigidbody != null)
                rigidbodyPtr = rigidbody.native.GetCachedPtr();

            Internal_SetBody(mCachedPtr, body, rigidbodyPtr);
        }
Beispiel #19
0
 private static extern void Internal_SetRotation(IntPtr thisPtr, JointBody body, ref Quaternion rotation);
Beispiel #20
0
 /// <summary>
 /// Returns the rotation at which the body is anchored to the joint.
 /// </summary>
 /// <param name="body">Which body to retrieve rotation for.</param>
 /// <returns>Rotation relative to the body.</returns>
 public Quaternion GetRotation(JointBody body)
 {
     return(commonData.rotations[(int)body]);
 }
Beispiel #21
0
 /// <summary>
 /// Returns the position at which the body is anchored to the joint.
 /// </summary>
 /// <param name="body">Which body to retrieve position for.</param>
 /// <returns>Position relative to the body.</returns>
 public Vector3 GetPosition(JointBody body)
 {
     return(commonData.positions[(int)body]);
 }
Beispiel #22
0
 private static extern void Internal_SetRotation(IntPtr thisPtr, JointBody body, ref Quaternion rotation);
Beispiel #23
0
 private static extern void Internal_SetPosition(IntPtr thisPtr, JointBody body, ref Vector3 position);
Beispiel #24
0
 private static extern void Internal_SetBody(IntPtr thisPtr, JointBody body, IntPtr rigidbody);
Beispiel #25
0
 private static extern void Internal_SetBody(IntPtr thisPtr, JointBody body, IntPtr rigidbody);
Beispiel #26
0
 private static extern void Internal_getPosition(IntPtr thisPtr, JointBody body, out Vector3 __output);
Beispiel #27
0
 private static extern void Internal_SetPosition(IntPtr thisPtr, JointBody body, ref Vector3 position);
Beispiel #28
0
 private static extern void Internal_setTransform(IntPtr thisPtr, JointBody body, ref Vector3 position, ref Quaternion rotation);
Beispiel #29
0
 public void SetPosition(JointBody body, Vector3 position)
 {
     Internal_SetPosition(mCachedPtr, body, ref position);
 }
Beispiel #30
0
 /// <summary>Determines a body managed by the joint. One of the bodies must be movable (non-kinematic).</summary>
 public void SetBody(JointBody body, Rigidbody value)
 {
     Internal_setBody(mCachedPtr, body, value);
 }
Beispiel #31
0
 public void SetRotation(JointBody body, Quaternion rotation)
 {
     Internal_SetRotation(mCachedPtr, body, ref rotation);
 }
Beispiel #32
0
 /// <summary>
 /// Returns one of the bodies managed by the joint.
 /// </summary>
 /// <param name="body">Which of the rigidbodies to return.</param>
 /// <returns>Rigidbody managed by the joint, or null if none.</returns>
 public Rigidbody GetRigidbody(JointBody body)
 {
     return commonData.bodies[(int) body];
 }
Beispiel #33
0
 private static extern void Internal_setBody(IntPtr thisPtr, JointBody body, Rigidbody value);
Beispiel #34
0
 public void SetPosition(JointBody body, Vector3 position)
 {
     Internal_SetPosition(mCachedPtr, body, ref position);
 }
Beispiel #35
0
 private static extern void Internal_getRotation(IntPtr thisPtr, JointBody body, out Quaternion __output);
Beispiel #36
0
 private static extern Rigidbody Internal_getBody(IntPtr thisPtr, JointBody body);
Beispiel #37
0
 /// <summary>Determines a body managed by the joint. One of the bodies must be movable (non-kinematic).</summary>
 public Rigidbody GetBody(JointBody body)
 {
     return(Internal_getBody(mCachedPtr, body));
 }
Beispiel #38
0
 /// <summary>
 /// Returns the position at which the body is anchored to the joint.
 /// </summary>
 /// <param name="body">Which body to retrieve position for.</param>
 /// <returns>Position relative to the body.</returns>
 public Vector3 GetPosition(JointBody body)
 {
     return commonData.positions[(int)body];
 }
Beispiel #39
0
 /// <summary>
 /// Returns the rotation at which the body is anchored to the joint.
 /// </summary>
 /// <param name="body">Which body to retrieve rotation for.</param>
 /// <returns>Rotation relative to the body.</returns>
 public Quaternion GetRotation(JointBody body)
 {
     return commonData.rotations[(int)body];
 }
Beispiel #40
0
        /// <summary>
        /// Returns the anchor position for the specified joint body. Anchor represents the world position of the rigidbody
        /// added to the offset provided by the joint.
        /// </summary>
        /// <param name="joint">Joint from which to retrieve the body.</param>
        /// <param name="body">Body to retrieve the anchor for.</param>
        /// <returns>Anchor position in world space.</returns>
        private static Vector3 GetAnchor(Joint joint, JointBody body)
        {
            Rigidbody rigidbody = joint.GetRigidbody(body);
            Vector3 anchor = joint.GetPosition(body);

            if (rigidbody != null)
            {
                Quaternion worldRot = rigidbody.SceneObject.Rotation;
                anchor = worldRot.Rotate(anchor) + rigidbody.SceneObject.Position;
            }
            else
            {
                Quaternion worldRot = joint.SceneObject.Rotation;
                anchor = worldRot.Rotate(anchor) + joint.SceneObject.Position;
            }

            return anchor;
        }
Beispiel #41
0
 /// <summary>Sets the position and rotation relative to the body, at which the body is anchored to the joint.</summary>
 public void SetTransform(JointBody body, Vector3 position, Quaternion rotation)
 {
     Internal_setTransform(mCachedPtr, body, ref position, ref rotation);
 }
Beispiel #42
0
        /// <summary>
        /// Sets a body managed by the joint. One of the bodies must be movable (non-kinematic).
        /// </summary>
        /// <param name="body">Which of the rigidbodies to set.</param>
        /// <param name="rigidbody">Rigidbody to managed by the joint, or null. If one of the bodies is null the other
        ///                         one will be anchored globally to the position/rotation set by <see cref="SetPosition"/>
        ///                         and <see cref="SetRotation"/>.</param>
        public void SetRigidbody(JointBody body, Rigidbody rigidbody)
        {
            if (commonData.bodies[(int)body] == rigidbody)
                return;

            if (commonData.bodies[(int)body] != null)
                commonData.bodies[(int)body].SetJoint(null);

            commonData.bodies[(int)body] = rigidbody;

            if (rigidbody != null)
                commonData.bodies[(int)body].SetJoint(this);

            // If joint already exists, destroy it if we removed all bodies, otherwise update its transform
            if (native != null)
            {
                if (!IsBodyValid(commonData.bodies[0]) && !IsBodyValid(commonData.bodies[0]))
                    DestroyNative();
                else
                {
                    native.SetRigidbody(body, rigidbody);
                    UpdateTransform(body);
                }
            }
            else // If joint doesn't exist, check if we can create it
            {
                // Must be an active component and at least one of the bodies must be non-null
                if (SceneObject.Active && (IsBodyValid(commonData.bodies[0]) || IsBodyValid(commonData.bodies[0])))
                {
                    RestoreNative();
                }
            }
        }
Beispiel #43
0
 /// <summary>
 /// Returns one of the bodies managed by the joint.
 /// </summary>
 /// <param name="body">Which of the rigidbodies to return.</param>
 /// <returns>Rigidbody managed by the joint, or null if none.</returns>
 public Rigidbody GetRigidbody(JointBody body)
 {
     return(commonData.bodies[(int)body]);
 }
Beispiel #44
0
        /// <summary>
        /// Updates the local transform for the specified body attached to the joint.
        /// </summary>
        /// <param name="body">Body to update.</param>
        private void UpdateTransform(JointBody body)
        {
            Vector3 localPos;
            Quaternion localRot;

            GetLocalTransform(body, out localPos, out localRot);

            native.SetPosition(body, localPos);
            native.SetRotation(body, localRot);
        }