/// <summary> /// Updates the transform of the internal Collider representation from the transform of the component's scene object. /// </summary> protected void UpdateTransform() { Vector3 myScale = SceneObject.Scale; if (parent != null) { Vector3 parentPos = parent.SceneObject.Position; Quaternion parentRot = parent.SceneObject.Rotation; Vector3 myPos = SceneObject.Position; Quaternion myRot = SceneObject.Rotation; Vector3 scale = parent.SceneObject.Scale; Vector3 invScale = scale; if (invScale.x != 0) { invScale.x = 1.0f / invScale.x; } if (invScale.y != 0) { invScale.y = 1.0f / invScale.y; } if (invScale.z != 0) { invScale.z = 1.0f / invScale.z; } Quaternion invRotation = parentRot.Inverse; Vector3 relativePos = invRotation.Rotate(myPos - parentPos) * invScale; Quaternion relativeRot = invRotation * myRot; relativePos = relativePos + myRot.Rotate(serializableData.localPosition * scale); relativeRot = relativeRot * serializableData.localRotation; native.Position = relativePos; native.Rotation = relativeRot; parent.UpdateMassDistribution(); } else { Quaternion myRot = SceneObject.Rotation; Vector3 myPos = SceneObject.Position + myRot.Rotate(serializableData.localPosition * myScale); myRot = myRot * serializableData.localRotation; native.Position = myPos; native.Rotation = myRot; } native.Scale = myScale; }
/// <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); } }
/// <inheritdoc/> protected internal override void PreInput() { Camera cam = EditorApplication.SceneViewCamera; if (cam == null) return; position = new Vector3(0, 0, -5.0f); rotation = cam.SceneObject.Rotation.Inverse; Vector3 xOffset = rotation.Rotate(new Vector3(BOX_EXTENT, 0.0f, 0.0f)); Vector3 yOffset = rotation.Rotate(new Vector3(0.0f, BOX_EXTENT, 0.0f)); Vector3 zOffset = rotation.Rotate(new Vector3(0.0f, 0.0f, BOX_EXTENT)); xAxis.Position = position + xOffset; yAxis.Position = position + yOffset; zAxis.Position = position + zOffset; xAxis.Rotation = rotation; yAxis.Rotation = rotation; zAxis.Rotation = rotation; xNegAxis.Position = position - xOffset; yNegAxis.Position = position - yOffset; zNegAxis.Position = position - zOffset; xNegAxis.Rotation = rotation; yNegAxis.Rotation = rotation; zNegAxis.Rotation = rotation; Vector3 cameraForward = cam.SceneObject.Forward; xAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.XAxis)) < DISABLE_THRESHOLD; yAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.YAxis)) < DISABLE_THRESHOLD; zAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.ZAxis)) < DISABLE_THRESHOLD; xNegAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.XAxis)) < DISABLE_THRESHOLD; yNegAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.YAxis)) < DISABLE_THRESHOLD; zNegAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.ZAxis)) < DISABLE_THRESHOLD; Vector3 freeAxisOffset = new Vector3(-BOX_EXTENT, -BOX_EXTENT, 0.2f); projTypePlane.Rotation = Quaternion.Identity; projTypePlane.Position = position + freeAxisOffset; }