static void CreateBallSocket(ref RigidPose a, ref RigidPose b, out BallSocket description) { var midpoint = 0.5f * (a.Position + b.Position); description.LocalOffsetA = Quaternion.Transform(midpoint - a.Position, Quaternion.Conjugate(a.Orientation)); description.LocalOffsetB = Quaternion.Transform(midpoint - b.Position, Quaternion.Conjugate(b.Orientation)); description.SpringSettings = new SpringSettings(15, 0.1f); }
///<summary> /// Transforms a position by a rigid transform's inverse. ///</summary> ///<param name="position">Position to transform.</param> ///<param name="transform">Transform to invert and apply.</param> ///<param name="result">Transformed position.</param> public static void TransformByInverse(ref Vector3 position, ref RigidTransform transform, out Vector3 result) { Quaternion orientation; Vector3 intermediate = position - transform.Position; Quaternion.Conjugate(transform.Orientation, out orientation); Quaternion.Transform(intermediate, orientation, out result); }
static void CreateBallSocket(ref RigidPose a, ref RigidPose b, out BallSocket description) { var midpoint = 0.5f * (a.Position + b.Position); description.LocalOffsetA = Quaternion.Transform(midpoint - a.Position, Quaternion.Conjugate(a.Orientation)); description.LocalOffsetB = Quaternion.Transform(midpoint - b.Position, Quaternion.Conjugate(b.Orientation)); description.SpringSettings = new SpringSettings { NaturalFrequency = (float)(Math.PI * 0.5f * 60), DampingRatio = 0.1f }; }
/// <summary> /// Inverts a rigid transform. /// </summary> /// <param name="transform">Transform to invert.</param> /// <param name="inverse">Inverse of the transform.</param> public static void Invert(ref RigidTransform transform, out RigidTransform inverse) { Quaternion.Conjugate(ref transform.Orientation, out inverse.Orientation); Quaternion.Transform(ref transform.Position, ref inverse.Orientation, out inverse.Position); inverse.Position = -inverse.Position; }