Fixes rotation matrix being improper

This commit is contained in:
2024-02-16 16:28:47 -05:00
parent c4b01b8a27
commit 92f59efeea
3 changed files with 32 additions and 8 deletions

View File

@@ -8,12 +8,12 @@ namespace fgl::engine
{
glm::mat4 TransformComponent::mat4() const
{
const float c3 { glm::cos( rotation.z ) };
const float s3 { glm::sin( rotation.z ) };
const float c3 { glm::cos( -rotation.z ) };
const float s3 { glm::sin( -rotation.z ) };
const float c2 { glm::cos( rotation.x ) };
const float s2 { glm::sin( rotation.x ) };
const float c1 { glm::cos( rotation.y ) };
const float s1 { glm::sin( rotation.y ) };
const float c1 { glm::cos( -rotation.y ) };
const float s1 { glm::sin( -rotation.y ) };
return glm::mat4 {
{ scale.x * ( c1 * c3 + s1 * s2 * s3 ), scale.x * ( c2 * s3 ), scale.x * ( c1 * s2 * s3 - c3 * s1 ), 0.0f },

View File

@@ -167,8 +167,8 @@ TEST_CASE( "Frustum translations", "[frustum][translation]" )
REQUIRE( Matrix< MatrixType::ModelToWorld > { 1.0f } * camera.getBaseFrustum() == camera.getFrustumBounds() );
//Testing rotation of the camera
SECTION( "Pitch" )
{
std::cout << "Testing rotation (Pitch)" << std::endl;
Vector rotation { 0.0f, 0.0f, 0.0f };
rotation.pitch -= glm::radians( 90.0f );
@@ -198,10 +198,10 @@ TEST_CASE( "Frustum translations", "[frustum][translation]" )
REQUIRE( rotated_frustum.pointInside( point ) );
}
SECTION( "Yaw" )
{
std::cout << "Testing rotation (Yaw)" << std::endl;
Vector rotation { 0.0f, 0.0f, 0.0f };
rotation.yaw -= glm::radians( 90.0f );
rotation.yaw += glm::radians( 90.0f );
camera.setViewYXZ( constants::CENTER, rotation );
@@ -230,8 +230,8 @@ TEST_CASE( "Frustum translations", "[frustum][translation]" )
REQUIRE_FALSE( rotated_frustum.pointInside( WorldCoordinate( constants::WORLD_LEFT ) ) );
}
SECTION( "Roll" )
{
std::cout << "Testing rotation (Roll)" << std::endl;
Vector rotation { 0.0f, 0.0f, 0.0f };
rotation.roll -= glm::radians( 90.0f );

View File

@@ -9,6 +9,12 @@
using namespace fgl::engine;
std::ostream& operator<<( std::ostream& os, const glm::vec3 vec )
{
os << "X: " << vec.x << " Y: " << vec.y << " Z: " << vec.z;
return os;
}
TEST_CASE( "Transform rotations", "[transform][rotation]" )
{
TransformComponent component;
@@ -31,6 +37,9 @@ TEST_CASE( "Transform rotations", "[transform][rotation]" )
//Must be dot here since the precision isn't good enough to be exact.
// If the dot product is close to 1, then the vectors are close to being equal
CAPTURE( rotated_point.x );
CAPTURE( rotated_point.y );
CAPTURE( rotated_point.z );
REQUIRE( glm::dot( rotated_point, constants::WORLD_UP ) > 0.99f );
}
@@ -40,6 +49,9 @@ TEST_CASE( "Transform rotations", "[transform][rotation]" )
const glm::vec3 rotated_point { component.mat4() * glm::vec4( TEST_POINT, 1.0f ) };
CAPTURE( rotated_point.x );
CAPTURE( rotated_point.y );
CAPTURE( rotated_point.z );
REQUIRE( glm::dot( rotated_point, constants::WORLD_DOWN ) > 0.99f );
}
@@ -49,6 +61,9 @@ TEST_CASE( "Transform rotations", "[transform][rotation]" )
const glm::vec3 rotated_point { component.mat4() * glm::vec4( TEST_POINT, 1.0f ) };
CAPTURE( rotated_point.x );
CAPTURE( rotated_point.y );
CAPTURE( rotated_point.z );
REQUIRE( glm::dot( rotated_point, constants::WORLD_RIGHT ) > 0.99f );
}
@@ -58,6 +73,9 @@ TEST_CASE( "Transform rotations", "[transform][rotation]" )
const glm::vec3 rotated_point { component.mat4() * glm::vec4( TEST_POINT, 1.0f ) };
CAPTURE( rotated_point.x );
CAPTURE( rotated_point.y );
CAPTURE( rotated_point.z );
REQUIRE( glm::dot( rotated_point, constants::WORLD_LEFT ) > 0.99f );
}
@@ -68,6 +86,9 @@ TEST_CASE( "Transform rotations", "[transform][rotation]" )
const glm::vec3 rotated_point { component.mat4() * glm::vec4( constants::WORLD_RIGHT, 1.0f ) };
CAPTURE( rotated_point.x );
CAPTURE( rotated_point.y );
CAPTURE( rotated_point.z );
REQUIRE( glm::dot( rotated_point, constants::WORLD_UP ) > 0.99f );
}
@@ -77,6 +98,9 @@ TEST_CASE( "Transform rotations", "[transform][rotation]" )
const glm::vec3 rotated_point { component.mat4() * glm::vec4( constants::WORLD_RIGHT, 1.0f ) };
CAPTURE( rotated_point.x );
CAPTURE( rotated_point.y );
CAPTURE( rotated_point.z );
REQUIRE( glm::dot( rotated_point, constants::WORLD_DOWN ) > 0.99f );
}
}