Transform2D
This commit is contained in:
@@ -12,11 +12,31 @@ namespace J3ML::LinearAlgebra {
|
||||
const static Transform2D FlipX;
|
||||
const static Transform2D FlipY;
|
||||
|
||||
/// Default constructor initializes to an Identity tansformation.
|
||||
Transform2D()
|
||||
{
|
||||
transformation.Row(0) = {1, 0, 0};
|
||||
transformation.Row(1) = {0, 1, 0};
|
||||
transformation.Row(2) = {0, 0, 1};
|
||||
}
|
||||
|
||||
Transform2D(float rotation, const Vector2& pos);
|
||||
Transform2D(float px, float py, float sx, float sy, float ox, float oy, float kx, float ky, float rotation)
|
||||
{
|
||||
transformation = Matrix3x3(px, py, rotation, sx, sy, ox, oy, kx, ky);
|
||||
}
|
||||
|
||||
static Transform2D FromScale(float sx, float sy)
|
||||
{
|
||||
Transform2D s;
|
||||
s.transformation[0][0] = sx;
|
||||
s.transformation[1][1] = sy;
|
||||
return s;
|
||||
}
|
||||
static Transform2D FromScale(const Vector2& scale)
|
||||
{
|
||||
return FromScale(scale.x, scale.y);
|
||||
}
|
||||
Transform2D(const Vector2& pos, const Vector2& scale, const Vector2& origin, const Vector2& skew, float rotation);
|
||||
Transform2D(const Matrix3x3& transform);
|
||||
Transform2D Translate(const Vector2& offset) const;
|
||||
@@ -25,7 +45,13 @@ namespace J3ML::LinearAlgebra {
|
||||
Transform2D Scale(float x, float y); // Perform Nonunform Scale
|
||||
Transform2D Scale(const Vector2& scales); // Perform Nonuniform Scale
|
||||
Transform2D Rotate();
|
||||
Vector2 Transform(const Vector2& input) const;
|
||||
Vector2 Transform(const Vector2& point) const
|
||||
{
|
||||
Vector2 result;
|
||||
result.x = transformation.At(0,0) * point.x + transformation.At(0,1) * point.y + transformation.At(0,2);
|
||||
result.y = transformation.At(1,0) * point.x + transformation.At(1,1) * point.y + transformation.At(1,2);
|
||||
return result;
|
||||
}
|
||||
Transform2D Inverse() const;
|
||||
Transform2D AffineInverse() const;
|
||||
float Determinant() const;
|
||||
|
Reference in New Issue
Block a user