Skip to content

Commit

Permalink
Matrix4::translateBy() implemented by Eigen
Browse files Browse the repository at this point in the history
Short-circuit the transformation by multiplying _transform directly with an
Eigen::Translation3d, rather than calling getTranslation() and multiplyBy().
  • Loading branch information
Matthew Mott committed Mar 31, 2021
1 parent 0a71ad4 commit 4141ee6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 0 additions & 6 deletions libs/math/Matrix4.cpp
Expand Up @@ -249,12 +249,6 @@ Matrix4 Matrix4::getScale(const Vector3& scale)
);
}

// Add a translation component
void Matrix4::translateBy(const Vector3& translation)
{
multiplyBy(getTranslation(translation));
}

// Add a scale component
void Matrix4::scaleBy(const Vector3& scale)
{
Expand Down
14 changes: 9 additions & 5 deletions libs/math/Matrix4.h
Expand Up @@ -351,13 +351,17 @@ class Matrix4
}

/**
* \brief
* Add a translation component to the transformation represented by this
* matrix.
* \brief Add a translation component to the transformation represented by
* this matrix.
*
* Equivalent to multiplyBy(Matrix4::getTranslation(translation));
* Equivalent to multiplyBy(Matrix4::getTranslation(tr)); note that this is
* a post-multiplication so the translation will be applied before (and be
* affected by) any existing rotation/scale in the current matrix.
*/
void translateBy(const Vector3& translation);
void translateBy(const Vector3& tr)
{
_transform *= Eigen::Translation3d(tr.x(), tr.y(), tr.z());
}

/**
* \brief Add a translation component to the transformation represented by
Expand Down

0 comments on commit 4141ee6

Please sign in to comment.