/// <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); }
/// <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; } }
/// <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); }
/// <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); }
public void SetRigidbody(JointBody body, Rigidbody rigidbody) { IntPtr rigidbodyPtr = IntPtr.Zero; if (rigidbody != null) { rigidbodyPtr = rigidbody.native.GetCachedPtr(); } Internal_SetBody(mCachedPtr, body, rigidbodyPtr); }
/// <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); } }
/// <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); } }
/// <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); }
/// <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); } }
/// <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(); } } }
/// <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; } }
/// <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; } }
/// <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); }
/// <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); }
public void SetRotation(JointBody body, Quaternion rotation) { Internal_SetRotation(mCachedPtr, body, ref rotation); }
public void SetRigidbody(JointBody body, Rigidbody rigidbody) { IntPtr rigidbodyPtr = IntPtr.Zero; if (rigidbody != null) rigidbodyPtr = rigidbody.native.GetCachedPtr(); Internal_SetBody(mCachedPtr, body, rigidbodyPtr); }
private static extern void Internal_SetRotation(IntPtr thisPtr, JointBody body, ref Quaternion rotation);
/// <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]); }
/// <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]); }
private static extern void Internal_SetPosition(IntPtr thisPtr, JointBody body, ref Vector3 position);
private static extern void Internal_SetBody(IntPtr thisPtr, JointBody body, IntPtr rigidbody);
private static extern void Internal_getPosition(IntPtr thisPtr, JointBody body, out Vector3 __output);
private static extern void Internal_setTransform(IntPtr thisPtr, JointBody body, ref Vector3 position, ref Quaternion rotation);
public void SetPosition(JointBody body, Vector3 position) { Internal_SetPosition(mCachedPtr, body, ref position); }
/// <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); }
/// <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]; }
private static extern void Internal_setBody(IntPtr thisPtr, JointBody body, Rigidbody value);
private static extern void Internal_getRotation(IntPtr thisPtr, JointBody body, out Quaternion __output);
private static extern Rigidbody Internal_getBody(IntPtr thisPtr, JointBody body);
/// <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)); }
/// <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]; }
/// <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]; }
/// <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; }
/// <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); }
/// <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(); } } }
/// <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]); }