[SOLVED] Reverse CreateFromYawPitchRoll() (or how to get the vector that would produce the matrix given only the matrix)

Solved it:

    /// <summary>
    /// Extract yaw, pitch and roll from existing matrix.
    /// </summary>
    /// <param name="matrix">Matrix to extract from.</param>
    /// <param name="yaw">Out yaw value.</param>
    /// <param name="pitch">Out pitch value.</param>
    /// <param name="roll">Out roll value.</param>
    public void ExtractYawPitchRoll(Matrix matrix, out float yaw, out float pitch, out float roll)
    {
        yaw = (float)System.Math.Atan2(matrix.M13, matrix.M33);
        pitch = (float)System.Math.Asin(-matrix.M23);
        roll = (float)System.Math.Atan2(matrix.M21, matrix.M22);
    }

Based on the code from here: https://github.com/cureos/aforge/blob/master/Sources/Math/Matrix4x4.cs#L239

1 Like