Skip to content

Commit

Permalink
Matrix4::getScale() implemented by Eigen
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Apr 1, 2021
1 parent 4be09ef commit d8f7bb3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
11 changes: 0 additions & 11 deletions libs/math/Matrix4.cpp
Expand Up @@ -215,17 +215,6 @@ Matrix4 Matrix4::getRotationForEulerXYZDegrees(const Vector3& euler)
return getRotationForEulerXYZ(euler_degrees_to_radians(euler));
}

// Get a scale matrix
Matrix4 Matrix4::getScale(const Vector3& scale)
{
return Matrix4::byColumns(
scale[0], 0, 0, 0,
0, scale[1], 0, 0,
0, 0, scale[2], 0,
0, 0, 0, 1
);
}

// Add a scale component
void Matrix4::scaleBy(const Vector3& scale)
{
Expand Down
15 changes: 7 additions & 8 deletions libs/math/Matrix4.h
Expand Up @@ -126,14 +126,13 @@ class alignas(16) Matrix4
*/
static Matrix4 getRotationForEulerXYZDegrees(const Vector3& euler);

/**
* \brief
* Get a matrix representing the given scale in 3D space.
*
* \param scale
* Vector3 representing the scale.
*/
static Matrix4 getScale(const Vector3& scale);
/// Get a matrix representing the given scale in 3D space.
static Matrix4 getScale(const Vector3& scale)
{
return Matrix4(
Transform(Eigen::Scaling(scale.x(), scale.y(), scale.z()))
);
}

/**
* \brief
Expand Down
12 changes: 12 additions & 0 deletions test/math/Matrix4.cpp
Expand Up @@ -124,6 +124,18 @@ TEST(MathTest, ConstructTranslationMatrix)
EXPECT_EQ(tm.translation(), TRANS);
}

TEST(MathTest, ConstructScaleMatrix)
{
const Vector3 SCALE(0.75, 1.25, 960);
Matrix4 sm = Matrix4::getScale(SCALE);

EXPECT_EQ(sm, Matrix4::byRows(SCALE.x(), 0, 0, 0,
0, SCALE.y(), 0, 0,
0, 0, SCALE.z(), 0,
0, 0, 0, 1));
EXPECT_EQ(sm.getScale(), SCALE);
}

TEST(MathTest, AccessMatrixColumnVectors)
{
Matrix4 m = Matrix4::byRows(1, 4, 8, -5,
Expand Down

0 comments on commit d8f7bb3

Please sign in to comment.