Implement Transform2D
This commit is contained in:
@@ -2,4 +2,29 @@
|
||||
|
||||
namespace LinearAlgebra {
|
||||
|
||||
const Transform2D Transform2D::Identity = Transform2D({0, 0}, {1, 1}, {0,0}, {0,0}, 0);
|
||||
const Transform2D Transform2D::FlipX = Transform2D({0, 0}, {-1, 1}, {0,0}, {0,0}, 0);
|
||||
const Transform2D Transform2D::FlipY = Transform2D({0, 0}, {1, -1}, {0,0}, {0,0}, 0);
|
||||
|
||||
|
||||
Vector2 Transform2D::Transform(const Vector2 &input) const {
|
||||
return transformation * input;
|
||||
}
|
||||
|
||||
Transform2D::Transform2D(const Matrix3x3 &transform) : transformation(transform) { }
|
||||
|
||||
Transform2D::Transform2D(const Vector2& pos, const Vector2& scale, const Vector2& origin, const Vector2& skew, float rotation) {
|
||||
transformation = Matrix3x3(pos.x, pos.y, rotation, scale.x, scale.y, origin.x, origin.y, skew.x, skew.y);
|
||||
}
|
||||
|
||||
Transform2D Transform2D::Translate(float x, float y) const {
|
||||
auto copy = Matrix3x3(transformation);
|
||||
copy.SetAt(0, 0, transformation.At(0, 0) + x);
|
||||
copy.SetAt(0, 1, transformation.At(0, 1) + y);
|
||||
return Transform2D(copy);
|
||||
}
|
||||
|
||||
Transform2D Transform2D::Translate(const LinearAlgebra::Vector2 &input) const {
|
||||
return Translate(input.x, input.y);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user