So many steps backwards
This commit is contained in:
@@ -64,7 +64,8 @@ namespace fgl::engine
|
||||
|
||||
const glm::vec3 camera_up { rotation_matrix * glm::vec4( constants::WORLD_UP, 0.0f ) };
|
||||
|
||||
view_matrix = Matrix< MatrixType::WorldToCamera >( glm::lookAtLH( pos, pos + forward, camera_up ) );
|
||||
view_matrix =
|
||||
Matrix< MatrixType::WorldToCamera >( glm::lookAtLH( pos, pos + forward, -camera_up ) );
|
||||
inverse_view_matrix = glm::inverse( view_matrix );
|
||||
|
||||
break;
|
||||
|
||||
@@ -83,9 +83,9 @@ namespace fgl::engine
|
||||
return WorldCoordinate( glm::inverse( view_matrix )[ 3 ] );
|
||||
}
|
||||
|
||||
const Vector getUp() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 1 ] ) ) ); }
|
||||
const Vector getUp() const { return -getDown(); }
|
||||
|
||||
const Vector getRight() const { return -Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 0 ] ) ) ); }
|
||||
const Vector getRight() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 0 ] ) ) ); }
|
||||
|
||||
const Vector getForward() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 2 ] ) ) ); }
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace fgl::engine
|
||||
|
||||
const Vector getBackward() const { return -getForward(); }
|
||||
|
||||
const Vector getDown() const { return -getUp(); }
|
||||
const Vector getDown() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 1 ] ) ) ); }
|
||||
|
||||
void setViewDirection( glm::vec3 pos, const Vector direction, glm::vec3 up = constants::WORLD_UP );
|
||||
void setViewTarget( glm::vec3 pos, glm::vec3 target, glm::vec3 up = constants::WORLD_UP );
|
||||
|
||||
@@ -32,6 +32,8 @@ TEST_CASE( "Camera", "[camera]" )
|
||||
{
|
||||
camera.setView( constants::WORLD_CENTER, Rotation( 0.0f ) );
|
||||
|
||||
CAPTURE( camera.view_matrix );
|
||||
|
||||
THEN( "Camera up is WORLD_UP" )
|
||||
{
|
||||
const auto camera_up { camera.getUp() };
|
||||
@@ -124,6 +126,48 @@ TEST_CASE( "Camera", "[camera]" )
|
||||
}
|
||||
}
|
||||
|
||||
WHEN( "Camera is translated left by WORLD_LEFT" )
|
||||
{
|
||||
camera.setView( constants::WORLD_CENTER + constants::WORLD_LEFT, Rotation( 0.0f ) );
|
||||
|
||||
THEN( "camera.getPosition() should be WORLD_UP" )
|
||||
{
|
||||
REQUIRE( camera.getPosition() == constants::WORLD_LEFT );
|
||||
}
|
||||
|
||||
THEN( "A point at the origin should be translated to the right" )
|
||||
{
|
||||
const auto matrix { camera.getProjectionViewMatrix() };
|
||||
const glm::vec3 point { matrix * glm::vec4( constants::WORLD_CENTER, 1.0f ) };
|
||||
|
||||
CAPTURE( point );
|
||||
|
||||
REQUIRE( point.x > 0.0f );
|
||||
REQUIRE( point.y == 0.0f );
|
||||
}
|
||||
}
|
||||
|
||||
WHEN( "Camera is translated down by WORLD_DOWN " )
|
||||
{
|
||||
camera.setView( constants::WORLD_CENTER + constants::WORLD_DOWN, Rotation( 0.0f ) );
|
||||
|
||||
THEN( "camera.getPosition() should be WORLD_DOWN" )
|
||||
{
|
||||
REQUIRE( camera.getPosition() == constants::WORLD_DOWN );
|
||||
}
|
||||
|
||||
THEN( "A point at the origin must be translated up" )
|
||||
{
|
||||
const auto matrix { camera.getProjectionViewMatrix() };
|
||||
const glm::vec3 point { matrix * glm::vec4( constants::WORLD_CENTER, 1.0f ) };
|
||||
|
||||
CAPTURE( point );
|
||||
|
||||
REQUIRE( point.x == 0.0f );
|
||||
REQUIRE( point.y > 0.0f );
|
||||
}
|
||||
}
|
||||
|
||||
WHEN( "Camera is translated up by WORLD_UP" )
|
||||
{
|
||||
camera.setView( constants::WORLD_CENTER + constants::WORLD_UP, Rotation( 0.0f ) );
|
||||
@@ -161,8 +205,11 @@ TEST_CASE( "Camera", "[camera]" )
|
||||
const auto matrix { camera.getProjectionViewMatrix() };
|
||||
const auto point { matrix * glm::vec4( constants::WORLD_CENTER, 1.0f ) };
|
||||
|
||||
CAPTURE( point );
|
||||
|
||||
REQUIRE( point.x <= 0.0f );
|
||||
REQUIRE( point.y <= 0.0f );
|
||||
REQUIRE( point.z < 0.0f );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
#include "engine/primitives/Matrix.hpp"
|
||||
#include "engine/primitives/Rotation.hpp"
|
||||
#include "engine/primitives/Vector.hpp"
|
||||
|
||||
@@ -48,6 +49,15 @@ namespace Catch
|
||||
}
|
||||
};
|
||||
|
||||
template < fgl::engine::MatrixType MType >
|
||||
struct StringMaker< fgl::engine::Matrix< MType > >
|
||||
{
|
||||
static std::string convert( const fgl::engine::Matrix< MType >& mat )
|
||||
{
|
||||
return StringMaker< glm::mat4 >::convert( static_cast< glm::mat4 >( mat ) );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Catch
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
Reference in New Issue
Block a user