aboutsummaryrefslogtreecommitdiff
path: root/core/math/math_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/math/math_2d.cpp')
-rw-r--r--core/math/math_2d.cpp80
1 files changed, 40 insertions, 40 deletions
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp
index df9383ed1..c6860ba2e 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -408,22 +408,22 @@ bool Point2i::operator!=(const Point2i& p_vec2) const {
return x!=p_vec2.x || y!=p_vec2.y;
}
-void Matrix32::invert() {
+void Transform2D::invert() {
// FIXME: this function assumes the basis is a rotation matrix, with no scaling.
- // Matrix32::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
+ // Transform2D::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
SWAP(elements[0][1],elements[1][0]);
elements[2] = basis_xform(-elements[2]);
}
-Matrix32 Matrix32::inverse() const {
+Transform2D Transform2D::inverse() const {
- Matrix32 inv=*this;
+ Transform2D inv=*this;
inv.invert();
return inv;
}
-void Matrix32::affine_invert() {
+void Transform2D::affine_invert() {
real_t det = basis_determinant();
ERR_FAIL_COND(det==0);
@@ -437,27 +437,27 @@ void Matrix32::affine_invert() {
}
-Matrix32 Matrix32::affine_inverse() const {
+Transform2D Transform2D::affine_inverse() const {
- Matrix32 inv=*this;
+ Transform2D inv=*this;
inv.affine_invert();
return inv;
}
-void Matrix32::rotate(real_t p_phi) {
- *this = Matrix32(p_phi,Vector2()) * (*this);
+void Transform2D::rotate(real_t p_phi) {
+ *this = Transform2D(p_phi,Vector2()) * (*this);
}
-real_t Matrix32::get_rotation() const {
+real_t Transform2D::get_rotation() const {
real_t det = basis_determinant();
- Matrix32 m = orthonormalized();
+ Transform2D m = orthonormalized();
if (det < 0) {
m.scale_basis(Size2(-1,-1));
}
return Math::atan2(m[0].y,m[0].x);
}
-void Matrix32::set_rotation(real_t p_rot) {
+void Transform2D::set_rotation(real_t p_rot) {
real_t cr = Math::cos(p_rot);
real_t sr = Math::sin(p_rot);
@@ -467,7 +467,7 @@ void Matrix32::set_rotation(real_t p_rot) {
elements[1][1]=cr;
}
-Matrix32::Matrix32(real_t p_rot, const Vector2& p_pos) {
+Transform2D::Transform2D(real_t p_rot, const Vector2& p_pos) {
real_t cr = Math::cos(p_rot);
real_t sr = Math::sin(p_rot);
@@ -478,16 +478,16 @@ Matrix32::Matrix32(real_t p_rot, const Vector2& p_pos) {
elements[2]=p_pos;
}
-Size2 Matrix32::get_scale() const {
+Size2 Transform2D::get_scale() const {
real_t det_sign = basis_determinant() > 0 ? 1 : -1;
return det_sign * Size2( elements[0].length(), elements[1].length() );
}
-void Matrix32::scale(const Size2& p_scale) {
+void Transform2D::scale(const Size2& p_scale) {
scale_basis(p_scale);
elements[2]*=p_scale;
}
-void Matrix32::scale_basis(const Size2& p_scale) {
+void Transform2D::scale_basis(const Size2& p_scale) {
elements[0][0]*=p_scale.x;
elements[0][1]*=p_scale.y;
@@ -495,16 +495,16 @@ void Matrix32::scale_basis(const Size2& p_scale) {
elements[1][1]*=p_scale.y;
}
-void Matrix32::translate( real_t p_tx, real_t p_ty) {
+void Transform2D::translate( real_t p_tx, real_t p_ty) {
translate(Vector2(p_tx,p_ty));
}
-void Matrix32::translate( const Vector2& p_translation ) {
+void Transform2D::translate( const Vector2& p_translation ) {
elements[2]+=basis_xform(p_translation);
}
-void Matrix32::orthonormalize() {
+void Transform2D::orthonormalize() {
// Gram-Schmidt Process
@@ -518,15 +518,15 @@ void Matrix32::orthonormalize() {
elements[0]=x;
elements[1]=y;
}
-Matrix32 Matrix32::orthonormalized() const {
+Transform2D Transform2D::orthonormalized() const {
- Matrix32 on=*this;
+ Transform2D on=*this;
on.orthonormalize();
return on;
}
-bool Matrix32::operator==(const Matrix32& p_transform) const {
+bool Transform2D::operator==(const Transform2D& p_transform) const {
for(int i=0;i<3;i++) {
if (elements[i]!=p_transform.elements[i])
@@ -536,7 +536,7 @@ bool Matrix32::operator==(const Matrix32& p_transform) const {
return true;
}
-bool Matrix32::operator!=(const Matrix32& p_transform) const {
+bool Transform2D::operator!=(const Transform2D& p_transform) const {
for(int i=0;i<3;i++) {
if (elements[i]!=p_transform.elements[i])
@@ -547,7 +547,7 @@ bool Matrix32::operator!=(const Matrix32& p_transform) const {
}
-void Matrix32::operator*=(const Matrix32& p_transform) {
+void Transform2D::operator*=(const Transform2D& p_transform) {
elements[2] = xform(p_transform.elements[2]);
@@ -565,59 +565,59 @@ void Matrix32::operator*=(const Matrix32& p_transform) {
}
-Matrix32 Matrix32::operator*(const Matrix32& p_transform) const {
+Transform2D Transform2D::operator*(const Transform2D& p_transform) const {
- Matrix32 t = *this;
+ Transform2D t = *this;
t*=p_transform;
return t;
}
-Matrix32 Matrix32::scaled(const Size2& p_scale) const {
+Transform2D Transform2D::scaled(const Size2& p_scale) const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.scale(p_scale);
return copy;
}
-Matrix32 Matrix32::basis_scaled(const Size2& p_scale) const {
+Transform2D Transform2D::basis_scaled(const Size2& p_scale) const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.scale_basis(p_scale);
return copy;
}
-Matrix32 Matrix32::untranslated() const {
+Transform2D Transform2D::untranslated() const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.elements[2]=Vector2();
return copy;
}
-Matrix32 Matrix32::translated(const Vector2& p_offset) const {
+Transform2D Transform2D::translated(const Vector2& p_offset) const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.translate(p_offset);
return copy;
}
-Matrix32 Matrix32::rotated(real_t p_phi) const {
+Transform2D Transform2D::rotated(real_t p_phi) const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.rotate(p_phi);
return copy;
}
-real_t Matrix32::basis_determinant() const {
+real_t Transform2D::basis_determinant() const {
return elements[0].x * elements[1].y - elements[0].y * elements[1].x;
}
-Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, real_t p_c) const {
+Transform2D Transform2D::interpolate_with(const Transform2D& p_transform, real_t p_c) const {
//extract parameters
Vector2 p1 = get_origin();
@@ -648,12 +648,12 @@ Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, real_t p_c) con
}
//construct matrix
- Matrix32 res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c));
+ Transform2D res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c));
res.scale_basis(Vector2::linear_interpolate(s1, s2, p_c));
return res;
}
-Matrix32::operator String() const {
+Transform2D::operator String() const {
return String(String()+elements[0]+", "+elements[1]+", "+elements[2]);
}