From 8b00d67febf133e89f6a0bfabc41feed555dc4a9 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 12 Jan 2019 21:48:33 +0800 Subject: =?UTF-8?q?*=E5=8E=BB=E6=8E=89=E6=96=87=E4=BB=B6=E5=89=8D=E7=BC=80?= =?UTF-8?q?je=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/math/transform.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/libjin/math/transform.cpp (limited to 'src/libjin/math/transform.cpp') diff --git a/src/libjin/math/transform.cpp b/src/libjin/math/transform.cpp new file mode 100644 index 0000000..84c8327 --- /dev/null +++ b/src/libjin/math/transform.cpp @@ -0,0 +1,104 @@ +#include "transform.h" + +namespace JinEngine +{ + namespace Math + { + + Transform::Transform() + : mScale(1, 1) + , mPosition(0, 0) + , mOrigin(0, 0) + , mRotation(0) + { + } + + Transform::Transform(float x, float y, float sx, float sy, float r, float ox, float oy) + { + set(x, y, sx, sy, r, ox, oy); + } + + void Transform::set(float x, float y, float sx, float sy, float r, float ox, float oy) + { + setPosition(x, y); + setScale(sx, sy); + setRotation(r); + setOrigin(ox, oy); + } + + void Transform::setScale(float sx, float sy) + { + mScale.set(sx, sy); + } + + Vector2 Transform::getScale() const + { + return mScale; + } + + void Transform::scale(float sx, float sy) + { + mScale.x() *= sx; + mScale.y() *= sy; + } + + void Transform::setPosition(const Vector2& p) + { + setPosition(p.x(), p.y()); + } + + void Transform::setPosition(float x, float y) + { + mPosition.set(x, y); + } + + Vector2 Transform::getPosition() const + { + return mPosition; + } + + void Transform::move(float x, float y) + { + mPosition.x() += x; + mPosition.y() += y; + } + + void Transform::move(const Vector2& v) + { + move(v.x(), v.y()); + } + + void Transform::setOrigin(float x, float y) + { + mOrigin.set(x, y); + } + + Vector2 Transform::getOrigin() const + { + return mOrigin; + } + + void Transform::setRotation(float r) + { + mRotation = r; + } + + float Transform::getRotation() const + { + return mRotation; + } + + void Transform::rotate(float r) + { + mRotation += r; + } + + Matrix Transform::getMatrix() const + { + Matrix m; + m.setTransformation(mPosition.x(), mPosition.y(), mRotation, mScale.x(), mScale.y(), mOrigin.x(), mOrigin.y()); + return m; + } + + } +} \ No newline at end of file -- cgit v1.1-26-g67d0