/// <summary> /// Method for building a Matrix4 from orientation / scale / position. /// </summary> /// <remarks> /// Transform is performed in the order scale, rotate, translation, i.e. translation is independent /// of orientation axes, scale does not affect size of translation, rotation and scaling are always /// centered on the origin. /// </remarks> /// <param name="position"></param> /// <param name="scale"></param> /// <param name="orientation"></param> /// <param name="destMatrix">object that will contain the transform</param> /// <returns></returns> public static void MakeTransform(Vector3 position, Vector3 scale, Quaternion orientation, out Matrix4 destMatrix) { destMatrix = Matrix4.Identity; // Ordering: // 1. Scale // 2. Rotate // 3. Translate Matrix3 rot3x3; Matrix3 scale3x3; rot3x3 = orientation.ToRotationMatrix(); scale3x3 = Matrix3.Zero; scale3x3.m00 = scale.x; scale3x3.m11 = scale.y; scale3x3.m22 = scale.z; destMatrix = rot3x3 * scale3x3; destMatrix.Translation = position; }
public static Matrix4 GetTransform(ref Quaternion orientation, ref Vector3 position) { Matrix4 rv = Matrix4.FromMatrix3(orientation.ToRotationMatrix()); rv.Translation = position; return rv; }