I=(S=Uno.Quaternion = function(){
}).prototype;

S.RotationMatrix = function(matrix, result)
{
    var sqrt = 0.0;
    var halff = 0.0;
    var scale = (matrix.M11 + matrix.M22) + matrix.M33;

    if (scale > 0.0)
    {
        sqrt = Math.sqrt(scale + 1.0);
        result().W = sqrt * 0.5;
        sqrt = 0.5 / sqrt;
        result().X = (matrix.M23 - matrix.M32) * sqrt;
        result().Y = (matrix.M31 - matrix.M13) * sqrt;
        result().Z = (matrix.M12 - matrix.M21) * sqrt;
    }
    else if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33))
    {
        sqrt = Math.sqrt(((1.0 + matrix.M11) - matrix.M22) - matrix.M33);
        halff = 0.5 / sqrt;
        result().X = 0.5 * sqrt;
        result().Y = (matrix.M12 + matrix.M21) * halff;
        result().Z = (matrix.M13 + matrix.M31) * halff;
        result().W = (matrix.M23 - matrix.M32) * halff;
    }
    else if (matrix.M22 > matrix.M33)
    {
        sqrt = Math.sqrt(((1.0 + matrix.M22) - matrix.M11) - matrix.M33);
        halff = 0.5 / sqrt;
        result().X = (matrix.M21 + matrix.M12) * halff;
        result().Y = 0.5 * sqrt;
        result().Z = (matrix.M32 + matrix.M23) * halff;
        result().W = (matrix.M31 - matrix.M13) * halff;
    }
    else
    {
        sqrt = Math.sqrt(((1.0 + matrix.M33) - matrix.M11) - matrix.M22);
        halff = 0.5 / sqrt;
        result().X = (matrix.M31 + matrix.M13) * halff;
        result().Y = (matrix.M32 + matrix.M23) * halff;
        result().Z = 0.5 * sqrt;
        result().W = (matrix.M12 - matrix.M21) * halff;
    }
};

S.Identity = function()
{
    return Uno.Float4.$1(0.0, 0.0, 0.0, 1.0);
};
