///<summary> /// Constructs a new affine transform. ///</summary> ///<param name="scaling">Scaling to apply in the linear transform.</param> ///<param name="orientation">Orientation to apply in the linear transform.</param> ///<param name="translation">Translation to apply.</param> public AffineTransform(Vector3 scaling, Quaternion orientation, Vector3 translation) { //Create an SRT transform. Matrix3X3.CreateScale(ref scaling, out LinearTransform); Matrix3X3 rotation; Matrix3X3.CreateFromQuaternion(ref orientation, out rotation); Matrix3X3.Multiply(ref LinearTransform, ref rotation, out LinearTransform); Translation = translation; }
/// <summary> /// Multiplies a transform by another transform. /// </summary> /// <param name="a">First transform.</param> /// <param name="b">Second transform.</param> /// <param name="transform">Combined transform.</param> public static void Multiply(ref AffineTransform a, ref AffineTransform b, out AffineTransform transform) { Matrix3X3 linearTransform;//Have to use temporary variable just in case a or b reference is transform. Matrix3X3.Multiply(ref a.LinearTransform, ref b.LinearTransform, out linearTransform); Vector3 translation; Matrix3X3.Transform(ref a.Translation, ref b.LinearTransform, out translation); Vector3.Add(ref translation, ref b.Translation, out transform.Translation); transform.LinearTransform = linearTransform; }
///<summary> /// Multiplies a rigid transform by an affine transform. ///</summary> ///<param name="a">Rigid transform.</param> ///<param name="b">Affine transform.</param> ///<param name="transform">Combined transform.</param> public static void Multiply(ref RigidTransform a, ref AffineTransform b, out AffineTransform transform) { Matrix3X3 linearTransform;//Have to use temporary variable just in case b reference is transform. Matrix3X3.CreateFromQuaternion(ref a.Orientation, out linearTransform); Matrix3X3.Multiply(ref linearTransform, ref b.LinearTransform, out linearTransform); Vector3 translation; Matrix3X3.Transform(ref a.Position, ref b.LinearTransform, out translation); Vector3.Add(ref translation, ref b.Translation, out transform.Translation); transform.LinearTransform = linearTransform; }