More work on camera tests
This commit is contained in:
@@ -244,7 +244,8 @@ namespace fgl::engine
|
||||
ZoneScoped;
|
||||
|
||||
//Flip Z due to the fact we use Z+ outside of this function. It must be Z- inside
|
||||
position.z = -position.z;
|
||||
//position.z = -position.z;
|
||||
// Maybe unneeded?
|
||||
|
||||
switch ( mode )
|
||||
{
|
||||
|
||||
@@ -79,13 +79,13 @@ namespace fgl::engine
|
||||
const Vector getUp() const
|
||||
{
|
||||
return Vector(
|
||||
glm::normalize( glm::vec3( view_matrix[ 0 ][ 1 ], view_matrix[ 1 ][ 1 ], view_matrix[ 2 ][ 1 ] ) ) );
|
||||
glm::normalize( -glm::vec3( view_matrix[ 0 ][ 1 ], view_matrix[ 1 ][ 1 ], view_matrix[ 2 ][ 1 ] ) ) );
|
||||
}
|
||||
|
||||
const Vector getRight() const
|
||||
{
|
||||
return Vector(
|
||||
glm::normalize( glm::vec3( -view_matrix[ 0 ][ 0 ], view_matrix[ 1 ][ 0 ], view_matrix[ 2 ][ 0 ] ) ) );
|
||||
glm::normalize( glm::vec3( view_matrix[ 0 ][ 0 ], view_matrix[ 1 ][ 0 ], view_matrix[ 2 ][ 0 ] ) ) );
|
||||
}
|
||||
|
||||
const Vector getForward() const
|
||||
|
||||
@@ -24,6 +24,8 @@ TEST_CASE( "Camera", "[camera]" )
|
||||
camera.setOrthographicProjection( 1.0f, 1.0f, 1.0f, 1.0f, constants::NEAR_PLANE, constants::FAR_PLANE );
|
||||
}
|
||||
|
||||
camera.setPerspectiveProjection( 90.0f, 1.0f, constants::NEAR_PLANE, constants::FAR_PLANE );
|
||||
|
||||
SECTION( "Default orientation" )
|
||||
{
|
||||
const auto camera_up { camera.getUp() };
|
||||
@@ -61,4 +63,81 @@ TEST_CASE( "Camera", "[camera]" )
|
||||
REQUIRE( camera_forward.z <= std::numeric_limits< float >::epsilon() );
|
||||
}
|
||||
}
|
||||
|
||||
SECTION( "Camera projection test - Perspective" )
|
||||
{
|
||||
WHEN( "Camera is translated right by WORLD_RIGHT" )
|
||||
{
|
||||
camera.setViewYXZ( constants::WORLD_CENTER + constants::WORLD_RIGHT, Rotation( 0.0f ) );
|
||||
|
||||
THEN( "camera.getPosition() should be WORLD_RIGHT" )
|
||||
{
|
||||
const auto position { camera.getPosition() };
|
||||
REQUIRE( position == constants::WORLD_RIGHT );
|
||||
}
|
||||
|
||||
THEN( "A point at the origin should be translated to the left" )
|
||||
{
|
||||
const auto matrix { camera.getProjectionViewMatrix() };
|
||||
const auto point { matrix * glm::vec4( constants::WORLD_CENTER, 1.0f ) };
|
||||
|
||||
REQUIRE( point.x < 0.0f );
|
||||
REQUIRE( point.y == 0.0f );
|
||||
}
|
||||
}
|
||||
|
||||
WHEN( "Camera is translated up by WORLD_UP" )
|
||||
{
|
||||
camera.setViewYXZ( constants::WORLD_CENTER + constants::WORLD_UP, Rotation( 0.0f ) );
|
||||
|
||||
THEN( "camera.getPosition() should be WORLD_UP" )
|
||||
{
|
||||
const auto position { camera.getPosition() };
|
||||
REQUIRE( position == constants::WORLD_UP );
|
||||
}
|
||||
|
||||
THEN( "A point at the origin should be translated down" )
|
||||
{
|
||||
const auto matrix { camera.getProjectionViewMatrix() };
|
||||
const auto point { matrix * glm::vec4( constants::WORLD_CENTER, 1.0f ) };
|
||||
|
||||
REQUIRE( point.x == 0.0f );
|
||||
REQUIRE( point.y < 0.0f );
|
||||
}
|
||||
}
|
||||
|
||||
WHEN( "Camera is translated forward by WORLD_FORWARD" )
|
||||
{
|
||||
camera.setViewYXZ( constants::WORLD_CENTER + constants::WORLD_FORWARD, Rotation( 0.0f ) );
|
||||
|
||||
THEN( "camera.getPosition() should be WORLD_FORWARD" )
|
||||
{
|
||||
const auto position { camera.getPosition() };
|
||||
REQUIRE( position == constants::WORLD_FORWARD );
|
||||
}
|
||||
|
||||
THEN( "A point at the origin should be translated back" )
|
||||
{
|
||||
const auto matrix { camera.getProjectionViewMatrix() };
|
||||
const auto point { matrix * glm::vec4( constants::WORLD_CENTER, 1.0f ) };
|
||||
|
||||
REQUIRE( point.x <= 0.0f );
|
||||
REQUIRE( point.y <= 0.0f );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WHEN( "Two points are translated by the camera when directly in front" )
|
||||
{
|
||||
const auto point_near { constants::WORLD_FORWARD };
|
||||
const auto point_far { constants::WORLD_FORWARD * 2.0f };
|
||||
|
||||
const auto projected_near { camera.getProjectionViewMatrix() * glm::vec4( point_near, 1.0f ) };
|
||||
const auto projected_far { camera.getProjectionViewMatrix() * glm::vec4( point_far, 1.0f ) };
|
||||
|
||||
THEN( "The near point should be closer than the far point" )
|
||||
{
|
||||
REQUIRE( projected_near.z < projected_far.z );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,30 +66,48 @@ TEST_CASE( "Frustum", "[frustum][rotation][translation]" )
|
||||
}
|
||||
}
|
||||
|
||||
SECTION( "Forward" )
|
||||
WHEN( "Translated Forward" )
|
||||
{
|
||||
camera.setViewYXZ( constants::WORLD_CENTER + constants::WORLD_FORWARD, Rotation( 0.0f, 0.0f, 0.0f ) );
|
||||
//Translate forward by 1 world unit
|
||||
const auto translated_forward { camera.getFrustumBounds() };
|
||||
|
||||
//Verify that during a translation the direction isn't changed
|
||||
REQUIRE( translated_forward.near.direction() == base_frustum.near.direction() );
|
||||
THEN( "Direction is the same" )
|
||||
{
|
||||
//Verify that during a translation the direction isn't changed
|
||||
REQUIRE( translated_forward.near.direction() == base_frustum.near.direction() );
|
||||
}
|
||||
|
||||
REQUIRE( translated_forward.near.direction() == constants::WORLD_FORWARD );
|
||||
REQUIRE( translated_forward.near.distance() == constants::NEAR_PLANE + 1.0f );
|
||||
THEN( "The near plane should be translated backwards" )
|
||||
{
|
||||
REQUIRE( translated_forward.near.direction() == constants::WORLD_FORWARD );
|
||||
REQUIRE( translated_forward.near.distance() == constants::NEAR_PLANE + 1.0f );
|
||||
REQUIRE(
|
||||
translated_forward.near.getPosition()
|
||||
== ( constants::WORLD_FORWARD * ( constants::NEAR_PLANE + 1.0f ) ) );
|
||||
}
|
||||
|
||||
REQUIRE( translated_forward.far.direction() == constants::WORLD_BACKWARD );
|
||||
REQUIRE( translated_forward.far.distance() == -( constants::FAR_PLANE + 1.0f ) );
|
||||
THEN( "The far plane should be translated backwards" )
|
||||
{
|
||||
REQUIRE( translated_forward.far.direction() == constants::WORLD_BACKWARD );
|
||||
REQUIRE( translated_forward.far.distance() == -( constants::FAR_PLANE + 1.0f ) );
|
||||
REQUIRE(
|
||||
translated_forward.far.getPosition()
|
||||
== ( constants::WORLD_FORWARD * ( constants::FAR_PLANE + 1.0f ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
SECTION( "Up" )
|
||||
WHEN( "Translated Up" )
|
||||
{
|
||||
camera.setViewYXZ( constants::WORLD_CENTER + constants::WORLD_UP, Rotation( 0.0f, 0.0f, 0.0f ) );
|
||||
//Translate up by 1 world unit
|
||||
const auto translated_up { camera.getFrustumBounds() };
|
||||
|
||||
//Verify that during a translation the direction isn't changed
|
||||
REQUIRE( translated_up.near.direction() == base_frustum.near.direction() );
|
||||
THEN( "Direction is the same" )
|
||||
{
|
||||
//Verify that during a translation the direction isn't changed
|
||||
REQUIRE( translated_up.near.direction() == base_frustum.near.direction() );
|
||||
}
|
||||
|
||||
REQUIRE( translated_up.near.direction() == constants::WORLD_FORWARD );
|
||||
REQUIRE( translated_up.near.distance() == constants::NEAR_PLANE );
|
||||
|
||||
@@ -9,11 +9,6 @@
|
||||
|
||||
using namespace fgl::engine;
|
||||
|
||||
bool epsilonEqual( const float a, const float b )
|
||||
{
|
||||
return std::abs( a - b ) <= std::numeric_limits< float >::epsilon();
|
||||
}
|
||||
|
||||
TEST_CASE( "Transform", "[transform][rotation][translation]" )
|
||||
{
|
||||
TransformComponent component;
|
||||
|
||||
Reference in New Issue
Block a user