Fixes view matrix being created with wrong forward vec

This commit is contained in:
2024-09-29 01:04:59 -04:00
parent 5527d77506
commit 5dc8c94219

View File

@@ -26,8 +26,7 @@ namespace fgl::engine
void Camera::setOrthographicProjection( float left, float right, float top, float bottom, float near, float far )
{
projection_matrix =
Matrix< MatrixType::CameraToScreen >( glm::orthoLH_ZO( left, right, bottom, top, near, far ) );
projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::ortho( left, right, bottom, top, near, far ) );
//TODO: Figure out frustum culling for orthographic projection. (If we even wanna use it)
}
@@ -35,7 +34,7 @@ namespace fgl::engine
FGL_FLATTEN_HOT void Camera::
setPerspectiveProjection( const float fovy, const float aspect, const float near, const float far )
{
projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::perspectiveLH_ZO( fovy, aspect, near, far ) );
projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::perspective( fovy, aspect, near, far ) );
base_frustum = createFrustum( aspect, fovy, near, far );
}
@@ -263,11 +262,11 @@ namespace fgl::engine
const glm::vec3 forward { rotation_matrix * glm::vec4( constants::WORLD_FORWARD, 0.0f ) };
const glm::vec3 camera_up { rotation_matrix * glm::vec4( constants::WORLD_UP, 0.0f ) };
const glm::vec3 camera_up { rotation_matrix * glm::vec4( -constants::WORLD_Z, 0.0f ) };
const WorldCoordinate center_pos { pos + forward };
view_matrix = Matrix< MatrixType::WorldToCamera >( glm::lookAtLH( pos.vec(), center_pos.vec(), -camera_up ) );
view_matrix = Matrix< MatrixType::WorldToCamera >( glm::lookAt( pos.vec(), center_pos.vec(), camera_up ) );
inverse_view_matrix = glm::inverse( view_matrix );
@@ -289,7 +288,7 @@ namespace fgl::engine
[[fallthrough]];
{
//TODO: Implement
//view_matrix = glm::lookAtLH(position, position + );
//view_matrix = glm::lookAt(position, position + );
}
default:
throw std::runtime_error( "Unimplemented view mode" );
@@ -346,42 +345,42 @@ namespace fgl::engine
FrustumBase createFrustum( const float aspect, const float fov_y, const float near, const float far )
{
const Plane< CoordinateSpace::Model > near_plane { ModelCoordinate( constants::WORLD_FORWARD * near ),
NormalVector( constants::WORLD_FORWARD ) };
const Plane< CoordinateSpace::Model > far_plane { ModelCoordinate( constants::WORLD_FORWARD * far ),
NormalVector( constants::WORLD_BACKWARD ) };
const Plane< CoordinateSpace::Model > near_plane { ModelCoordinate( constants::WORLD_Y * near ),
NormalVector( constants::WORLD_Y ) };
const Plane< CoordinateSpace::Model > far_plane { ModelCoordinate( constants::WORLD_Y * far ),
NormalVector( constants::WORLD_Y_NEG ) };
const float half_height { far * glm::tan( fov_y / 2.0f ) };
const float half_width { half_height * aspect };
const ModelCoordinate far_forward { constants::WORLD_FORWARD * far };
const ModelCoordinate right_half { constants::WORLD_RIGHT * half_width };
const ModelCoordinate far_forward { constants::WORLD_Y * far };
const ModelCoordinate right_half { constants::WORLD_X * half_width };
const Vector right_forward { ( far_forward + right_half ).vec() };
const Vector left_forward { ( far_forward - right_half ).vec() };
const Plane< CoordinateSpace::Model > right_plane {
ModelCoordinate( constants::WORLD_CENTER ),
NormalVector( glm::cross( right_forward.vec(), constants::WORLD_DOWN ) )
NormalVector( glm::cross( right_forward.vec(), constants::WORLD_Z_NEG ) )
};
const Plane< CoordinateSpace::Model > left_plane {
ModelCoordinate( constants::WORLD_CENTER ),
NormalVector( glm::cross( left_forward.vec(), constants::WORLD_UP ) )
NormalVector( glm::cross( left_forward.vec(), constants::WORLD_Z ) )
};
const ModelCoordinate top_half { constants::WORLD_UP * half_height };
const ModelCoordinate top_half { constants::WORLD_Z * half_height };
const Vector top_forward { ( far_forward + top_half ).vec() };
const Vector bottom_forward { ( far_forward - top_half ).vec() };
const Plane< CoordinateSpace::Model > top_plane {
ModelCoordinate( constants::WORLD_CENTER ),
NormalVector( glm::cross( top_forward.vec(), constants::WORLD_RIGHT ) )
NormalVector( glm::cross( top_forward.vec(), constants::WORLD_X ) )
};
const Plane< CoordinateSpace::Model > bottom_plane {
ModelCoordinate( constants::WORLD_CENTER ),
NormalVector( glm::cross( bottom_forward.vec(), constants::WORLD_LEFT ) )
NormalVector( glm::cross( bottom_forward.vec(), constants::WORLD_X_NEG ) )
};
return { near_plane,