Fixes frustum plane math being wrong
This commit is contained in:
@@ -84,7 +84,7 @@ namespace fgl::engine::debug
|
||||
ZoneScopedC( TRACY_DRAWER_FUNC_COLOR );
|
||||
for ( const auto [ p1, p2 ] : box.lines() )
|
||||
{
|
||||
drawLineI( { p1, p2 }, color );
|
||||
drawLine( { p1, p2 }, color );
|
||||
}
|
||||
|
||||
for ( const auto point : box.points() )
|
||||
@@ -201,12 +201,12 @@ namespace fgl::engine::debug
|
||||
|
||||
void drawFrustum( const Frustum< CoordinateSpace::World >& frustum, const WorldCoordinate point )
|
||||
{
|
||||
drawPlane( frustum.near, point, "near" );
|
||||
drawPlane( frustum.far, point, "far" );
|
||||
drawPlane( frustum.top, point, "top" );
|
||||
drawPlane( frustum.bottom, point, "bottom" );
|
||||
drawPlane( frustum.right, point, "right" );
|
||||
drawPlane( frustum.left, point, "left" );
|
||||
drawPlane( frustum.near, frustum.near.getPosition(), "near" );
|
||||
drawPlane( frustum.far, frustum.far.getPosition(), "far" );
|
||||
drawPlane( frustum.top, frustum.top.getPosition(), "top" );
|
||||
drawPlane( frustum.bottom, frustum.bottom.getPosition(), "bottom" );
|
||||
drawPlane( frustum.right, frustum.right.getPosition(), "right" );
|
||||
drawPlane( frustum.left, frustum.left.getPosition(), "left" );
|
||||
}
|
||||
|
||||
void drawFrustum()
|
||||
|
||||
@@ -42,8 +42,6 @@ namespace fgl::engine
|
||||
|
||||
constexpr explicit Coordinate( const float value ) : glm::vec3( value ) {}
|
||||
|
||||
operator glm::vec4() const { return glm::vec4( x, y, z, 1.0f ); }
|
||||
|
||||
Coordinate operator+( const glm::vec3 other )
|
||||
{
|
||||
assert( static_cast< glm::vec3 >( *this ) != constants::DEFAULT_VEC3 );
|
||||
@@ -67,8 +65,7 @@ namespace fgl::engine
|
||||
template < MatrixType MType >
|
||||
Coordinate< EvolvedType< MType >() > operator*( const Matrix< MType >& mat )
|
||||
{
|
||||
return Coordinate<
|
||||
EvolvedType< MType >() >( mat * static_cast< glm::vec4 >( static_cast< glm::vec3 >( *this ), 1.0f ) );
|
||||
return Coordinate< EvolvedType< MType >() >( mat * glm::vec4( static_cast< glm::vec3 >( *this ), 1.0f ) );
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
@@ -84,6 +81,13 @@ namespace fgl::engine
|
||||
#endif
|
||||
};
|
||||
|
||||
template < CoordinateSpace CType, MatrixType MType >
|
||||
Coordinate< EvolvedType< MType >() > operator*( const Matrix< MType > mat, const Coordinate< CType > coord )
|
||||
{
|
||||
return Coordinate< EvolvedType<
|
||||
MType >() >( static_cast< glm::mat4 >( mat ) * glm::vec4( static_cast< glm::vec3 >( coord ), 1.0f ) );
|
||||
}
|
||||
|
||||
using ModelCoordinate = Coordinate< CoordinateSpace::Model >;
|
||||
using WorldCoordinate = Coordinate< CoordinateSpace::World >;
|
||||
|
||||
|
||||
@@ -171,6 +171,8 @@ namespace fgl::engine
|
||||
{
|
||||
const auto box_points { box.points() };
|
||||
|
||||
debug::world::drawBoundingBox( box );
|
||||
|
||||
for ( const auto point : box_points )
|
||||
{
|
||||
if ( pointInside( point ) ) return true;
|
||||
@@ -178,7 +180,7 @@ namespace fgl::engine
|
||||
|
||||
//TODO: Do weird line intersection shit
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
@@ -20,11 +20,17 @@ namespace fgl::engine
|
||||
|
||||
public:
|
||||
|
||||
PointPlane() = default;
|
||||
explicit PointPlane() = default;
|
||||
|
||||
PointPlane( const Coordinate< CType > pos, const Vector vec ) : coordinate( pos ), vector( vec ) {}
|
||||
explicit PointPlane( const Coordinate< CType > pos, const Vector vec ) :
|
||||
coordinate( pos ),
|
||||
vector( glm::normalize( vec ) )
|
||||
{}
|
||||
|
||||
explicit PointPlane( const glm::vec3 pos, const glm::vec3 vec ) : coordinate( pos ), vector( vec ) {}
|
||||
explicit PointPlane( const glm::vec3 pos, const glm::vec3 vec ) :
|
||||
coordinate( pos ),
|
||||
vector( glm::normalize( vec ) )
|
||||
{}
|
||||
|
||||
Vector direction() const { return vector; }
|
||||
|
||||
@@ -45,8 +51,7 @@ namespace fgl::engine
|
||||
template < CoordinateSpace CType, MatrixType MType >
|
||||
PointPlane< EvolvedType< MType >() > operator*( const Matrix< MType >& mat, const PointPlane< CType >& plane )
|
||||
{
|
||||
PointPlane< EvolvedType< MType >() > new_plane { plane.getPosition() * mat, plane.direction() * mat };
|
||||
return new_plane;
|
||||
return PointPlane< EvolvedType< MType >() >( mat * plane.getPosition(), mat * plane.direction() );
|
||||
}
|
||||
|
||||
template < CoordinateSpace CType >
|
||||
|
||||
Reference in New Issue
Block a user