Fixes BoundingBox lines not being correct

This commit is contained in:
2024-02-23 23:25:50 -05:00
parent 4ffc52de07
commit 40cbffc450
3 changed files with 37 additions and 17 deletions

View File

@@ -199,11 +199,26 @@ namespace fgl::engine
std::vector< Line< CType > > BoundingBox< CType >::lines() const
{
const auto points { this->points() };
std::vector< Line< CType > > lines;
for ( std::uint32_t i = 0; i < points.size() - 1; ++i )
{
lines.emplace_back( points[ i ], points[ i + 1 ] );
}
//Top
lines.emplace_back( points[ 0 ], points[ 1 ] );
lines.emplace_back( points[ 1 ], points[ 2 ] );
lines.emplace_back( points[ 2 ], points[ 3 ] );
lines.emplace_back( points[ 3 ], points[ 0 ] );
//Bottom
lines.emplace_back( points[ 4 ], points[ 5 ] );
lines.emplace_back( points[ 5 ], points[ 6 ] );
lines.emplace_back( points[ 6 ], points[ 7 ] );
lines.emplace_back( points[ 7 ], points[ 4 ] );
//Sides
lines.emplace_back( points[ 0 ], points[ 4 ] );
lines.emplace_back( points[ 1 ], points[ 5 ] );
lines.emplace_back( points[ 2 ], points[ 6 ] );
lines.emplace_back( points[ 3 ], points[ 7 ] );
return lines;
}

View File

@@ -13,17 +13,27 @@ namespace fgl::engine
template <>
bool Frustum< CoordinateSpace::World >::intersects( const Line< CoordinateSpace::World > line ) const
{
const bool top_intersects { top.intersects( line ) };
const bool bottom_intersects { bottom.intersects( line ) };
const bool left_intersects { left.intersects( line ) };
const bool right_intersects { right.intersects( line ) };
const bool near_intersects { near.intersects( line ) };
const bool far_intersects { far.intersects( line ) };
//Check if the line passes through the frustum
const bool intersects_forward_back { near.intersects( line ) && far.intersects( line ) };
const bool intersects_left_right { left.intersects( line ) && right.intersects( line ) };
const bool intersects_top_bottom { top.intersects( line ) && bottom.intersects( line ) };
const bool intersects_left_right { left_intersects && right_intersects };
const bool intersects_top_bottom { top_intersects && bottom_intersects };
//const bool line_within_top_bottom { top.isForward( line ) && bottom.isForward( line ) };
//const bool line_within_left_right { left.isForward( line ) && right.isForward( line ) };
//At least one point of the line is within the near and far planes
const bool line_within_near_far { near.isForward( line ) || far.isForward( line ) };
const bool line_within_near_far { !near_intersects && !far_intersects };
return line_within_near_far && ( intersects_forward_back || intersects_top_bottom || intersects_left_right );
const bool line_outside_top_bottom { !top_intersects && !bottom_intersects };
const bool line_outside_left_right { !left_intersects && !right_intersects };
const bool line_outside_range { line_outside_top_bottom && line_outside_left_right };
return line_within_near_far && !( line_outside_range ) && ( intersects_top_bottom || intersects_left_right );
}
template <>

View File

@@ -48,11 +48,6 @@ namespace fgl::engine
bool isForward( const WorldCoordinate coord ) const { return distanceFrom( coord ) > 0.0; }
bool isForward( const Line< CoordinateSpace::World > line ) const
{
return isForward( line.start ) && isForward( line.end );
}
bool isBehind( const WorldCoordinate coord ) const { return !isForward( coord ); }
//! Returns a normalized Vector