More bounding box fixes
This commit is contained in:
22
src/engine/debug/logging/formatters/matrix.cpp
Normal file
22
src/engine/debug/logging/formatters/matrix.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by kj16609 on 10/1/24.
|
||||
//
|
||||
|
||||
#include "matrix.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
std::format_context::iterator std::formatter< glm::vec4 >::format( const glm::vec4& vec, format_context& ctx ) const
|
||||
{
|
||||
return format_to( ctx.out(), "vec4( x: {:10f}, y: {:10f}, z: {:10f}, w: {:10f} )", vec.x, vec.y, vec.z, vec.w );
|
||||
}
|
||||
|
||||
std::format_context::iterator std::formatter< glm::vec3 >::format( const glm::vec3& vec, format_context& ctx ) const
|
||||
{
|
||||
return format_to( ctx.out(), "vec3( x: {}, y: {}, z: {} )", vec.x, vec.y, vec.z );
|
||||
}
|
||||
|
||||
std::format_context::iterator std::formatter< glm::mat4 >::format( const glm::mat4& mat, format_context& ctx ) const
|
||||
{
|
||||
return format_to( ctx.out(), "mat4: [\n{},\n{},\n{},\n{} ]", mat[ 0 ], mat[ 1 ], mat[ 2 ], mat[ 3 ] );
|
||||
}
|
||||
32
src/engine/debug/logging/formatters/matrix.hpp
Normal file
32
src/engine/debug/logging/formatters/matrix.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by kj16609 on 10/1/24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <glm/fwd.hpp>
|
||||
|
||||
#include <format>
|
||||
|
||||
template <>
|
||||
struct std::formatter< glm::vec4 >
|
||||
{
|
||||
constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
|
||||
|
||||
format_context::iterator format( const glm::vec4& vec, format_context& ctx ) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter< glm::vec3 >
|
||||
{
|
||||
constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
|
||||
|
||||
format_context::iterator format( const glm::vec3& vec, format_context& ctx ) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter< glm::mat4 >
|
||||
{
|
||||
constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
|
||||
|
||||
format_context::iterator format( const glm::mat4& mat, format_context& ctx ) const;
|
||||
};
|
||||
@@ -12,6 +12,7 @@
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "formatters/filesystem.hpp"
|
||||
#include "formatters/matrix.hpp"
|
||||
|
||||
namespace fgl::engine::log
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Rotation.hpp"
|
||||
#include "Scale.hpp"
|
||||
#include "engine/FGL_DEFINES.hpp"
|
||||
#include "engine/debug/logging/logging.hpp"
|
||||
#include "engine/primitives/points/Coordinate.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
@@ -67,6 +68,7 @@ namespace fgl::engine
|
||||
|
||||
// if any of the values in scale is zero then we need to set it to something very small
|
||||
// otherwise the decompose function will fail
|
||||
/*
|
||||
if ( transform.scale.x == 0.0f ) transform.scale.x = constants::EPSILON;
|
||||
if ( transform.scale.y == 0.0f ) transform.scale.y = constants::EPSILON;
|
||||
if ( transform.scale.z == 0.0f ) transform.scale.z = constants::EPSILON;
|
||||
@@ -75,15 +77,31 @@ namespace fgl::engine
|
||||
if ( matrix[ 0 ][ 0 ] == 0.0f ) matrix[ 0 ][ 0 ] = constants::EPSILON;
|
||||
if ( matrix[ 1 ][ 1 ] == 0.0f ) matrix[ 1 ][ 1 ] = constants::EPSILON;
|
||||
if ( matrix[ 2 ][ 2 ] == 0.0f ) matrix[ 2 ][ 2 ] = constants::EPSILON;
|
||||
*/
|
||||
|
||||
const auto combined_matrix { matrix * transform.mat() };
|
||||
auto combined_matrix { matrix * transform.mat() };
|
||||
|
||||
glm::vec3 scale {}, translation {};
|
||||
[[maybe_unused]] glm::vec3 skew {};
|
||||
glm::quat quat {};
|
||||
[[maybe_unused]] glm::vec4 perspective {};
|
||||
if ( combined_matrix[ 0 ][ 0 ] == 0.0f ) combined_matrix[ 0 ][ 0 ] = constants::EPSILON;
|
||||
if ( combined_matrix[ 1 ][ 1 ] == 0.0f ) combined_matrix[ 1 ][ 1 ] = constants::EPSILON;
|
||||
if ( combined_matrix[ 2 ][ 2 ] == 0.0f ) combined_matrix[ 2 ][ 2 ] = constants::EPSILON;
|
||||
|
||||
glm::decompose( combined_matrix, scale, quat, translation, skew, perspective );
|
||||
const auto NaN { std::numeric_limits< float >::quiet_NaN() };
|
||||
|
||||
glm::vec3 scale { NaN }, translation { NaN };
|
||||
[[maybe_unused]] glm::vec3 skew { NaN };
|
||||
glm::quat quat { NaN, NaN, NaN, NaN };
|
||||
[[maybe_unused]] glm::vec4 perspective { NaN };
|
||||
|
||||
if ( !glm::decompose( combined_matrix, scale, quat, translation, skew, perspective ) )
|
||||
{
|
||||
log::warn(
|
||||
"Failed to decompose matrix:\n{},\n{}",
|
||||
static_cast< glm::mat4 >( matrix ),
|
||||
static_cast< glm::mat4 >( combined_matrix ) );
|
||||
}
|
||||
|
||||
assert( !std::isnan( scale.x ) );
|
||||
assert( scale != glm::vec3( 0.0f, 0.0f, 0.0f ) );
|
||||
|
||||
return { Coordinate< EvolvedType< MType >() >( translation ), Scale( scale ), Rotation( quat ) };
|
||||
}
|
||||
@@ -93,4 +111,4 @@ namespace fgl::engine
|
||||
// using ModelTransform = TransformComponent< CoordinateSpace::Model >;
|
||||
using WorldTransform = TransformComponent< CoordinateSpace::World >;
|
||||
|
||||
} // namespace fgl::engine
|
||||
} // namespace fgl::engine
|
||||
Reference in New Issue
Block a user