mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
LibGfx+LibGL: Allow singular matrices to be inverted
This is basically the old behavior before the GLtron port was introduced, but `.inverse()` no longer crashes if the matrix is singular.
This commit is contained in:
parent
b2e0bf24ef
commit
a41d5ffa1e
2 changed files with 5 additions and 12 deletions
|
@ -317,8 +317,7 @@ void SoftwareGLContext::gl_end()
|
||||||
mv_elements[0][0], mv_elements[1][0], mv_elements[2][0],
|
mv_elements[0][0], mv_elements[1][0], mv_elements[2][0],
|
||||||
mv_elements[0][1], mv_elements[1][1], mv_elements[2][1],
|
mv_elements[0][1], mv_elements[1][1], mv_elements[2][1],
|
||||||
mv_elements[0][2], mv_elements[1][2], mv_elements[2][2]);
|
mv_elements[0][2], mv_elements[1][2], mv_elements[2][2]);
|
||||||
auto normal_transform_or_error = model_view_transposed.inverse();
|
auto const& normal_transform = model_view_transposed.inverse();
|
||||||
auto const& normal_transform = normal_transform_or_error.is_error() ? model_view_transposed : normal_transform_or_error.release_value();
|
|
||||||
|
|
||||||
m_rasterizer.draw_primitives(primitive_type, m_model_view_matrix, normal_transform, m_projection_matrix, m_texture_matrix, m_vertex_list, enabled_texture_units);
|
m_rasterizer.draw_primitives(primitive_type, m_model_view_matrix, normal_transform, m_projection_matrix, m_texture_matrix, m_vertex_list, enabled_texture_units);
|
||||||
|
|
||||||
|
@ -2810,9 +2809,7 @@ void SoftwareGLContext::gl_tex_gen_floatv(GLenum coord, GLenum pname, GLfloat co
|
||||||
texture_coordinate_generation(capability).object_plane_coefficients = { params[0], params[1], params[2], params[3] };
|
texture_coordinate_generation(capability).object_plane_coefficients = { params[0], params[1], params[2], params[3] };
|
||||||
break;
|
break;
|
||||||
case GL_EYE_PLANE: {
|
case GL_EYE_PLANE: {
|
||||||
auto inverse_matrix_or_error = m_model_view_matrix.inverse();
|
auto const& inverse_model_view = m_model_view_matrix.inverse();
|
||||||
auto const& inverse_model_view_matrix = inverse_matrix_or_error.is_error() ? m_model_view_matrix : inverse_matrix_or_error.release_value();
|
|
||||||
|
|
||||||
auto input_coefficients = FloatVector4 { params[0], params[1], params[2], params[3] };
|
auto input_coefficients = FloatVector4 { params[0], params[1], params[2], params[3] };
|
||||||
|
|
||||||
// Note: we are allowed to store transformed coefficients here, according to the documentation on
|
// Note: we are allowed to store transformed coefficients here, according to the documentation on
|
||||||
|
@ -2821,7 +2818,7 @@ void SoftwareGLContext::gl_tex_gen_floatv(GLenum coord, GLenum pname, GLfloat co
|
||||||
// "The returned values are those maintained in eye coordinates. They are not equal to the values
|
// "The returned values are those maintained in eye coordinates. They are not equal to the values
|
||||||
// specified using glTexGen, unless the modelview matrix was identity when glTexGen was called."
|
// specified using glTexGen, unless the modelview matrix was identity when glTexGen was called."
|
||||||
|
|
||||||
texture_coordinate_generation(capability).eye_plane_coefficients = inverse_model_view_matrix * input_coefficients;
|
texture_coordinate_generation(capability).eye_plane_coefficients = inverse_model_view * input_coefficients;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Error.h>
|
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|
||||||
|
@ -159,12 +158,9 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr ErrorOr<Matrix> inverse() const
|
[[nodiscard]] constexpr Matrix inverse() const
|
||||||
{
|
{
|
||||||
auto det = determinant();
|
return adjugate() / determinant();
|
||||||
if (det == 0)
|
|
||||||
return Error::from_string_literal("inverse of matrix does not exist"sv);
|
|
||||||
return adjugate() / det;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr Matrix transpose() const
|
[[nodiscard]] constexpr Matrix transpose() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue