include/Spectre/Math/Transform.h: Adding inverse()
This commit is contained in:
parent
d8db86e40c
commit
0f7a4bbabc
2 changed files with 22 additions and 0 deletions
|
|
@ -53,6 +53,10 @@ public :
|
|||
Transform& scale(Vector2f offset);
|
||||
Transform& scale(float s);
|
||||
|
||||
// Inverse
|
||||
|
||||
Transform inverse();
|
||||
|
||||
Transform& combine(const Transform& other);
|
||||
|
||||
Vector2f transformPoint(float x, float y) const;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include <Spectre/Math/Math.h>
|
||||
#include <Spectre/Math/Matrix3.h>
|
||||
#include <Spectre/Math/Transform.h>
|
||||
|
||||
namespace sp {
|
||||
|
|
@ -83,6 +84,23 @@ Transform& Transform::scale(float s)
|
|||
return scale(s, s);
|
||||
}
|
||||
|
||||
Transform Transform::inverse()
|
||||
{
|
||||
// Because a 2D Transform matrix is really just a 3x3 matrix.
|
||||
// We can cheat here :)
|
||||
Matrix3f m(m_matrix.e[0], m_matrix.e[1], m_matrix.e[3],
|
||||
m_matrix.e[4], m_matrix.e[5], m_matrix.e[7],
|
||||
m_matrix.e[12], m_matrix.e[13], m_matrix.e[15]);
|
||||
|
||||
m = m.inverse();
|
||||
|
||||
return Transform(
|
||||
m.v[0], m.v[3], m.v[6],
|
||||
m.v[1], m.v[4], m.v[7],
|
||||
m.v[2], m.v[5], m.v[8]
|
||||
);
|
||||
}
|
||||
|
||||
Transform& Transform::combine(const Transform& other)
|
||||
{
|
||||
m_matrix *= other.m_matrix;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue