Merge pull request #856 from aaronfranke/rename-elements

Rename Transform2D and Basis `elements` to `columns` and `rows` respectively
pull/859/head
Rémi Verschelde 2022-09-20 07:02:49 +02:00 committed by GitHub
commit 8670305589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 331 additions and 331 deletions

View File

@ -43,17 +43,17 @@ class Basis {
friend class Variant; friend class Variant;
public: public:
Vector3 elements[3] = { Vector3 rows[3] = {
Vector3(1, 0, 0), Vector3(1, 0, 0),
Vector3(0, 1, 0), Vector3(0, 1, 0),
Vector3(0, 0, 1) Vector3(0, 0, 1)
}; };
inline const Vector3 &operator[](int axis) const { inline const Vector3 &operator[](int axis) const {
return elements[axis]; return rows[axis];
} }
inline Vector3 &operator[](int axis) { inline Vector3 &operator[](int axis) {
return elements[axis]; return rows[axis];
} }
void invert(); void invert();
@ -67,14 +67,14 @@ public:
void from_z(const Vector3 &p_z); void from_z(const Vector3 &p_z);
inline Vector3 get_axis(int p_axis) const { inline Vector3 get_axis(int p_axis) const {
// get actual basis axis (elements is transposed for performance) // get actual basis axis (rows is transposed for performance)
return Vector3(elements[0][p_axis], elements[1][p_axis], elements[2][p_axis]); return Vector3(rows[0][p_axis], rows[1][p_axis], rows[2][p_axis]);
} }
inline void set_axis(int p_axis, const Vector3 &p_value) { inline void set_axis(int p_axis, const Vector3 &p_value) {
// get actual basis axis (elements is transposed for performance) // get actual basis axis (rows is transposed for performance)
elements[0][p_axis] = p_value.x; rows[0][p_axis] = p_value.x;
elements[1][p_axis] = p_value.y; rows[1][p_axis] = p_value.y;
elements[2][p_axis] = p_value.z; rows[2][p_axis] = p_value.z;
} }
void rotate(const Vector3 &p_axis, real_t p_phi); void rotate(const Vector3 &p_axis, real_t p_phi);
@ -143,13 +143,13 @@ public:
// transposed dot products // transposed dot products
inline real_t tdotx(const Vector3 &v) const { inline real_t tdotx(const Vector3 &v) const {
return elements[0][0] * v[0] + elements[1][0] * v[1] + elements[2][0] * v[2]; return rows[0][0] * v[0] + rows[1][0] * v[1] + rows[2][0] * v[2];
} }
inline real_t tdoty(const Vector3 &v) const { inline real_t tdoty(const Vector3 &v) const {
return elements[0][1] * v[0] + elements[1][1] * v[1] + elements[2][1] * v[2]; return rows[0][1] * v[0] + rows[1][1] * v[1] + rows[2][1] * v[2];
} }
inline real_t tdotz(const Vector3 &v) const { inline real_t tdotz(const Vector3 &v) const {
return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2]; return rows[0][2] * v[0] + rows[1][2] * v[1] + rows[2][2] * v[2];
} }
bool is_equal_approx(const Basis &p_basis) const; bool is_equal_approx(const Basis &p_basis) const;
@ -185,15 +185,15 @@ public:
/* create / set */ /* create / set */
inline void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { inline void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
elements[0][0] = xx; rows[0][0] = xx;
elements[0][1] = xy; rows[0][1] = xy;
elements[0][2] = xz; rows[0][2] = xz;
elements[1][0] = yx; rows[1][0] = yx;
elements[1][1] = yy; rows[1][1] = yy;
elements[1][2] = yz; rows[1][2] = yz;
elements[2][0] = zx; rows[2][0] = zx;
elements[2][1] = zy; rows[2][1] = zy;
elements[2][2] = zz; rows[2][2] = zz;
} }
inline void set(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z) { inline void set(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z) {
set_axis(0, p_x); set_axis(0, p_x);
@ -201,39 +201,39 @@ public:
set_axis(2, p_z); set_axis(2, p_z);
} }
inline Vector3 get_column(int i) const { inline Vector3 get_column(int i) const {
return Vector3(elements[0][i], elements[1][i], elements[2][i]); return Vector3(rows[0][i], rows[1][i], rows[2][i]);
} }
inline Vector3 get_row(int i) const { inline Vector3 get_row(int i) const {
return Vector3(elements[i][0], elements[i][1], elements[i][2]); return Vector3(rows[i][0], rows[i][1], rows[i][2]);
} }
inline Vector3 get_main_diagonal() const { inline Vector3 get_main_diagonal() const {
return Vector3(elements[0][0], elements[1][1], elements[2][2]); return Vector3(rows[0][0], rows[1][1], rows[2][2]);
} }
inline void set_row(int i, const Vector3 &p_row) { inline void set_row(int i, const Vector3 &p_row) {
elements[i][0] = p_row.x; rows[i][0] = p_row.x;
elements[i][1] = p_row.y; rows[i][1] = p_row.y;
elements[i][2] = p_row.z; rows[i][2] = p_row.z;
} }
inline void set_zero() { inline void set_zero() {
elements[0].zero(); rows[0].zero();
elements[1].zero(); rows[1].zero();
elements[2].zero(); rows[2].zero();
} }
inline Basis transpose_xform(const Basis &m) const { inline Basis transpose_xform(const Basis &m) const {
return Basis( return Basis(
elements[0].x * m[0].x + elements[1].x * m[1].x + elements[2].x * m[2].x, rows[0].x * m[0].x + rows[1].x * m[1].x + rows[2].x * m[2].x,
elements[0].x * m[0].y + elements[1].x * m[1].y + elements[2].x * m[2].y, rows[0].x * m[0].y + rows[1].x * m[1].y + rows[2].x * m[2].y,
elements[0].x * m[0].z + elements[1].x * m[1].z + elements[2].x * m[2].z, rows[0].x * m[0].z + rows[1].x * m[1].z + rows[2].x * m[2].z,
elements[0].y * m[0].x + elements[1].y * m[1].x + elements[2].y * m[2].x, rows[0].y * m[0].x + rows[1].y * m[1].x + rows[2].y * m[2].x,
elements[0].y * m[0].y + elements[1].y * m[1].y + elements[2].y * m[2].y, rows[0].y * m[0].y + rows[1].y * m[1].y + rows[2].y * m[2].y,
elements[0].y * m[0].z + elements[1].y * m[1].z + elements[2].y * m[2].z, rows[0].y * m[0].z + rows[1].y * m[1].z + rows[2].y * m[2].z,
elements[0].z * m[0].x + elements[1].z * m[1].x + elements[2].z * m[2].x, rows[0].z * m[0].x + rows[1].z * m[1].x + rows[2].z * m[2].x,
elements[0].z * m[0].y + elements[1].z * m[1].y + elements[2].z * m[2].y, rows[0].z * m[0].y + rows[1].z * m[1].y + rows[2].z * m[2].y,
elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z); rows[0].z * m[0].z + rows[1].z * m[1].z + rows[2].z * m[2].z);
} }
Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
set(xx, xy, xz, yx, yy, yz, zx, zy, zz); set(xx, xy, xz, yx, yy, yz, zx, zy, zz);
@ -269,22 +269,22 @@ public:
inline void Basis::operator*=(const Basis &p_matrix) { inline void Basis::operator*=(const Basis &p_matrix) {
set( set(
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), p_matrix.tdotx(rows[0]), p_matrix.tdoty(rows[0]), p_matrix.tdotz(rows[0]),
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]), p_matrix.tdotx(rows[1]), p_matrix.tdoty(rows[1]), p_matrix.tdotz(rows[1]),
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2])); p_matrix.tdotx(rows[2]), p_matrix.tdoty(rows[2]), p_matrix.tdotz(rows[2]));
} }
inline Basis Basis::operator*(const Basis &p_matrix) const { inline Basis Basis::operator*(const Basis &p_matrix) const {
return Basis( return Basis(
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), p_matrix.tdotx(rows[0]), p_matrix.tdoty(rows[0]), p_matrix.tdotz(rows[0]),
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]), p_matrix.tdotx(rows[1]), p_matrix.tdoty(rows[1]), p_matrix.tdotz(rows[1]),
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2])); p_matrix.tdotx(rows[2]), p_matrix.tdoty(rows[2]), p_matrix.tdotz(rows[2]));
} }
inline void Basis::operator+=(const Basis &p_matrix) { inline void Basis::operator+=(const Basis &p_matrix) {
elements[0] += p_matrix.elements[0]; rows[0] += p_matrix.rows[0];
elements[1] += p_matrix.elements[1]; rows[1] += p_matrix.rows[1];
elements[2] += p_matrix.elements[2]; rows[2] += p_matrix.rows[2];
} }
inline Basis Basis::operator+(const Basis &p_matrix) const { inline Basis Basis::operator+(const Basis &p_matrix) const {
@ -294,9 +294,9 @@ inline Basis Basis::operator+(const Basis &p_matrix) const {
} }
inline void Basis::operator-=(const Basis &p_matrix) { inline void Basis::operator-=(const Basis &p_matrix) {
elements[0] -= p_matrix.elements[0]; rows[0] -= p_matrix.rows[0];
elements[1] -= p_matrix.elements[1]; rows[1] -= p_matrix.rows[1];
elements[2] -= p_matrix.elements[2]; rows[2] -= p_matrix.rows[2];
} }
inline Basis Basis::operator-(const Basis &p_matrix) const { inline Basis Basis::operator-(const Basis &p_matrix) const {
@ -306,9 +306,9 @@ inline Basis Basis::operator-(const Basis &p_matrix) const {
} }
inline void Basis::operator*=(real_t p_val) { inline void Basis::operator*=(real_t p_val) {
elements[0] *= p_val; rows[0] *= p_val;
elements[1] *= p_val; rows[1] *= p_val;
elements[2] *= p_val; rows[2] *= p_val;
} }
inline Basis Basis::operator*(real_t p_val) const { inline Basis Basis::operator*(real_t p_val) const {
@ -319,22 +319,22 @@ inline Basis Basis::operator*(real_t p_val) const {
Vector3 Basis::xform(const Vector3 &p_vector) const { Vector3 Basis::xform(const Vector3 &p_vector) const {
return Vector3( return Vector3(
elements[0].dot(p_vector), rows[0].dot(p_vector),
elements[1].dot(p_vector), rows[1].dot(p_vector),
elements[2].dot(p_vector)); rows[2].dot(p_vector));
} }
Vector3 Basis::xform_inv(const Vector3 &p_vector) const { Vector3 Basis::xform_inv(const Vector3 &p_vector) const {
return Vector3( return Vector3(
(elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z), (rows[0][0] * p_vector.x) + (rows[1][0] * p_vector.y) + (rows[2][0] * p_vector.z),
(elements[0][1] * p_vector.x) + (elements[1][1] * p_vector.y) + (elements[2][1] * p_vector.z), (rows[0][1] * p_vector.x) + (rows[1][1] * p_vector.y) + (rows[2][1] * p_vector.z),
(elements[0][2] * p_vector.x) + (elements[1][2] * p_vector.y) + (elements[2][2] * p_vector.z)); (rows[0][2] * p_vector.x) + (rows[1][2] * p_vector.y) + (rows[2][2] * p_vector.z));
} }
real_t Basis::determinant() const { real_t Basis::determinant() const {
return elements[0][0] * (elements[1][1] * elements[2][2] - elements[2][1] * elements[1][2]) - return rows[0][0] * (rows[1][1] * rows[2][2] - rows[2][1] * rows[1][2]) -
elements[1][0] * (elements[0][1] * elements[2][2] - elements[2][1] * elements[0][2]) + rows[1][0] * (rows[0][1] * rows[2][2] - rows[2][1] * rows[0][2]) +
elements[2][0] * (elements[0][1] * elements[1][2] - elements[1][1] * elements[0][2]); rows[2][0] * (rows[0][1] * rows[1][2] - rows[1][1] * rows[0][2]);
} }
} // namespace godot } // namespace godot

View File

@ -45,32 +45,32 @@ class Transform2D {
friend class Variant; friend class Variant;
public: public:
// Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper": // Warning #1: basis of Transform2D is stored differently from Basis. In terms of columns array, the basis matrix looks like "on paper":
// M = (elements[0][0] elements[1][0]) // M = (columns[0][0] columns[1][0])
// (elements[0][1] elements[1][1]) // (columns[0][1] columns[1][1])
// This is such that the columns, which can be interpreted as basis vectors of the coordinate system "painted" on the object, can be accessed as elements[i]. // This is such that the columns, which can be interpreted as basis vectors of the coordinate system "painted" on the object, can be accessed as columns[i].
// Note that this is the opposite of the indices in mathematical texts, meaning: $M_{12}$ in a math book corresponds to elements[1][0] here. // Note that this is the opposite of the indices in mathematical texts, meaning: $M_{12}$ in a math book corresponds to columns[1][0] here.
// This requires additional care when working with explicit indices. // This requires additional care when working with explicit indices.
// See https://en.wikipedia.org/wiki/Row-_and_column-major_order for further reading. // See https://en.wikipedia.org/wiki/Row-_and_column-major_order for further reading.
// Warning #2: 2D be aware that unlike 3D code, 2D code uses a left-handed coordinate system: Y-axis points down, // Warning #2: 2D be aware that unlike 3D code, 2D code uses a left-handed coordinate system: Y-axis points down,
// and angle is measure from +X to +Y in a clockwise-fashion. // and angle is measure from +X to +Y in a clockwise-fashion.
Vector2 elements[3]; Vector2 columns[3];
inline real_t tdotx(const Vector2 &v) const { return elements[0][0] * v.x + elements[1][0] * v.y; } inline real_t tdotx(const Vector2 &v) const { return columns[0][0] * v.x + columns[1][0] * v.y; }
inline real_t tdoty(const Vector2 &v) const { return elements[0][1] * v.x + elements[1][1] * v.y; } inline real_t tdoty(const Vector2 &v) const { return columns[0][1] * v.x + columns[1][1] * v.y; }
const Vector2 &operator[](int p_idx) const { return elements[p_idx]; } const Vector2 &operator[](int p_idx) const { return columns[p_idx]; }
Vector2 &operator[](int p_idx) { return elements[p_idx]; } Vector2 &operator[](int p_idx) { return columns[p_idx]; }
inline Vector2 get_axis(int p_axis) const { inline Vector2 get_axis(int p_axis) const {
ERR_FAIL_INDEX_V(p_axis, 3, Vector2()); ERR_FAIL_INDEX_V(p_axis, 3, Vector2());
return elements[p_axis]; return columns[p_axis];
} }
inline void set_axis(int p_axis, const Vector2 &p_vec) { inline void set_axis(int p_axis, const Vector2 &p_vec) {
ERR_FAIL_INDEX(p_axis, 3); ERR_FAIL_INDEX(p_axis, 3);
elements[p_axis] = p_vec; columns[p_axis] = p_vec;
} }
void invert(); void invert();
@ -97,8 +97,8 @@ public:
Size2 get_scale() const; Size2 get_scale() const;
void set_scale(const Size2 &p_scale); void set_scale(const Size2 &p_scale);
inline const Vector2 &get_origin() const { return elements[2]; } inline const Vector2 &get_origin() const { return columns[2]; }
inline void set_origin(const Vector2 &p_origin) { elements[2] = p_origin; } inline void set_origin(const Vector2 &p_origin) { columns[2] = p_origin; }
Transform2D scaled(const Size2 &p_scale) const; Transform2D scaled(const Size2 &p_scale) const;
Transform2D basis_scaled(const Size2 &p_scale) const; Transform2D basis_scaled(const Size2 &p_scale) const;
@ -131,24 +131,24 @@ public:
operator String() const; operator String() const;
Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) { Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) {
elements[0][0] = xx; columns[0][0] = xx;
elements[0][1] = xy; columns[0][1] = xy;
elements[1][0] = yx; columns[1][0] = yx;
elements[1][1] = yy; columns[1][1] = yy;
elements[2][0] = ox; columns[2][0] = ox;
elements[2][1] = oy; columns[2][1] = oy;
} }
Transform2D(const Vector2 &p_x, const Vector2 &p_y, const Vector2 &p_origin) { Transform2D(const Vector2 &p_x, const Vector2 &p_y, const Vector2 &p_origin) {
elements[0] = p_x; columns[0] = p_x;
elements[1] = p_y; columns[1] = p_y;
elements[2] = p_origin; columns[2] = p_origin;
} }
Transform2D(real_t p_rot, const Vector2 &p_pos); Transform2D(real_t p_rot, const Vector2 &p_pos);
Transform2D() { Transform2D() {
elements[0][0] = 1.0; columns[0][0] = 1.0;
elements[1][1] = 1.0; columns[1][1] = 1.0;
} }
}; };
@ -160,28 +160,28 @@ Vector2 Transform2D::basis_xform(const Vector2 &p_vec) const {
Vector2 Transform2D::basis_xform_inv(const Vector2 &p_vec) const { Vector2 Transform2D::basis_xform_inv(const Vector2 &p_vec) const {
return Vector2( return Vector2(
elements[0].dot(p_vec), columns[0].dot(p_vec),
elements[1].dot(p_vec)); columns[1].dot(p_vec));
} }
Vector2 Transform2D::xform(const Vector2 &p_vec) const { Vector2 Transform2D::xform(const Vector2 &p_vec) const {
return Vector2( return Vector2(
tdotx(p_vec), tdotx(p_vec),
tdoty(p_vec)) + tdoty(p_vec)) +
elements[2]; columns[2];
} }
Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const {
Vector2 v = p_vec - elements[2]; Vector2 v = p_vec - columns[2];
return Vector2( return Vector2(
elements[0].dot(v), columns[0].dot(v),
elements[1].dot(v)); columns[1].dot(v));
} }
Rect2 Transform2D::xform(const Rect2 &p_rect) const { Rect2 Transform2D::xform(const Rect2 &p_rect) const {
Vector2 x = elements[0] * p_rect.size.x; Vector2 x = columns[0] * p_rect.size.x;
Vector2 y = elements[1] * p_rect.size.y; Vector2 y = columns[1] * p_rect.size.y;
Vector2 pos = xform(p_rect.position); Vector2 pos = xform(p_rect.position);
Rect2 new_rect; Rect2 new_rect;
@ -193,17 +193,17 @@ Rect2 Transform2D::xform(const Rect2 &p_rect) const {
} }
void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) { void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) {
elements[0][0] = Math::cos(p_rot) * p_scale.x; columns[0][0] = Math::cos(p_rot) * p_scale.x;
elements[1][1] = Math::cos(p_rot) * p_scale.y; columns[1][1] = Math::cos(p_rot) * p_scale.y;
elements[1][0] = -Math::sin(p_rot) * p_scale.y; columns[1][0] = -Math::sin(p_rot) * p_scale.y;
elements[0][1] = Math::sin(p_rot) * p_scale.x; columns[0][1] = Math::sin(p_rot) * p_scale.x;
} }
void Transform2D::set_rotation_scale_and_skew(real_t p_rot, const Size2 &p_scale, float p_skew) { void Transform2D::set_rotation_scale_and_skew(real_t p_rot, const Size2 &p_scale, float p_skew) {
elements[0][0] = Math::cos(p_rot) * p_scale.x; columns[0][0] = Math::cos(p_rot) * p_scale.x;
elements[1][1] = Math::cos(p_rot + p_skew) * p_scale.y; columns[1][1] = Math::cos(p_rot + p_skew) * p_scale.y;
elements[1][0] = -Math::sin(p_rot + p_skew) * p_scale.y; columns[1][0] = -Math::sin(p_rot + p_skew) * p_scale.y;
elements[0][1] = Math::sin(p_rot) * p_scale.x; columns[0][1] = Math::sin(p_rot) * p_scale.x;
} }
Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const { Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const {

View File

@ -134,9 +134,9 @@ inline Vector3 Transform3D::xform_inv(const Vector3 &p_vector) const {
Vector3 v = p_vector - origin; Vector3 v = p_vector - origin;
return Vector3( return Vector3(
(basis.elements[0][0] * v.x) + (basis.elements[1][0] * v.y) + (basis.elements[2][0] * v.z), (basis.rows[0][0] * v.x) + (basis.rows[1][0] * v.y) + (basis.rows[2][0] * v.z),
(basis.elements[0][1] * v.x) + (basis.elements[1][1] * v.y) + (basis.elements[2][1] * v.z), (basis.rows[0][1] * v.x) + (basis.rows[1][1] * v.y) + (basis.rows[2][1] * v.z),
(basis.elements[0][2] * v.x) + (basis.elements[1][2] * v.y) + (basis.elements[2][2] * v.z)); (basis.rows[0][2] * v.x) + (basis.rows[1][2] * v.y) + (basis.rows[2][2] * v.z));
} }
inline Plane Transform3D::xform(const Plane &p_plane) const { inline Plane Transform3D::xform(const Plane &p_plane) const {

View File

@ -33,7 +33,7 @@
#include <godot_cpp/variant/string.hpp> #include <godot_cpp/variant/string.hpp>
#define cofac(row1, col1, row2, col2) \ #define cofac(row1, col1, row2, col2) \
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1]) (rows[row1][col1] * rows[row2][col2] - rows[row1][col2] * rows[row2][col1])
namespace godot { namespace godot {
@ -42,25 +42,25 @@ void Basis::from_z(const Vector3 &p_z) {
// choose p in y-z plane // choose p in y-z plane
real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2]; real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2];
real_t k = 1.0 / Math::sqrt(a); real_t k = 1.0 / Math::sqrt(a);
elements[0] = Vector3(0, -p_z[2] * k, p_z[1] * k); rows[0] = Vector3(0, -p_z[2] * k, p_z[1] * k);
elements[1] = Vector3(a * k, -p_z[0] * elements[0][2], p_z[0] * elements[0][1]); rows[1] = Vector3(a * k, -p_z[0] * rows[0][2], p_z[0] * rows[0][1]);
} else { } else {
// choose p in x-y plane // choose p in x-y plane
real_t a = p_z.x * p_z.x + p_z.y * p_z.y; real_t a = p_z.x * p_z.x + p_z.y * p_z.y;
real_t k = 1.0 / Math::sqrt(a); real_t k = 1.0 / Math::sqrt(a);
elements[0] = Vector3(-p_z.y * k, p_z.x * k, 0); rows[0] = Vector3(-p_z.y * k, p_z.x * k, 0);
elements[1] = Vector3(-p_z.z * elements[0].y, p_z.z * elements[0].x, a * k); rows[1] = Vector3(-p_z.z * rows[0].y, p_z.z * rows[0].x, a * k);
} }
elements[2] = p_z; rows[2] = p_z;
} }
void Basis::invert() { void Basis::invert() {
real_t co[3] = { real_t co[3] = {
cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1) cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)
}; };
real_t det = elements[0][0] * co[0] + real_t det = rows[0][0] * co[0] +
elements[0][1] * co[1] + rows[0][1] * co[1] +
elements[0][2] * co[2]; rows[0][2] * co[2];
#ifdef MATH_CHECKS #ifdef MATH_CHECKS
ERR_FAIL_COND(det == 0); ERR_FAIL_COND(det == 0);
#endif #endif
@ -104,9 +104,9 @@ bool Basis::is_orthogonal() const {
bool Basis::is_diagonal() const { bool Basis::is_diagonal() const {
return ( return (
Math::is_zero_approx(elements[0][1]) && Math::is_zero_approx(elements[0][2]) && Math::is_zero_approx(rows[0][1]) && Math::is_zero_approx(rows[0][2]) &&
Math::is_zero_approx(elements[1][0]) && Math::is_zero_approx(elements[1][2]) && Math::is_zero_approx(rows[1][0]) && Math::is_zero_approx(rows[1][2]) &&
Math::is_zero_approx(elements[2][0]) && Math::is_zero_approx(elements[2][1])); Math::is_zero_approx(rows[2][0]) && Math::is_zero_approx(rows[2][1]));
} }
bool Basis::is_rotation() const { bool Basis::is_rotation() const {
@ -116,13 +116,13 @@ bool Basis::is_rotation() const {
#ifdef MATH_CHECKS #ifdef MATH_CHECKS
// This method is only used once, in diagonalize. If it's desired elsewhere, feel free to remove the #ifdef. // This method is only used once, in diagonalize. If it's desired elsewhere, feel free to remove the #ifdef.
bool Basis::is_symmetric() const { bool Basis::is_symmetric() const {
if (!Math::is_equal_approx(elements[0][1], elements[1][0])) { if (!Math::is_equal_approx(rows[0][1], rows[1][0])) {
return false; return false;
} }
if (!Math::is_equal_approx(elements[0][2], elements[2][0])) { if (!Math::is_equal_approx(rows[0][2], rows[2][0])) {
return false; return false;
} }
if (!Math::is_equal_approx(elements[1][2], elements[2][1])) { if (!Math::is_equal_approx(rows[1][2], rows[2][1])) {
return false; return false;
} }
@ -138,14 +138,14 @@ Basis Basis::diagonalize() {
#endif #endif
const int ite_max = 1024; const int ite_max = 1024;
real_t off_matrix_norm_2 = elements[0][1] * elements[0][1] + elements[0][2] * elements[0][2] + elements[1][2] * elements[1][2]; real_t off_matrix_norm_2 = rows[0][1] * rows[0][1] + rows[0][2] * rows[0][2] + rows[1][2] * rows[1][2];
int ite = 0; int ite = 0;
Basis acc_rot; Basis acc_rot;
while (off_matrix_norm_2 > CMP_EPSILON2 && ite++ < ite_max) { while (off_matrix_norm_2 > CMP_EPSILON2 && ite++ < ite_max) {
real_t el01_2 = elements[0][1] * elements[0][1]; real_t el01_2 = rows[0][1] * rows[0][1];
real_t el02_2 = elements[0][2] * elements[0][2]; real_t el02_2 = rows[0][2] * rows[0][2];
real_t el12_2 = elements[1][2] * elements[1][2]; real_t el12_2 = rows[1][2] * rows[1][2];
// Find the pivot element // Find the pivot element
int i, j; int i, j;
if (el01_2 > el02_2) { if (el01_2 > el02_2) {
@ -168,19 +168,19 @@ Basis Basis::diagonalize() {
// Compute the rotation angle // Compute the rotation angle
real_t angle; real_t angle;
if (Math::is_equal_approx(elements[j][j], elements[i][i])) { if (Math::is_equal_approx(rows[j][j], rows[i][i])) {
angle = Math_PI / 4; angle = Math_PI / 4;
} else { } else {
angle = 0.5 * Math::atan(2 * elements[i][j] / (elements[j][j] - elements[i][i])); angle = 0.5 * Math::atan(2 * rows[i][j] / (rows[j][j] - rows[i][i]));
} }
// Compute the rotation matrix // Compute the rotation matrix
Basis rot; Basis rot;
rot.elements[i][i] = rot.elements[j][j] = Math::cos(angle); rot.rows[i][i] = rot.rows[j][j] = Math::cos(angle);
rot.elements[i][j] = -(rot.elements[j][i] = Math::sin(angle)); rot.rows[i][j] = -(rot.rows[j][i] = Math::sin(angle));
// Update the off matrix norm // Update the off matrix norm
off_matrix_norm_2 -= elements[i][j] * elements[i][j]; off_matrix_norm_2 -= rows[i][j] * rows[i][j];
// Apply the rotation // Apply the rotation
*this = rot * *this * rot.transposed(); *this = rot * *this * rot.transposed();
@ -197,9 +197,9 @@ Basis Basis::inverse() const {
} }
void Basis::transpose() { void Basis::transpose() {
SWAP(elements[0][1], elements[1][0]); SWAP(rows[0][1], rows[1][0]);
SWAP(elements[0][2], elements[2][0]); SWAP(rows[0][2], rows[2][0]);
SWAP(elements[1][2], elements[2][1]); SWAP(rows[1][2], rows[2][1]);
} }
Basis Basis::transposed() const { Basis Basis::transposed() const {
@ -211,15 +211,15 @@ Basis Basis::transposed() const {
// Multiplies the matrix from left by the scaling matrix: M -> S.M // Multiplies the matrix from left by the scaling matrix: M -> S.M
// See the comment for Basis::rotated for further explanation. // See the comment for Basis::rotated for further explanation.
void Basis::scale(const Vector3 &p_scale) { void Basis::scale(const Vector3 &p_scale) {
elements[0][0] *= p_scale.x; rows[0][0] *= p_scale.x;
elements[0][1] *= p_scale.x; rows[0][1] *= p_scale.x;
elements[0][2] *= p_scale.x; rows[0][2] *= p_scale.x;
elements[1][0] *= p_scale.y; rows[1][0] *= p_scale.y;
elements[1][1] *= p_scale.y; rows[1][1] *= p_scale.y;
elements[1][2] *= p_scale.y; rows[1][2] *= p_scale.y;
elements[2][0] *= p_scale.z; rows[2][0] *= p_scale.z;
elements[2][1] *= p_scale.z; rows[2][1] *= p_scale.z;
elements[2][2] *= p_scale.z; rows[2][2] *= p_scale.z;
} }
Basis Basis::scaled(const Vector3 &p_scale) const { Basis Basis::scaled(const Vector3 &p_scale) const {
@ -235,14 +235,14 @@ void Basis::scale_local(const Vector3 &p_scale) {
} }
float Basis::get_uniform_scale() const { float Basis::get_uniform_scale() const {
return (elements[0].length() + elements[1].length() + elements[2].length()) / 3.0; return (rows[0].length() + rows[1].length() + rows[2].length()) / 3.0;
} }
void Basis::make_scale_uniform() { void Basis::make_scale_uniform() {
float l = (elements[0].length() + elements[1].length() + elements[2].length()) / 3.0; float l = (rows[0].length() + rows[1].length() + rows[2].length()) / 3.0;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
elements[i].normalize(); rows[i].normalize();
elements[i] *= l; rows[i] *= l;
} }
} }
@ -255,14 +255,14 @@ Basis Basis::scaled_local(const Vector3 &p_scale) const {
Vector3 Basis::get_scale_abs() const { Vector3 Basis::get_scale_abs() const {
return Vector3( return Vector3(
Vector3(elements[0][0], elements[1][0], elements[2][0]).length(), Vector3(rows[0][0], rows[1][0], rows[2][0]).length(),
Vector3(elements[0][1], elements[1][1], elements[2][1]).length(), Vector3(rows[0][1], rows[1][1], rows[2][1]).length(),
Vector3(elements[0][2], elements[1][2], elements[2][2]).length()); Vector3(rows[0][2], rows[1][2], rows[2][2]).length());
} }
Vector3 Basis::get_scale_local() const { Vector3 Basis::get_scale_local() const {
real_t det_sign = Math::sign(determinant()); real_t det_sign = Math::sign(determinant());
return det_sign * Vector3(elements[0].length(), elements[1].length(), elements[2].length()); return det_sign * Vector3(rows[0].length(), rows[1].length(), rows[2].length());
} }
// get_scale works with get_rotation, use get_scale_abs if you need to enforce positive signature. // get_scale works with get_rotation, use get_scale_abs if you need to enforce positive signature.
@ -284,14 +284,14 @@ Vector3 Basis::get_scale() const {
// //
// A proper way to get rid of this issue would be to store the scaling values (or at least their signs) // A proper way to get rid of this issue would be to store the scaling values (or at least their signs)
// as a part of Basis. However, if we go that path, we need to disable direct (write) access to the // as a part of Basis. However, if we go that path, we need to disable direct (write) access to the
// matrix elements. // matrix rows.
// //
// The rotation part of this decomposition is returned by get_rotation* functions. // The rotation part of this decomposition is returned by get_rotation* functions.
real_t det_sign = Math::sign(determinant()); real_t det_sign = Math::sign(determinant());
return det_sign * Vector3( return det_sign * Vector3(
Vector3(elements[0][0], elements[1][0], elements[2][0]).length(), Vector3(rows[0][0], rows[1][0], rows[2][0]).length(),
Vector3(elements[0][1], elements[1][1], elements[2][1]).length(), Vector3(rows[0][1], rows[1][1], rows[2][1]).length(),
Vector3(elements[0][2], elements[1][2], elements[2][2]).length()); Vector3(rows[0][2], rows[1][2], rows[2][2]).length());
} }
// Decomposes a Basis into a rotation-reflection matrix (an element of the group O(3)) and a positive scaling matrix as B = O.S. // Decomposes a Basis into a rotation-reflection matrix (an element of the group O(3)) and a positive scaling matrix as B = O.S.
@ -431,27 +431,27 @@ Vector3 Basis::get_euler_xyz() const {
// -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy // -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy
Vector3 euler; Vector3 euler;
real_t sy = elements[0][2]; real_t sy = rows[0][2];
if (sy < (1.0 - CMP_EPSILON)) { if (sy < (1.0 - CMP_EPSILON)) {
if (sy > -(1.0 - CMP_EPSILON)) { if (sy > -(1.0 - CMP_EPSILON)) {
// is this a pure Y rotation? // is this a pure Y rotation?
if (elements[1][0] == 0.0 && elements[0][1] == 0.0 && elements[1][2] == 0 && elements[2][1] == 0 && elements[1][1] == 1) { if (rows[1][0] == 0.0 && rows[0][1] == 0.0 && rows[1][2] == 0 && rows[2][1] == 0 && rows[1][1] == 1) {
// return the simplest form (human friendlier in editor and scripts) // return the simplest form (human friendlier in editor and scripts)
euler.x = 0; euler.x = 0;
euler.y = atan2(elements[0][2], elements[0][0]); euler.y = atan2(rows[0][2], rows[0][0]);
euler.z = 0; euler.z = 0;
} else { } else {
euler.x = Math::atan2(-elements[1][2], elements[2][2]); euler.x = Math::atan2(-rows[1][2], rows[2][2]);
euler.y = Math::asin(sy); euler.y = Math::asin(sy);
euler.z = Math::atan2(-elements[0][1], elements[0][0]); euler.z = Math::atan2(-rows[0][1], rows[0][0]);
} }
} else { } else {
euler.x = Math::atan2(elements[2][1], elements[1][1]); euler.x = Math::atan2(rows[2][1], rows[1][1]);
euler.y = -Math_PI / 2.0; euler.y = -Math_PI / 2.0;
euler.z = 0.0; euler.z = 0.0;
} }
} else { } else {
euler.x = Math::atan2(elements[2][1], elements[1][1]); euler.x = Math::atan2(rows[2][1], rows[1][1]);
euler.y = Math_PI / 2.0; euler.y = Math_PI / 2.0;
euler.z = 0.0; euler.z = 0.0;
} }
@ -490,21 +490,21 @@ Vector3 Basis::get_euler_xzy() const {
// cy*sx*sz cz*sx cx*cy+sx*sz*sy // cy*sx*sz cz*sx cx*cy+sx*sz*sy
Vector3 euler; Vector3 euler;
real_t sz = elements[0][1]; real_t sz = rows[0][1];
if (sz < (1.0 - CMP_EPSILON)) { if (sz < (1.0 - CMP_EPSILON)) {
if (sz > -(1.0 - CMP_EPSILON)) { if (sz > -(1.0 - CMP_EPSILON)) {
euler.x = Math::atan2(elements[2][1], elements[1][1]); euler.x = Math::atan2(rows[2][1], rows[1][1]);
euler.y = Math::atan2(elements[0][2], elements[0][0]); euler.y = Math::atan2(rows[0][2], rows[0][0]);
euler.z = Math::asin(-sz); euler.z = Math::asin(-sz);
} else { } else {
// It's -1 // It's -1
euler.x = -Math::atan2(elements[1][2], elements[2][2]); euler.x = -Math::atan2(rows[1][2], rows[2][2]);
euler.y = 0.0; euler.y = 0.0;
euler.z = Math_PI / 2.0; euler.z = Math_PI / 2.0;
} }
} else { } else {
// It's 1 // It's 1
euler.x = -Math::atan2(elements[1][2], elements[2][2]); euler.x = -Math::atan2(rows[1][2], rows[2][2]);
euler.y = 0.0; euler.y = 0.0;
euler.z = -Math_PI / 2.0; euler.z = -Math_PI / 2.0;
} }
@ -538,21 +538,21 @@ Vector3 Basis::get_euler_yzx() const {
// -cz*sy cy*sx+cx*sy*sz cy*cx-sy*sz*sx // -cz*sy cy*sx+cx*sy*sz cy*cx-sy*sz*sx
Vector3 euler; Vector3 euler;
real_t sz = elements[1][0]; real_t sz = rows[1][0];
if (sz < (1.0 - CMP_EPSILON)) { if (sz < (1.0 - CMP_EPSILON)) {
if (sz > -(1.0 - CMP_EPSILON)) { if (sz > -(1.0 - CMP_EPSILON)) {
euler.x = Math::atan2(-elements[1][2], elements[1][1]); euler.x = Math::atan2(-rows[1][2], rows[1][1]);
euler.y = Math::atan2(-elements[2][0], elements[0][0]); euler.y = Math::atan2(-rows[2][0], rows[0][0]);
euler.z = Math::asin(sz); euler.z = Math::asin(sz);
} else { } else {
// It's -1 // It's -1
euler.x = Math::atan2(elements[2][1], elements[2][2]); euler.x = Math::atan2(rows[2][1], rows[2][2]);
euler.y = 0.0; euler.y = 0.0;
euler.z = -Math_PI / 2.0; euler.z = -Math_PI / 2.0;
} }
} else { } else {
// It's 1 // It's 1
euler.x = Math::atan2(elements[2][1], elements[2][2]); euler.x = Math::atan2(rows[2][1], rows[2][2]);
euler.y = 0.0; euler.y = 0.0;
euler.z = Math_PI / 2.0; euler.z = Math_PI / 2.0;
} }
@ -590,29 +590,29 @@ Vector3 Basis::get_euler_yxz() const {
Vector3 euler; Vector3 euler;
real_t m12 = elements[1][2]; real_t m12 = rows[1][2];
if (m12 < (1 - CMP_EPSILON)) { if (m12 < (1 - CMP_EPSILON)) {
if (m12 > -(1 - CMP_EPSILON)) { if (m12 > -(1 - CMP_EPSILON)) {
// is this a pure X rotation? // is this a pure X rotation?
if (elements[1][0] == 0 && elements[0][1] == 0 && elements[0][2] == 0 && elements[2][0] == 0 && elements[0][0] == 1) { if (rows[1][0] == 0 && rows[0][1] == 0 && rows[0][2] == 0 && rows[2][0] == 0 && rows[0][0] == 1) {
// return the simplest form (human friendlier in editor and scripts) // return the simplest form (human friendlier in editor and scripts)
euler.x = atan2(-m12, elements[1][1]); euler.x = atan2(-m12, rows[1][1]);
euler.y = 0; euler.y = 0;
euler.z = 0; euler.z = 0;
} else { } else {
euler.x = asin(-m12); euler.x = asin(-m12);
euler.y = atan2(elements[0][2], elements[2][2]); euler.y = atan2(rows[0][2], rows[2][2]);
euler.z = atan2(elements[1][0], elements[1][1]); euler.z = atan2(rows[1][0], rows[1][1]);
} }
} else { // m12 == -1 } else { // m12 == -1
euler.x = Math_PI * 0.5; euler.x = Math_PI * 0.5;
euler.y = atan2(elements[0][1], elements[0][0]); euler.y = atan2(rows[0][1], rows[0][0]);
euler.z = 0; euler.z = 0;
} }
} else { // m12 == 1 } else { // m12 == 1
euler.x = -Math_PI * 0.5; euler.x = -Math_PI * 0.5;
euler.y = -atan2(elements[0][1], elements[0][0]); euler.y = -atan2(rows[0][1], rows[0][0]);
euler.z = 0; euler.z = 0;
} }
@ -650,22 +650,22 @@ Vector3 Basis::get_euler_zxy() const {
// cy*sz+cz*sx*sy cz*cx sz*sy-cz*cy*sx // cy*sz+cz*sx*sy cz*cx sz*sy-cz*cy*sx
// -cx*sy sx cx*cy // -cx*sy sx cx*cy
Vector3 euler; Vector3 euler;
real_t sx = elements[2][1]; real_t sx = rows[2][1];
if (sx < (1.0 - CMP_EPSILON)) { if (sx < (1.0 - CMP_EPSILON)) {
if (sx > -(1.0 - CMP_EPSILON)) { if (sx > -(1.0 - CMP_EPSILON)) {
euler.x = Math::asin(sx); euler.x = Math::asin(sx);
euler.y = Math::atan2(-elements[2][0], elements[2][2]); euler.y = Math::atan2(-rows[2][0], rows[2][2]);
euler.z = Math::atan2(-elements[0][1], elements[1][1]); euler.z = Math::atan2(-rows[0][1], rows[1][1]);
} else { } else {
// It's -1 // It's -1
euler.x = -Math_PI / 2.0; euler.x = -Math_PI / 2.0;
euler.y = Math::atan2(elements[0][2], elements[0][0]); euler.y = Math::atan2(rows[0][2], rows[0][0]);
euler.z = 0; euler.z = 0;
} }
} else { } else {
// It's 1 // It's 1
euler.x = Math_PI / 2.0; euler.x = Math_PI / 2.0;
euler.y = Math::atan2(elements[0][2], elements[0][0]); euler.y = Math::atan2(rows[0][2], rows[0][0]);
euler.z = 0; euler.z = 0;
} }
return euler; return euler;
@ -697,23 +697,23 @@ Vector3 Basis::get_euler_zyx() const {
// cy*sz cz*cx+sz*sy*sx cx*sz*sy-cz*sx // cy*sz cz*cx+sz*sy*sx cx*sz*sy-cz*sx
// -sy cy*sx cy*cx // -sy cy*sx cy*cx
Vector3 euler; Vector3 euler;
real_t sy = elements[2][0]; real_t sy = rows[2][0];
if (sy < (1.0 - CMP_EPSILON)) { if (sy < (1.0 - CMP_EPSILON)) {
if (sy > -(1.0 - CMP_EPSILON)) { if (sy > -(1.0 - CMP_EPSILON)) {
euler.x = Math::atan2(elements[2][1], elements[2][2]); euler.x = Math::atan2(rows[2][1], rows[2][2]);
euler.y = Math::asin(-sy); euler.y = Math::asin(-sy);
euler.z = Math::atan2(elements[1][0], elements[0][0]); euler.z = Math::atan2(rows[1][0], rows[0][0]);
} else { } else {
// It's -1 // It's -1
euler.x = 0; euler.x = 0;
euler.y = Math_PI / 2.0; euler.y = Math_PI / 2.0;
euler.z = -Math::atan2(elements[0][1], elements[1][1]); euler.z = -Math::atan2(rows[0][1], rows[1][1]);
} }
} else { } else {
// It's 1 // It's 1
euler.x = 0; euler.x = 0;
euler.y = -Math_PI / 2.0; euler.y = -Math_PI / 2.0;
euler.z = -Math::atan2(elements[0][1], elements[1][1]); euler.z = -Math::atan2(rows[0][1], rows[1][1]);
} }
return euler; return euler;
} }
@ -737,13 +737,13 @@ void Basis::set_euler_zyx(const Vector3 &p_euler) {
} }
bool Basis::is_equal_approx(const Basis &p_basis) const { bool Basis::is_equal_approx(const Basis &p_basis) const {
return elements[0].is_equal_approx(p_basis.elements[0]) && elements[1].is_equal_approx(p_basis.elements[1]) && elements[2].is_equal_approx(p_basis.elements[2]); return rows[0].is_equal_approx(p_basis.rows[0]) && rows[1].is_equal_approx(p_basis.rows[1]) && rows[2].is_equal_approx(p_basis.rows[2]);
} }
bool Basis::operator==(const Basis &p_matrix) const { bool Basis::operator==(const Basis &p_matrix) const {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) { for (int j = 0; j < 3; j++) {
if (elements[i][j] != p_matrix.elements[i][j]) { if (rows[i][j] != p_matrix.rows[i][j]) {
return false; return false;
} }
} }
@ -764,7 +764,7 @@ Basis::operator String() const {
mtx = mtx + ", "; mtx = mtx + ", ";
} }
mtx = mtx + String::num(elements[j][i]); // matrix is stored transposed for performance, so print it transposed mtx = mtx + String::num(rows[j][i]); // matrix is stored transposed for performance, so print it transposed
} }
} }
@ -777,7 +777,7 @@ Quaternion Basis::get_quaternion() const {
#endif #endif
/* Allow getting a quaternion from an unnormalized transform */ /* Allow getting a quaternion from an unnormalized transform */
Basis m = *this; Basis m = *this;
real_t trace = m.elements[0][0] + m.elements[1][1] + m.elements[2][2]; real_t trace = m.rows[0][0] + m.rows[1][1] + m.rows[2][2];
real_t temp[4]; real_t temp[4];
if (trace > 0.0) { if (trace > 0.0) {
@ -785,23 +785,23 @@ Quaternion Basis::get_quaternion() const {
temp[3] = (s * 0.5); temp[3] = (s * 0.5);
s = 0.5 / s; s = 0.5 / s;
temp[0] = ((m.elements[2][1] - m.elements[1][2]) * s); temp[0] = ((m.rows[2][1] - m.rows[1][2]) * s);
temp[1] = ((m.elements[0][2] - m.elements[2][0]) * s); temp[1] = ((m.rows[0][2] - m.rows[2][0]) * s);
temp[2] = ((m.elements[1][0] - m.elements[0][1]) * s); temp[2] = ((m.rows[1][0] - m.rows[0][1]) * s);
} else { } else {
int i = m.elements[0][0] < m.elements[1][1] ? int i = m.rows[0][0] < m.rows[1][1] ?
(m.elements[1][1] < m.elements[2][2] ? 2 : 1) : (m.rows[1][1] < m.rows[2][2] ? 2 : 1) :
(m.elements[0][0] < m.elements[2][2] ? 2 : 0); (m.rows[0][0] < m.rows[2][2] ? 2 : 0);
int j = (i + 1) % 3; int j = (i + 1) % 3;
int k = (i + 2) % 3; int k = (i + 2) % 3;
real_t s = Math::sqrt(m.elements[i][i] - m.elements[j][j] - m.elements[k][k] + 1.0); real_t s = Math::sqrt(m.rows[i][i] - m.rows[j][j] - m.rows[k][k] + 1.0);
temp[i] = s * 0.5; temp[i] = s * 0.5;
s = 0.5 / s; s = 0.5 / s;
temp[3] = (m.elements[k][j] - m.elements[j][k]) * s; temp[3] = (m.rows[k][j] - m.rows[j][k]) * s;
temp[j] = (m.elements[j][i] + m.elements[i][j]) * s; temp[j] = (m.rows[j][i] + m.rows[i][j]) * s;
temp[k] = (m.elements[k][i] + m.elements[i][k]) * s; temp[k] = (m.rows[k][i] + m.rows[i][k]) * s;
} }
return Quaternion(temp[0], temp[1], temp[2], temp[3]); return Quaternion(temp[0], temp[1], temp[2], temp[3]);
@ -878,11 +878,11 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
real_t epsilon = 0.01; // margin to allow for rounding errors real_t epsilon = 0.01; // margin to allow for rounding errors
real_t epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees real_t epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
if ((Math::abs(elements[1][0] - elements[0][1]) < epsilon) && (Math::abs(elements[2][0] - elements[0][2]) < epsilon) && (Math::abs(elements[2][1] - elements[1][2]) < epsilon)) { if ((Math::abs(rows[1][0] - rows[0][1]) < epsilon) && (Math::abs(rows[2][0] - rows[0][2]) < epsilon) && (Math::abs(rows[2][1] - rows[1][2]) < epsilon)) {
// singularity found // singularity found
// first check for identity matrix which must have +1 for all terms // first check for identity matrix which must have +1 for all terms
// in leading diagonaland zero in other terms // in leading diagonaland zero in other terms
if ((Math::abs(elements[1][0] + elements[0][1]) < epsilon2) && (Math::abs(elements[2][0] + elements[0][2]) < epsilon2) && (Math::abs(elements[2][1] + elements[1][2]) < epsilon2) && (Math::abs(elements[0][0] + elements[1][1] + elements[2][2] - 3) < epsilon2)) { if ((Math::abs(rows[1][0] + rows[0][1]) < epsilon2) && (Math::abs(rows[2][0] + rows[0][2]) < epsilon2) && (Math::abs(rows[2][1] + rows[1][2]) < epsilon2) && (Math::abs(rows[0][0] + rows[1][1] + rows[2][2] - 3) < epsilon2)) {
// this singularity is identity matrix so angle = 0 // this singularity is identity matrix so angle = 0
r_axis = Vector3(0, 1, 0); r_axis = Vector3(0, 1, 0);
r_angle = 0; r_angle = 0;
@ -890,13 +890,13 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
} }
// otherwise this singularity is angle = 180 // otherwise this singularity is angle = 180
angle = Math_PI; angle = Math_PI;
real_t xx = (elements[0][0] + 1) / 2; real_t xx = (rows[0][0] + 1) / 2;
real_t yy = (elements[1][1] + 1) / 2; real_t yy = (rows[1][1] + 1) / 2;
real_t zz = (elements[2][2] + 1) / 2; real_t zz = (rows[2][2] + 1) / 2;
real_t xy = (elements[1][0] + elements[0][1]) / 4; real_t xy = (rows[1][0] + rows[0][1]) / 4;
real_t xz = (elements[2][0] + elements[0][2]) / 4; real_t xz = (rows[2][0] + rows[0][2]) / 4;
real_t yz = (elements[2][1] + elements[1][2]) / 4; real_t yz = (rows[2][1] + rows[1][2]) / 4;
if ((xx > yy) && (xx > zz)) { // elements[0][0] is the largest diagonal term if ((xx > yy) && (xx > zz)) { // rows[0][0] is the largest diagonal term
if (xx < epsilon) { if (xx < epsilon) {
x = 0; x = 0;
y = Math_SQRT12; y = Math_SQRT12;
@ -906,7 +906,7 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
y = xy / x; y = xy / x;
z = xz / x; z = xz / x;
} }
} else if (yy > zz) { // elements[1][1] is the largest diagonal term } else if (yy > zz) { // rows[1][1] is the largest diagonal term
if (yy < epsilon) { if (yy < epsilon) {
x = Math_SQRT12; x = Math_SQRT12;
y = 0; y = 0;
@ -916,7 +916,7 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
x = xy / y; x = xy / y;
z = yz / y; z = yz / y;
} }
} else { // elements[2][2] is the largest diagonal term so base result on this } else { // rows[2][2] is the largest diagonal term so base result on this
if (zz < epsilon) { if (zz < epsilon) {
x = Math_SQRT12; x = Math_SQRT12;
y = Math_SQRT12; y = Math_SQRT12;
@ -932,15 +932,15 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
return; return;
} }
// as we have reached here there are no singularities so we can handle normally // as we have reached here there are no singularities so we can handle normally
real_t s = Math::sqrt((elements[1][2] - elements[2][1]) * (elements[1][2] - elements[2][1]) + (elements[2][0] - elements[0][2]) * (elements[2][0] - elements[0][2]) + (elements[0][1] - elements[1][0]) * (elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise real_t s = Math::sqrt((rows[1][2] - rows[2][1]) * (rows[1][2] - rows[2][1]) + (rows[2][0] - rows[0][2]) * (rows[2][0] - rows[0][2]) + (rows[0][1] - rows[1][0]) * (rows[0][1] - rows[1][0])); // s=|axis||sin(angle)|, used to normalise
angle = Math::acos((elements[0][0] + elements[1][1] + elements[2][2] - 1) / 2); angle = Math::acos((rows[0][0] + rows[1][1] + rows[2][2] - 1) / 2);
if (angle < 0) { if (angle < 0) {
s = -s; s = -s;
} }
x = (elements[2][1] - elements[1][2]) / s; x = (rows[2][1] - rows[1][2]) / s;
y = (elements[0][2] - elements[2][0]) / s; y = (rows[0][2] - rows[2][0]) / s;
z = (elements[1][0] - elements[0][1]) / s; z = (rows[1][0] - rows[0][1]) / s;
r_axis = Vector3(x, y, z); r_axis = Vector3(x, y, z);
r_angle = angle; r_angle = angle;
@ -965,27 +965,27 @@ void Basis::set_axis_angle(const Vector3 &p_axis, real_t p_phi) {
#endif #endif
Vector3 axis_sq(p_axis.x * p_axis.x, p_axis.y * p_axis.y, p_axis.z * p_axis.z); Vector3 axis_sq(p_axis.x * p_axis.x, p_axis.y * p_axis.y, p_axis.z * p_axis.z);
real_t cosine = Math::cos(p_phi); real_t cosine = Math::cos(p_phi);
elements[0][0] = axis_sq.x + cosine * (1.0 - axis_sq.x); rows[0][0] = axis_sq.x + cosine * (1.0 - axis_sq.x);
elements[1][1] = axis_sq.y + cosine * (1.0 - axis_sq.y); rows[1][1] = axis_sq.y + cosine * (1.0 - axis_sq.y);
elements[2][2] = axis_sq.z + cosine * (1.0 - axis_sq.z); rows[2][2] = axis_sq.z + cosine * (1.0 - axis_sq.z);
real_t sine = Math::sin(p_phi); real_t sine = Math::sin(p_phi);
real_t t = 1 - cosine; real_t t = 1 - cosine;
real_t xyzt = p_axis.x * p_axis.y * t; real_t xyzt = p_axis.x * p_axis.y * t;
real_t zyxs = p_axis.z * sine; real_t zyxs = p_axis.z * sine;
elements[0][1] = xyzt - zyxs; rows[0][1] = xyzt - zyxs;
elements[1][0] = xyzt + zyxs; rows[1][0] = xyzt + zyxs;
xyzt = p_axis.x * p_axis.z * t; xyzt = p_axis.x * p_axis.z * t;
zyxs = p_axis.y * sine; zyxs = p_axis.y * sine;
elements[0][2] = xyzt + zyxs; rows[0][2] = xyzt + zyxs;
elements[2][0] = xyzt - zyxs; rows[2][0] = xyzt - zyxs;
xyzt = p_axis.y * p_axis.z * t; xyzt = p_axis.y * p_axis.z * t;
zyxs = p_axis.x * sine; zyxs = p_axis.x * sine;
elements[1][2] = xyzt - zyxs; rows[1][2] = xyzt - zyxs;
elements[2][1] = xyzt + zyxs; rows[2][1] = xyzt + zyxs;
} }
void Basis::set_axis_angle_scale(const Vector3 &p_axis, real_t p_phi, const Vector3 &p_scale) { void Basis::set_axis_angle_scale(const Vector3 &p_axis, real_t p_phi, const Vector3 &p_scale) {
@ -1004,17 +1004,17 @@ void Basis::set_quaternion_scale(const Quaternion &p_quat, const Vector3 &p_scal
} }
void Basis::set_diagonal(const Vector3 &p_diag) { void Basis::set_diagonal(const Vector3 &p_diag) {
elements[0][0] = p_diag.x; rows[0][0] = p_diag.x;
elements[0][1] = 0; rows[0][1] = 0;
elements[0][2] = 0; rows[0][2] = 0;
elements[1][0] = 0; rows[1][0] = 0;
elements[1][1] = p_diag.y; rows[1][1] = p_diag.y;
elements[1][2] = 0; rows[1][2] = 0;
elements[2][0] = 0; rows[2][0] = 0;
elements[2][1] = 0; rows[2][1] = 0;
elements[2][2] = p_diag.z; rows[2][2] = p_diag.z;
} }
Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const { Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const {
@ -1023,9 +1023,9 @@ Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const {
Quaternion to(p_to); Quaternion to(p_to);
Basis b(from.slerp(to, p_weight)); Basis b(from.slerp(to, p_weight));
b.elements[0] *= Math::lerp(elements[0].length(), p_to.elements[0].length(), p_weight); b.rows[0] *= Math::lerp(rows[0].length(), p_to.rows[0].length(), p_weight);
b.elements[1] *= Math::lerp(elements[1].length(), p_to.elements[1].length(), p_weight); b.rows[1] *= Math::lerp(rows[1].length(), p_to.rows[1].length(), p_weight);
b.elements[2] *= Math::lerp(elements[2].length(), p_to.elements[2].length(), p_weight); b.rows[2] *= Math::lerp(rows[2].length(), p_to.rows[2].length(), p_weight);
return b; return b;
} }
@ -1051,15 +1051,15 @@ void Basis::rotate_sh(real_t *p_values) {
real_t src[9] = { p_values[0], p_values[1], p_values[2], p_values[3], p_values[4], p_values[5], p_values[6], p_values[7], p_values[8] }; real_t src[9] = { p_values[0], p_values[1], p_values[2], p_values[3], p_values[4], p_values[5], p_values[6], p_values[7], p_values[8] };
real_t m00 = elements[0][0]; real_t m00 = rows[0][0];
real_t m01 = elements[0][1]; real_t m01 = rows[0][1];
real_t m02 = elements[0][2]; real_t m02 = rows[0][2];
real_t m10 = elements[1][0]; real_t m10 = rows[1][0];
real_t m11 = elements[1][1]; real_t m11 = rows[1][1];
real_t m12 = elements[1][2]; real_t m12 = rows[1][2];
real_t m20 = elements[2][0]; real_t m20 = rows[2][0];
real_t m21 = elements[2][1]; real_t m21 = rows[2][1];
real_t m22 = elements[2][2]; real_t m22 = rows[2][2];
p_values[0] = src[0]; p_values[0] = src[0];
p_values[1] = m11 * src[1] - m12 * src[2] + m10 * src[3]; p_values[1] = m11 * src[1] - m12 * src[2] + m10 * src[3];

View File

@ -882,17 +882,17 @@ Projection::operator Transform3D() const {
Transform3D tr; Transform3D tr;
const real_t *m = &matrix[0][0]; const real_t *m = &matrix[0][0];
tr.basis.elements[0][0] = m[0]; tr.basis.rows[0][0] = m[0];
tr.basis.elements[1][0] = m[1]; tr.basis.rows[1][0] = m[1];
tr.basis.elements[2][0] = m[2]; tr.basis.rows[2][0] = m[2];
tr.basis.elements[0][1] = m[4]; tr.basis.rows[0][1] = m[4];
tr.basis.elements[1][1] = m[5]; tr.basis.rows[1][1] = m[5];
tr.basis.elements[2][1] = m[6]; tr.basis.rows[2][1] = m[6];
tr.basis.elements[0][2] = m[8]; tr.basis.rows[0][2] = m[8];
tr.basis.elements[1][2] = m[9]; tr.basis.rows[1][2] = m[9];
tr.basis.elements[2][2] = m[10]; tr.basis.rows[2][2] = m[10];
tr.origin.x = m[12]; tr.origin.x = m[12];
tr.origin.y = m[13]; tr.origin.y = m[13];
@ -910,17 +910,17 @@ Projection::Projection(const Transform3D &p_transform) {
const Transform3D &tr = p_transform; const Transform3D &tr = p_transform;
real_t *m = &matrix[0][0]; real_t *m = &matrix[0][0];
m[0] = tr.basis.elements[0][0]; m[0] = tr.basis.rows[0][0];
m[1] = tr.basis.elements[1][0]; m[1] = tr.basis.rows[1][0];
m[2] = tr.basis.elements[2][0]; m[2] = tr.basis.rows[2][0];
m[3] = 0.0; m[3] = 0.0;
m[4] = tr.basis.elements[0][1]; m[4] = tr.basis.rows[0][1];
m[5] = tr.basis.elements[1][1]; m[5] = tr.basis.rows[1][1];
m[6] = tr.basis.elements[2][1]; m[6] = tr.basis.rows[2][1];
m[7] = 0.0; m[7] = 0.0;
m[8] = tr.basis.elements[0][2]; m[8] = tr.basis.rows[0][2];
m[9] = tr.basis.elements[1][2]; m[9] = tr.basis.rows[1][2];
m[10] = tr.basis.elements[2][2]; m[10] = tr.basis.rows[2][2];
m[11] = 0.0; m[11] = 0.0;
m[12] = tr.origin.x; m[12] = tr.origin.x;
m[13] = tr.origin.y; m[13] = tr.origin.y;

View File

@ -193,33 +193,33 @@ next4:
Vector2(position.x + size.x, position.y + size.y), Vector2(position.x + size.x, position.y + size.y),
}; };
real_t maxa = p_xform.elements[0].dot(xf_points2[0]); real_t maxa = p_xform.columns[0].dot(xf_points2[0]);
real_t mina = maxa; real_t mina = maxa;
real_t dp = p_xform.elements[0].dot(xf_points2[1]); real_t dp = p_xform.columns[0].dot(xf_points2[1]);
maxa = Math::max(dp, maxa); maxa = Math::max(dp, maxa);
mina = Math::min(dp, mina); mina = Math::min(dp, mina);
dp = p_xform.elements[0].dot(xf_points2[2]); dp = p_xform.columns[0].dot(xf_points2[2]);
maxa = Math::max(dp, maxa); maxa = Math::max(dp, maxa);
mina = Math::min(dp, mina); mina = Math::min(dp, mina);
dp = p_xform.elements[0].dot(xf_points2[3]); dp = p_xform.columns[0].dot(xf_points2[3]);
maxa = Math::max(dp, maxa); maxa = Math::max(dp, maxa);
mina = Math::min(dp, mina); mina = Math::min(dp, mina);
real_t maxb = p_xform.elements[0].dot(xf_points[0]); real_t maxb = p_xform.columns[0].dot(xf_points[0]);
real_t minb = maxb; real_t minb = maxb;
dp = p_xform.elements[0].dot(xf_points[1]); dp = p_xform.columns[0].dot(xf_points[1]);
maxb = Math::max(dp, maxb); maxb = Math::max(dp, maxb);
minb = Math::min(dp, minb); minb = Math::min(dp, minb);
dp = p_xform.elements[0].dot(xf_points[2]); dp = p_xform.columns[0].dot(xf_points[2]);
maxb = Math::max(dp, maxb); maxb = Math::max(dp, maxb);
minb = Math::min(dp, minb); minb = Math::min(dp, minb);
dp = p_xform.elements[0].dot(xf_points[3]); dp = p_xform.columns[0].dot(xf_points[3]);
maxb = Math::max(dp, maxb); maxb = Math::max(dp, maxb);
minb = Math::min(dp, minb); minb = Math::min(dp, minb);
@ -230,33 +230,33 @@ next4:
return false; return false;
} }
maxa = p_xform.elements[1].dot(xf_points2[0]); maxa = p_xform.columns[1].dot(xf_points2[0]);
mina = maxa; mina = maxa;
dp = p_xform.elements[1].dot(xf_points2[1]); dp = p_xform.columns[1].dot(xf_points2[1]);
maxa = Math::max(dp, maxa); maxa = Math::max(dp, maxa);
mina = Math::min(dp, mina); mina = Math::min(dp, mina);
dp = p_xform.elements[1].dot(xf_points2[2]); dp = p_xform.columns[1].dot(xf_points2[2]);
maxa = Math::max(dp, maxa); maxa = Math::max(dp, maxa);
mina = Math::min(dp, mina); mina = Math::min(dp, mina);
dp = p_xform.elements[1].dot(xf_points2[3]); dp = p_xform.columns[1].dot(xf_points2[3]);
maxa = Math::max(dp, maxa); maxa = Math::max(dp, maxa);
mina = Math::min(dp, mina); mina = Math::min(dp, mina);
maxb = p_xform.elements[1].dot(xf_points[0]); maxb = p_xform.columns[1].dot(xf_points[0]);
minb = maxb; minb = maxb;
dp = p_xform.elements[1].dot(xf_points[1]); dp = p_xform.columns[1].dot(xf_points[1]);
maxb = Math::max(dp, maxb); maxb = Math::max(dp, maxb);
minb = Math::min(dp, minb); minb = Math::min(dp, minb);
dp = p_xform.elements[1].dot(xf_points[2]); dp = p_xform.columns[1].dot(xf_points[2]);
maxb = Math::max(dp, maxb); maxb = Math::max(dp, maxb);
minb = Math::min(dp, minb); minb = Math::min(dp, minb);
dp = p_xform.elements[1].dot(xf_points[3]); dp = p_xform.columns[1].dot(xf_points[3]);
maxb = Math::max(dp, maxb); maxb = Math::max(dp, maxb);
minb = Math::min(dp, minb); minb = Math::min(dp, minb);

View File

@ -35,8 +35,8 @@ namespace godot {
void Transform2D::invert() { void Transform2D::invert() {
// FIXME: this function assumes the basis is a rotation matrix, with no scaling. // FIXME: this function assumes the basis is a rotation matrix, with no scaling.
// Transform2D::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]); SWAP(columns[0][1], columns[1][0]);
elements[2] = basis_xform(-elements[2]); columns[2] = basis_xform(-columns[2]);
} }
Transform2D Transform2D::inverse() const { Transform2D Transform2D::inverse() const {
@ -52,11 +52,11 @@ void Transform2D::affine_invert() {
#endif #endif
real_t idet = 1.0 / det; real_t idet = 1.0 / det;
SWAP(elements[0][0], elements[1][1]); SWAP(columns[0][0], columns[1][1]);
elements[0] *= Vector2(idet, -idet); columns[0] *= Vector2(idet, -idet);
elements[1] *= Vector2(-idet, idet); columns[1] *= Vector2(-idet, idet);
elements[2] = basis_xform(-elements[2]); columns[2] = basis_xform(-columns[2]);
} }
Transform2D Transform2D::affine_inverse() const { Transform2D Transform2D::affine_inverse() const {
@ -71,61 +71,61 @@ void Transform2D::rotate(real_t p_phi) {
real_t Transform2D::get_skew() const { real_t Transform2D::get_skew() const {
real_t det = basis_determinant(); real_t det = basis_determinant();
return Math::acos(elements[0].normalized().dot(Math::sign(det) * elements[1].normalized())) - Math_PI * 0.5; return Math::acos(columns[0].normalized().dot(Math::sign(det) * columns[1].normalized())) - Math_PI * 0.5;
} }
void Transform2D::set_skew(float p_angle) { void Transform2D::set_skew(float p_angle) {
real_t det = basis_determinant(); real_t det = basis_determinant();
elements[1] = Math::sign(det) * elements[0].rotated((Math_PI * 0.5 + p_angle)).normalized() * elements[1].length(); columns[1] = Math::sign(det) * columns[0].rotated((Math_PI * 0.5 + p_angle)).normalized() * columns[1].length();
} }
real_t Transform2D::get_rotation() const { real_t Transform2D::get_rotation() const {
return Math::atan2(elements[0].y, elements[0].x); return Math::atan2(columns[0].y, columns[0].x);
} }
void Transform2D::set_rotation(real_t p_rot) { void Transform2D::set_rotation(real_t p_rot) {
Size2 scale = get_scale(); Size2 scale = get_scale();
real_t cr = Math::cos(p_rot); real_t cr = Math::cos(p_rot);
real_t sr = Math::sin(p_rot); real_t sr = Math::sin(p_rot);
elements[0][0] = cr; columns[0][0] = cr;
elements[0][1] = sr; columns[0][1] = sr;
elements[1][0] = -sr; columns[1][0] = -sr;
elements[1][1] = cr; columns[1][1] = cr;
set_scale(scale); set_scale(scale);
} }
Transform2D::Transform2D(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 cr = Math::cos(p_rot);
real_t sr = Math::sin(p_rot); real_t sr = Math::sin(p_rot);
elements[0][0] = cr; columns[0][0] = cr;
elements[0][1] = sr; columns[0][1] = sr;
elements[1][0] = -sr; columns[1][0] = -sr;
elements[1][1] = cr; columns[1][1] = cr;
elements[2] = p_pos; columns[2] = p_pos;
} }
Size2 Transform2D::get_scale() const { Size2 Transform2D::get_scale() const {
real_t det_sign = Math::sign(basis_determinant()); real_t det_sign = Math::sign(basis_determinant());
return Size2(elements[0].length(), det_sign * elements[1].length()); return Size2(columns[0].length(), det_sign * columns[1].length());
} }
void Transform2D::set_scale(const Size2 &p_scale) { void Transform2D::set_scale(const Size2 &p_scale) {
elements[0].normalize(); columns[0].normalize();
elements[1].normalize(); columns[1].normalize();
elements[0] *= p_scale.x; columns[0] *= p_scale.x;
elements[1] *= p_scale.y; columns[1] *= p_scale.y;
} }
void Transform2D::scale(const Size2 &p_scale) { void Transform2D::scale(const Size2 &p_scale) {
scale_basis(p_scale); scale_basis(p_scale);
elements[2] *= p_scale; columns[2] *= p_scale;
} }
void Transform2D::scale_basis(const Size2 &p_scale) { void Transform2D::scale_basis(const Size2 &p_scale) {
elements[0][0] *= p_scale.x; columns[0][0] *= p_scale.x;
elements[0][1] *= p_scale.y; columns[0][1] *= p_scale.y;
elements[1][0] *= p_scale.x; columns[1][0] *= p_scale.x;
elements[1][1] *= p_scale.y; columns[1][1] *= p_scale.y;
} }
void Transform2D::translate(real_t p_tx, real_t p_ty) { void Transform2D::translate(real_t p_tx, real_t p_ty) {
@ -133,21 +133,21 @@ void Transform2D::translate(real_t p_tx, real_t p_ty) {
} }
void Transform2D::translate(const Vector2 &p_translation) { void Transform2D::translate(const Vector2 &p_translation) {
elements[2] += basis_xform(p_translation); columns[2] += basis_xform(p_translation);
} }
void Transform2D::orthonormalize() { void Transform2D::orthonormalize() {
// Gram-Schmidt Process // Gram-Schmidt Process
Vector2 x = elements[0]; Vector2 x = columns[0];
Vector2 y = elements[1]; Vector2 y = columns[1];
x.normalize(); x.normalize();
y = (y - x * (x.dot(y))); y = (y - x * (x.dot(y)));
y.normalize(); y.normalize();
elements[0] = x; columns[0] = x;
elements[1] = y; columns[1] = y;
} }
Transform2D Transform2D::orthonormalized() const { Transform2D Transform2D::orthonormalized() const {
@ -157,12 +157,12 @@ Transform2D Transform2D::orthonormalized() const {
} }
bool Transform2D::is_equal_approx(const Transform2D &p_transform) const { bool Transform2D::is_equal_approx(const Transform2D &p_transform) const {
return elements[0].is_equal_approx(p_transform.elements[0]) && elements[1].is_equal_approx(p_transform.elements[1]) && elements[2].is_equal_approx(p_transform.elements[2]); return columns[0].is_equal_approx(p_transform.columns[0]) && columns[1].is_equal_approx(p_transform.columns[1]) && columns[2].is_equal_approx(p_transform.columns[2]);
} }
bool Transform2D::operator==(const Transform2D &p_transform) const { bool Transform2D::operator==(const Transform2D &p_transform) const {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (elements[i] != p_transform.elements[i]) { if (columns[i] != p_transform.columns[i]) {
return false; return false;
} }
} }
@ -172,7 +172,7 @@ bool Transform2D::operator==(const Transform2D &p_transform) const {
bool Transform2D::operator!=(const Transform2D &p_transform) const { bool Transform2D::operator!=(const Transform2D &p_transform) const {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (elements[i] != p_transform.elements[i]) { if (columns[i] != p_transform.columns[i]) {
return true; return true;
} }
} }
@ -181,19 +181,19 @@ bool Transform2D::operator!=(const Transform2D &p_transform) const {
} }
void Transform2D::operator*=(const Transform2D &p_transform) { void Transform2D::operator*=(const Transform2D &p_transform) {
elements[2] = xform(p_transform.elements[2]); columns[2] = xform(p_transform.columns[2]);
real_t x0, x1, y0, y1; real_t x0, x1, y0, y1;
x0 = tdotx(p_transform.elements[0]); x0 = tdotx(p_transform.columns[0]);
x1 = tdoty(p_transform.elements[0]); x1 = tdoty(p_transform.columns[0]);
y0 = tdotx(p_transform.elements[1]); y0 = tdotx(p_transform.columns[1]);
y1 = tdoty(p_transform.elements[1]); y1 = tdoty(p_transform.columns[1]);
elements[0][0] = x0; columns[0][0] = x0;
elements[0][1] = x1; columns[0][1] = x1;
elements[1][0] = y0; columns[1][0] = y0;
elements[1][1] = y1; columns[1][1] = y1;
} }
Transform2D Transform2D::operator*(const Transform2D &p_transform) const { Transform2D Transform2D::operator*(const Transform2D &p_transform) const {
@ -216,7 +216,7 @@ Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const {
Transform2D Transform2D::untranslated() const { Transform2D Transform2D::untranslated() const {
Transform2D copy = *this; Transform2D copy = *this;
copy.elements[2] = Vector2(); copy.columns[2] = Vector2();
return copy; return copy;
} }
@ -233,7 +233,7 @@ Transform2D Transform2D::rotated(real_t p_phi) const {
} }
real_t Transform2D::basis_determinant() const { real_t Transform2D::basis_determinant() const {
return elements[0].x * elements[1].y - elements[0].y * elements[1].x; return columns[0].x * columns[1].y - columns[0].y * columns[1].x;
} }
Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t p_c) const { Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t p_c) const {
@ -272,7 +272,7 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t
} }
Transform2D::operator String() const { Transform2D::operator String() const {
return elements[0].operator String() + ", " + elements[1].operator String() + ", " + elements[2].operator String(); return columns[0].operator String() + ", " + columns[1].operator String() + ", " + columns[2].operator String();
} }
} // namespace godot } // namespace godot