using System.Numerics; namespace Demo { /// /// /// Represents a rigid transformation from one coordinate system to another. NOTE: By default, unless otherwise /// stated, the Pose of an object transforms its local space to the ambient world space. /// /// /// Given two Poses p1 and p2 which transform from space A to B and from B to C respectively, /// the pose p2 * p1 transforms from A to C, and p1 * v transforms a vector v from space A to /// B. A Pose has a rotation and a translation. The rotation is always applied first, followed by the /// translation. /// /// /// The rotation of this pose. /// The translation of this pose. public struct Pose(Quaternion rotation, Vector3 translation) { public Vector3 Translation { readonly get; set; } = translation; public Quaternion Rotation { readonly get; set; } = rotation; public static Pose Identity => new(Quaternion.Identity, Vector3.Zero); public Pose(Vector3 translation) : this(Quaternion.Identity, translation) { } public Pose(Quaternion rotation) : this(rotation, Vector3.Zero) { } public static Vector3 operator *(Pose p, Vector3 v) => Vector3.Transform(v, p.Rotation) + p.Translation; public static Pose operator *(Pose a, Pose b) => new(a.Rotation * b.Rotation, a * b.Translation); public readonly Pose Inverse { get { var rotInv = Quaternion.Conjugate(Rotation); return new(rotInv, -Vector3.Transform(Translation, rotInv)); } } } }