Even more camera tests
This commit is contained in:
@@ -74,18 +74,22 @@ namespace fgl::engine
|
||||
void setOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
|
||||
void setPerspectiveProjection( float fovy, float aspect, float near, float far );
|
||||
|
||||
const Coordinate< CoordinateSpace::World > getPosition() const { return WorldCoordinate( -view_matrix[ 3 ] ); }
|
||||
const Coordinate< CoordinateSpace::World > getPosition() const
|
||||
{
|
||||
//Should maybe store the inverse view matrix
|
||||
return WorldCoordinate( glm::inverse( view_matrix )[ 3 ] );
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -31,6 +31,6 @@ namespace fgl::engine::constants
|
||||
constexpr float FAR_PLANE { 100.0f };
|
||||
constexpr glm::vec3 CENTER { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
constexpr auto EPSILON { std::numeric_limits< float >::epsilon() };
|
||||
constexpr auto EPSILON { std::numeric_limits< float >::epsilon() * 2 };
|
||||
|
||||
} // namespace fgl::engine::constants
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
|
||||
#include <ostream>
|
||||
|
||||
@@ -65,6 +66,18 @@ namespace fgl::engine
|
||||
glm::vec3::operator=( other );
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool operator==( const Coordinate& other ) const { return *this == static_cast< glm::vec3 >( other ); }
|
||||
|
||||
bool operator==( const glm::vec3 other ) const
|
||||
{
|
||||
const auto diff { glm::abs( static_cast< glm::vec3 >( *this ) - other ) };
|
||||
return glm::all( glm::lessThanEqual( diff, glm::vec3( constants::EPSILON ) ) );
|
||||
//These should have the same behaviour. I'm kind of confused why they don't?
|
||||
//return glm::all( glm::epsilonEqual( static_cast< glm::vec3 >( *this ), other, constants::EPSILON ) );
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
using ModelCoordinate = Coordinate< CoordinateSpace::Model >;
|
||||
|
||||
@@ -66,6 +66,23 @@ TEST_CASE( "Camera", "[camera]" )
|
||||
|
||||
SECTION( "Camera projection test - Perspective" )
|
||||
{
|
||||
WHEN( "Camera is rotated" )
|
||||
{
|
||||
float x_gen { GENERATE( 0.0f, 90.0f, 180.0f, 270.0f ) };
|
||||
float y_gen { GENERATE( 0.0f, 90.0f, 180.0f, 270.0f ) };
|
||||
float z_gen { GENERATE( 0.0f, 90.0f, 180.0f, 270.0f ) };
|
||||
|
||||
const Rotation rotation { x_gen, y_gen, z_gen };
|
||||
|
||||
camera.setViewYXZ( constants::WORLD_RIGHT, rotation );
|
||||
|
||||
THEN( "Camera translation should not change" )
|
||||
{
|
||||
const Coordinate< CoordinateSpace::World > position { camera.getPosition() };
|
||||
REQUIRE( position == constants::WORLD_RIGHT );
|
||||
}
|
||||
}
|
||||
|
||||
WHEN( "Camera is translated right by WORLD_RIGHT" )
|
||||
{
|
||||
camera.setViewYXZ( constants::WORLD_CENTER + constants::WORLD_RIGHT, Rotation( 0.0f ) );
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace Catch
|
||||
|
||||
} // namespace Catch
|
||||
|
||||
#ifndef NDEBUG
|
||||
namespace glm
|
||||
{
|
||||
inline bool operator==( const glm::vec3& lhs, const glm::vec3& rhs )
|
||||
@@ -38,3 +39,6 @@ namespace glm
|
||||
}
|
||||
|
||||
} // namespace glm
|
||||
#else
|
||||
#warning "Debug mode not enabled. Tests will pass when checking for floating point equality."
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user