From d9e094ab9aec110e654531458be9da11efa22e4f Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 13 Aug 2022 19:07:59 +0200 Subject: [PATCH] Renamed elements in Basis to rows. --- core/io/marshalls.cpp | 8 +- core/io/resource_format_binary.cpp | 72 ++--- core/math/basis.cpp | 254 +++++++++--------- core/math/basis.h | 156 +++++------ core/math/camera_matrix.cpp | 36 +-- core/math/math_fieldwise.cpp | 36 +-- core/math/projection.cpp | 36 +-- core/math/transform.h | 12 +- core/math/transform_interpolator.cpp | 28 +- core/variant.cpp | 26 +- core/variant_parser.cpp | 4 +- drivers/gles2/rasterizer_storage_gles2.cpp | 54 ++-- drivers/gles2/shader_gles2.cpp | 36 +-- editor/property_editor.cpp | 12 +- gles_builders.py | 18 +- .../scene_synchronizer.cpp | 12 +- scene/3d/cpu_particles.h | 18 +- scene/animation/scene_tree_tween.cpp | 72 ++--- scene/animation/tween.cpp | 72 ++--- servers/visual/rasterizer.cpp | 72 ++--- servers/visual/visual_server_scene.cpp | 4 +- 21 files changed, 519 insertions(+), 519 deletions(-) diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index dd7a54596..852b7b8f4 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -319,7 +319,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Basis val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); + val.rows[i][j] = decode_float(&buf[(i * 3 + j) * 4]); } } @@ -335,7 +335,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Transform val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); + val.basis.rows[i][j] = decode_float(&buf[(i * 3 + j) * 4]); } } val.origin[0] = decode_float(&buf[36]); @@ -1144,7 +1144,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Basis val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - memcpy(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 3 + j) * 4], &val.rows[i][j], sizeof(float)); } } } @@ -1157,7 +1157,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Transform val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - memcpy(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 3 + j) * 4], &val.basis.rows[i][j], sizeof(float)); } } diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index aeaa13bba..a01776552 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -239,29 +239,29 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_MATRIX3: { Basis v; - v.elements[0].x = f->get_real(); - v.elements[0].y = f->get_real(); - v.elements[0].z = f->get_real(); - v.elements[1].x = f->get_real(); - v.elements[1].y = f->get_real(); - v.elements[1].z = f->get_real(); - v.elements[2].x = f->get_real(); - v.elements[2].y = f->get_real(); - v.elements[2].z = f->get_real(); + v.rows[0].x = f->get_real(); + v.rows[0].y = f->get_real(); + v.rows[0].z = f->get_real(); + v.rows[1].x = f->get_real(); + v.rows[1].y = f->get_real(); + v.rows[1].z = f->get_real(); + v.rows[2].x = f->get_real(); + v.rows[2].y = f->get_real(); + v.rows[2].z = f->get_real(); r_v = v; } break; case VARIANT_TRANSFORM: { Transform v; - v.basis.elements[0].x = f->get_real(); - v.basis.elements[0].y = f->get_real(); - v.basis.elements[0].z = f->get_real(); - v.basis.elements[1].x = f->get_real(); - v.basis.elements[1].y = f->get_real(); - v.basis.elements[1].z = f->get_real(); - v.basis.elements[2].x = f->get_real(); - v.basis.elements[2].y = f->get_real(); - v.basis.elements[2].z = f->get_real(); + v.basis.rows[0].x = f->get_real(); + v.basis.rows[0].y = f->get_real(); + v.basis.rows[0].z = f->get_real(); + v.basis.rows[1].x = f->get_real(); + v.basis.rows[1].y = f->get_real(); + v.basis.rows[1].z = f->get_real(); + v.basis.rows[2].x = f->get_real(); + v.basis.rows[2].y = f->get_real(); + v.basis.rows[2].z = f->get_real(); v.origin.x = f->get_real(); v.origin.y = f->get_real(); v.origin.z = f->get_real(); @@ -1436,30 +1436,30 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia case Variant::BASIS: { f->store_32(VARIANT_MATRIX3); Basis val = p_property; - f->store_real(val.elements[0].x); - f->store_real(val.elements[0].y); - f->store_real(val.elements[0].z); - f->store_real(val.elements[1].x); - f->store_real(val.elements[1].y); - f->store_real(val.elements[1].z); - f->store_real(val.elements[2].x); - f->store_real(val.elements[2].y); - f->store_real(val.elements[2].z); + f->store_real(val.rows[0].x); + f->store_real(val.rows[0].y); + f->store_real(val.rows[0].z); + f->store_real(val.rows[1].x); + f->store_real(val.rows[1].y); + f->store_real(val.rows[1].z); + f->store_real(val.rows[2].x); + f->store_real(val.rows[2].y); + f->store_real(val.rows[2].z); } break; case Variant::TRANSFORM: { f->store_32(VARIANT_TRANSFORM); Transform val = p_property; - f->store_real(val.basis.elements[0].x); - f->store_real(val.basis.elements[0].y); - f->store_real(val.basis.elements[0].z); - f->store_real(val.basis.elements[1].x); - f->store_real(val.basis.elements[1].y); - f->store_real(val.basis.elements[1].z); - f->store_real(val.basis.elements[2].x); - f->store_real(val.basis.elements[2].y); - f->store_real(val.basis.elements[2].z); + f->store_real(val.basis.rows[0].x); + f->store_real(val.basis.rows[0].y); + f->store_real(val.basis.rows[0].z); + f->store_real(val.basis.rows[1].x); + f->store_real(val.basis.rows[1].y); + f->store_real(val.basis.rows[1].z); + f->store_real(val.basis.rows[2].x); + f->store_real(val.basis.rows[2].y); + f->store_real(val.basis.rows[2].z); f->store_real(val.origin.x); f->store_real(val.origin.y); f->store_real(val.origin.z); diff --git a/core/math/basis.cpp b/core/math/basis.cpp index c72ca24e4..96329ab92 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -34,32 +34,32 @@ #include "core/print_string.h" #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]) void Basis::from_z(const Vector3 &p_z) { if (Math::abs(p_z.z) > (real_t)Math_SQRT12) { // choose p in y-z plane real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2]; real_t k = 1 / Math::sqrt(a); - elements[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[0] = Vector3(0, -p_z[2] * k, p_z[1] * k); + rows[1] = Vector3(a * k, -p_z[0] * rows[0][2], p_z[0] * rows[0][1]); } else { // choose p in x-y plane real_t a = p_z.x * p_z.x + p_z.y * p_z.y; real_t k = 1 / Math::sqrt(a); - elements[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[0] = Vector3(-p_z.y * k, p_z.x * k, 0); + 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() { real_t co[3] = { cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1) }; - real_t det = elements[0][0] * co[0] + - elements[0][1] * co[1] + - elements[0][2] * co[2]; + real_t det = rows[0][0] * co[0] + + rows[0][1] * co[1] + + rows[0][2] * co[2]; #ifdef MATH_CHECKS ERR_FAIL_COND(det == 0); #endif @@ -103,9 +103,9 @@ bool Basis::is_orthogonal() const { bool Basis::is_diagonal() const { return ( - Math::is_zero_approx(elements[0][1]) && Math::is_zero_approx(elements[0][2]) && - Math::is_zero_approx(elements[1][0]) && Math::is_zero_approx(elements[1][2]) && - Math::is_zero_approx(elements[2][0]) && Math::is_zero_approx(elements[2][1])); + Math::is_zero_approx(rows[0][1]) && Math::is_zero_approx(rows[0][2]) && + Math::is_zero_approx(rows[1][0]) && Math::is_zero_approx(rows[1][2]) && + Math::is_zero_approx(rows[2][0]) && Math::is_zero_approx(rows[2][1])); } bool Basis::is_rotation() const { @@ -113,13 +113,13 @@ bool Basis::is_rotation() const { } bool Basis::is_symmetric() const { - if (!Math::is_equal_approx_ratio(elements[0][1], elements[1][0], (real_t)UNIT_EPSILON)) { + if (!Math::is_equal_approx_ratio(rows[0][1], rows[1][0], (real_t)UNIT_EPSILON)) { return false; } - if (!Math::is_equal_approx_ratio(elements[0][2], elements[2][0], (real_t)UNIT_EPSILON)) { + if (!Math::is_equal_approx_ratio(rows[0][2], rows[2][0], (real_t)UNIT_EPSILON)) { return false; } - if (!Math::is_equal_approx_ratio(elements[1][2], elements[2][1], (real_t)UNIT_EPSILON)) { + if (!Math::is_equal_approx_ratio(rows[1][2], rows[2][1], (real_t)UNIT_EPSILON)) { return false; } @@ -134,14 +134,14 @@ Basis Basis::diagonalize() { #endif 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; Basis acc_rot; while (off_matrix_norm_2 > (real_t)CMP_EPSILON2 && ite++ < ite_max) { - real_t el01_2 = elements[0][1] * elements[0][1]; - real_t el02_2 = elements[0][2] * elements[0][2]; - real_t el12_2 = elements[1][2] * elements[1][2]; + real_t el01_2 = rows[0][1] * rows[0][1]; + real_t el02_2 = rows[0][2] * rows[0][2]; + real_t el12_2 = rows[1][2] * rows[1][2]; // Find the pivot element int i, j; if (el01_2 > el02_2) { @@ -164,19 +164,19 @@ Basis Basis::diagonalize() { // Compute the rotation 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; } else { - angle = 0.5f * Math::atan(2 * elements[i][j] / (elements[j][j] - elements[i][i])); + angle = 0.5f * Math::atan(2 * rows[i][j] / (rows[j][j] - rows[i][i])); } // Compute the rotation matrix Basis rot; - rot.elements[i][i] = rot.elements[j][j] = Math::cos(angle); - rot.elements[i][j] = -(rot.elements[j][i] = Math::sin(angle)); + rot.rows[i][i] = rot.rows[j][j] = Math::cos(angle); + rot.rows[i][j] = -(rot.rows[j][i] = Math::sin(angle)); // 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 *this = rot * *this * rot.transposed(); @@ -193,9 +193,9 @@ Basis Basis::inverse() const { } void Basis::transpose() { - SWAP(elements[0][1], elements[1][0]); - SWAP(elements[0][2], elements[2][0]); - SWAP(elements[1][2], elements[2][1]); + SWAP(rows[0][1], rows[1][0]); + SWAP(rows[0][2], rows[2][0]); + SWAP(rows[1][2], rows[2][1]); } Basis Basis::transposed() const { @@ -207,15 +207,15 @@ Basis Basis::transposed() const { // Multiplies the matrix from left by the scaling matrix: M -> S.M // See the comment for Basis::rotated for further explanation. void Basis::scale(const Vector3 &p_scale) { - elements[0][0] *= p_scale.x; - elements[0][1] *= p_scale.x; - elements[0][2] *= p_scale.x; - elements[1][0] *= p_scale.y; - elements[1][1] *= p_scale.y; - elements[1][2] *= p_scale.y; - elements[2][0] *= p_scale.z; - elements[2][1] *= p_scale.z; - elements[2][2] *= p_scale.z; + rows[0][0] *= p_scale.x; + rows[0][1] *= p_scale.x; + rows[0][2] *= p_scale.x; + rows[1][0] *= p_scale.y; + rows[1][1] *= p_scale.y; + rows[1][2] *= p_scale.y; + rows[2][0] *= p_scale.z; + rows[2][1] *= p_scale.z; + rows[2][2] *= p_scale.z; } Basis Basis::scaled(const Vector3 &p_scale) const { @@ -239,14 +239,14 @@ Basis Basis::scaled_local(const Vector3 &p_scale) const { Vector3 Basis::get_scale_abs() const { return Vector3( - Vector3(elements[0][0], elements[1][0], elements[2][0]).length(), - Vector3(elements[0][1], elements[1][1], elements[2][1]).length(), - Vector3(elements[0][2], elements[1][2], elements[2][2]).length()); + Vector3(rows[0][0], rows[1][0], rows[2][0]).length(), + Vector3(rows[0][1], rows[1][1], rows[2][1]).length(), + Vector3(rows[0][2], rows[1][2], rows[2][2]).length()); } Vector3 Basis::get_scale_local() const { real_t det_sign = SGN(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. @@ -268,7 +268,7 @@ 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) // 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. real_t det_sign = SGN(determinant()); @@ -423,27 +423,27 @@ Vector3 Basis::get_euler_xyz() const { // -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy Vector3 euler; - real_t sy = elements[0][2]; + real_t sy = rows[0][2]; if (sy < (1 - (real_t)CMP_EPSILON)) { if (sy > -(1 - (real_t)CMP_EPSILON)) { // is this a pure Y rotation? - if (elements[1][0] == 0 && elements[0][1] == 0 && elements[1][2] == 0 && elements[2][1] == 0 && elements[1][1] == 1) { + if (rows[1][0] == 0 && rows[0][1] == 0 && rows[1][2] == 0 && rows[2][1] == 0 && rows[1][1] == 1) { // return the simplest form (human friendlier in editor and scripts) euler.x = 0; - euler.y = atan2(elements[0][2], elements[0][0]); + euler.y = atan2(rows[0][2], rows[0][0]); euler.z = 0; } 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.z = Math::atan2(-elements[0][1], elements[0][0]); + euler.z = Math::atan2(-rows[0][1], rows[0][0]); } } 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.z = 0.0; } } 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.z = 0.0; } @@ -482,21 +482,21 @@ Vector3 Basis::get_euler_xzy() const { // cy*sx*sz cz*sx cx*cy+sx*sz*sy Vector3 euler; - real_t sz = elements[0][1]; + real_t sz = rows[0][1]; if (sz < (1 - (real_t)CMP_EPSILON)) { if (sz > -(1 - (real_t)CMP_EPSILON)) { - euler.x = Math::atan2(elements[2][1], elements[1][1]); - euler.y = Math::atan2(elements[0][2], elements[0][0]); + euler.x = Math::atan2(rows[2][1], rows[1][1]); + euler.y = Math::atan2(rows[0][2], rows[0][0]); euler.z = Math::asin(-sz); } else { // 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.z = Math_PI / 2.0; } } else { // 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.z = -Math_PI / 2.0; } @@ -530,21 +530,21 @@ Vector3 Basis::get_euler_yzx() const { // -cz*sy cy*sx+cx*sy*sz cy*cx-sy*sz*sx Vector3 euler; - real_t sz = elements[1][0]; + real_t sz = rows[1][0]; if (sz < (1 - (real_t)CMP_EPSILON)) { if (sz > -(1 - (real_t)CMP_EPSILON)) { - euler.x = Math::atan2(-elements[1][2], elements[1][1]); - euler.y = Math::atan2(-elements[2][0], elements[0][0]); + euler.x = Math::atan2(-rows[1][2], rows[1][1]); + euler.y = Math::atan2(-rows[2][0], rows[0][0]); euler.z = Math::asin(sz); } else { // 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.z = -Math_PI / 2.0; } } else { // 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.z = Math_PI / 2.0; } @@ -582,29 +582,29 @@ Vector3 Basis::get_euler_yxz() const { Vector3 euler; - real_t m12 = elements[1][2]; + real_t m12 = rows[1][2]; if (m12 < (1 - (real_t)CMP_EPSILON)) { if (m12 > -(1 - (real_t)CMP_EPSILON)) { // 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) - euler.x = atan2(-m12, elements[1][1]); + euler.x = atan2(-m12, rows[1][1]); euler.y = 0; euler.z = 0; } else { euler.x = asin(-m12); - euler.y = atan2(elements[0][2], elements[2][2]); - euler.z = atan2(elements[1][0], elements[1][1]); + euler.y = atan2(rows[0][2], rows[2][2]); + euler.z = atan2(rows[1][0], rows[1][1]); } } else { // m12 == -1 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; } } else { // m12 == 1 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; } @@ -642,22 +642,22 @@ Vector3 Basis::get_euler_zxy() const { // cy*sz+cz*sx*sy cz*cx sz*sy-cz*cy*sx // -cx*sy sx cx*cy Vector3 euler; - real_t sx = elements[2][1]; + real_t sx = rows[2][1]; if (sx < (1 - (real_t)CMP_EPSILON)) { if (sx > -(1 - (real_t)CMP_EPSILON)) { euler.x = Math::asin(sx); - euler.y = Math::atan2(-elements[2][0], elements[2][2]); - euler.z = Math::atan2(-elements[0][1], elements[1][1]); + euler.y = Math::atan2(-rows[2][0], rows[2][2]); + euler.z = Math::atan2(-rows[0][1], rows[1][1]); } else { // It's -1 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; } } else { // It's 1 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; } return euler; @@ -689,23 +689,23 @@ Vector3 Basis::get_euler_zyx() const { // cy*sz cz*cx+sz*sy*sx cx*sz*sy-cz*sx // -sy cy*sx cy*cx Vector3 euler; - real_t sy = elements[2][0]; + real_t sy = rows[2][0]; if (sy < (1 - (real_t)CMP_EPSILON)) { if (sy > -(1 - (real_t)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.z = Math::atan2(elements[1][0], elements[0][0]); + euler.z = Math::atan2(rows[1][0], rows[0][0]); } else { // It's -1 euler.x = 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 { // It's 1 euler.x = 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; } @@ -729,13 +729,13 @@ void Basis::set_euler_zyx(const Vector3 &p_euler) { } 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::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsilon) const { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if (!Math::is_equal_approx_ratio(a.elements[i][j], b.elements[i][j], p_epsilon)) { + if (!Math::is_equal_approx_ratio(a.rows[i][j], b.rows[i][j], p_epsilon)) { return false; } } @@ -747,7 +747,7 @@ bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsil bool Basis::operator==(const Basis &p_matrix) const { for (int i = 0; i < 3; i++) { 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; } } @@ -768,7 +768,7 @@ Basis::operator String() const { mtx += ", "; } - mtx += rtos(elements[i][j]); + mtx += rtos(rows[i][j]); } } @@ -781,7 +781,7 @@ Quaternion Basis::get_quat() const { #endif /* Allow getting a quaternion from an unnormalized transform */ 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]; if (trace > 0) { @@ -789,23 +789,23 @@ Quaternion Basis::get_quat() const { temp[3] = (s * 0.5f); s = 0.5f / s; - temp[0] = ((m.elements[2][1] - m.elements[1][2]) * s); - temp[1] = ((m.elements[0][2] - m.elements[2][0]) * s); - temp[2] = ((m.elements[1][0] - m.elements[0][1]) * s); + temp[0] = ((m.rows[2][1] - m.rows[1][2]) * s); + temp[1] = ((m.rows[0][2] - m.rows[2][0]) * s); + temp[2] = ((m.rows[1][0] - m.rows[0][1]) * s); } else { - int i = m.elements[0][0] < m.elements[1][1] - ? (m.elements[1][1] < m.elements[2][2] ? 2 : 1) - : (m.elements[0][0] < m.elements[2][2] ? 2 : 0); + int i = m.rows[0][0] < m.rows[1][1] + ? (m.rows[1][1] < m.rows[2][2] ? 2 : 1) + : (m.rows[0][0] < m.rows[2][2] ? 2 : 0); int j = (i + 1) % 3; int k = (i + 2) % 3; - real_t s = Math::sqrt(m.elements[i][i] - m.elements[j][j] - m.elements[k][k] + 1); + real_t s = Math::sqrt(m.rows[i][i] - m.rows[j][j] - m.rows[k][k] + 1); temp[i] = s * 0.5f; s = 0.5f / s; - temp[3] = (m.elements[k][j] - m.elements[j][k]) * s; - temp[j] = (m.elements[j][i] + m.elements[i][j]) * s; - temp[k] = (m.elements[k][i] + m.elements[i][k]) * s; + temp[3] = (m.rows[k][j] - m.rows[j][k]) * s; + temp[j] = (m.rows[j][i] + m.rows[i][j]) * s; + temp[k] = (m.rows[k][i] + m.rows[i][k]) * s; } return Quaternion(temp[0], temp[1], temp[2], temp[3]); @@ -881,11 +881,11 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { real_t angle, x, y, z; // variables for result real_t angle_epsilon = 0.1; // margin to distinguish between 0 and 180 degrees - if ((Math::abs(elements[1][0] - elements[0][1]) < CMP_EPSILON) && (Math::abs(elements[2][0] - elements[0][2]) < CMP_EPSILON) && (Math::abs(elements[2][1] - elements[1][2]) < CMP_EPSILON)) { + if ((Math::abs(rows[1][0] - rows[0][1]) < CMP_EPSILON) && (Math::abs(rows[2][0] - rows[0][2]) < CMP_EPSILON) && (Math::abs(rows[2][1] - rows[1][2]) < CMP_EPSILON)) { // singularity found // first check for identity matrix which must have +1 for all terms // in leading diagonaland zero in other terms - if ((Math::abs(elements[1][0] + elements[0][1]) < angle_epsilon) && (Math::abs(elements[2][0] + elements[0][2]) < angle_epsilon) && (Math::abs(elements[2][1] + elements[1][2]) < angle_epsilon) && (Math::abs(elements[0][0] + elements[1][1] + elements[2][2] - 3) < angle_epsilon)) { + if ((Math::abs(rows[1][0] + rows[0][1]) < angle_epsilon) && (Math::abs(rows[2][0] + rows[0][2]) < angle_epsilon) && (Math::abs(rows[2][1] + rows[1][2]) < angle_epsilon) && (Math::abs(rows[0][0] + rows[1][1] + rows[2][2] - 3) < angle_epsilon)) { // this singularity is identity matrix so angle = 0 r_axis = Vector3(0, 1, 0); r_angle = 0; @@ -893,13 +893,13 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { } // otherwise this singularity is angle = 180 angle = Math_PI; - real_t xx = (elements[0][0] + 1) / 2; - real_t yy = (elements[1][1] + 1) / 2; - real_t zz = (elements[2][2] + 1) / 2; - real_t xy = (elements[1][0] + elements[0][1]) / 4; - real_t xz = (elements[2][0] + elements[0][2]) / 4; - real_t yz = (elements[2][1] + elements[1][2]) / 4; - if ((xx > yy) && (xx > zz)) { // elements[0][0] is the largest diagonal term + real_t xx = (rows[0][0] + 1) / 2; + real_t yy = (rows[1][1] + 1) / 2; + real_t zz = (rows[2][2] + 1) / 2; + real_t xy = (rows[1][0] + rows[0][1]) / 4; + real_t xz = (rows[2][0] + rows[0][2]) / 4; + real_t yz = (rows[2][1] + rows[1][2]) / 4; + if ((xx > yy) && (xx > zz)) { // rows[0][0] is the largest diagonal term if (xx < CMP_EPSILON) { x = 0; y = Math_SQRT12; @@ -909,7 +909,7 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { y = xy / 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 < CMP_EPSILON) { x = Math_SQRT12; y = 0; @@ -919,7 +919,7 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { x = xy / 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 < CMP_EPSILON) { x = Math_SQRT12; y = Math_SQRT12; @@ -935,15 +935,15 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { return; } // 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) { s = -s; } - x = (elements[2][1] - elements[1][2]) / s; - y = (elements[0][2] - elements[2][0]) / s; - z = (elements[1][0] - elements[0][1]) / s; + x = (rows[2][1] - rows[1][2]) / s; + y = (rows[0][2] - rows[2][0]) / s; + z = (rows[1][0] - rows[0][1]) / s; r_axis = Vector3(x, y, z); r_angle = angle; @@ -968,27 +968,27 @@ void Basis::set_axis_angle(const Vector3 &p_axis, real_t p_phi) { #endif 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); - elements[0][0] = axis_sq.x + cosine * (1 - axis_sq.x); - elements[1][1] = axis_sq.y + cosine * (1 - axis_sq.y); - elements[2][2] = axis_sq.z + cosine * (1 - axis_sq.z); + rows[0][0] = axis_sq.x + cosine * (1 - axis_sq.x); + rows[1][1] = axis_sq.y + cosine * (1 - axis_sq.y); + rows[2][2] = axis_sq.z + cosine * (1 - axis_sq.z); real_t sine = Math::sin(p_phi); real_t t = 1 - cosine; real_t xyzt = p_axis.x * p_axis.y * t; real_t zyxs = p_axis.z * sine; - elements[0][1] = xyzt - zyxs; - elements[1][0] = xyzt + zyxs; + rows[0][1] = xyzt - zyxs; + rows[1][0] = xyzt + zyxs; xyzt = p_axis.x * p_axis.z * t; zyxs = p_axis.y * sine; - elements[0][2] = xyzt + zyxs; - elements[2][0] = xyzt - zyxs; + rows[0][2] = xyzt + zyxs; + rows[2][0] = xyzt - zyxs; xyzt = p_axis.y * p_axis.z * t; zyxs = p_axis.x * sine; - elements[1][2] = xyzt - zyxs; - elements[2][1] = xyzt + zyxs; + rows[1][2] = 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) { @@ -1007,17 +1007,17 @@ void Basis::set_quat_scale(const Quaternion &p_quat, const Vector3 &p_scale) { } void Basis::set_diagonal(const Vector3 &p_diag) { - elements[0][0] = p_diag.x; - elements[0][1] = 0; - elements[0][2] = 0; + rows[0][0] = p_diag.x; + rows[0][1] = 0; + rows[0][2] = 0; - elements[1][0] = 0; - elements[1][1] = p_diag.y; - elements[1][2] = 0; + rows[1][0] = 0; + rows[1][1] = p_diag.y; + rows[1][2] = 0; - elements[2][0] = 0; - elements[2][1] = 0; - elements[2][2] = p_diag.z; + rows[2][0] = 0; + rows[2][1] = 0; + rows[2][2] = p_diag.z; } Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const { @@ -1026,9 +1026,9 @@ Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const { Quaternion to(p_to); Basis b(from.slerp(to, p_weight)); - b.elements[0] *= Math::lerp(elements[0].length(), p_to.elements[0].length(), p_weight); - b.elements[1] *= Math::lerp(elements[1].length(), p_to.elements[1].length(), p_weight); - b.elements[2] *= Math::lerp(elements[2].length(), p_to.elements[2].length(), p_weight); + b.rows[0] *= Math::lerp(rows[0].length(), p_to.rows[0].length(), p_weight); + b.rows[1] *= Math::lerp(rows[1].length(), p_to.rows[1].length(), p_weight); + b.rows[2] *= Math::lerp(rows[2].length(), p_to.rows[2].length(), p_weight); return b; } diff --git a/core/math/basis.h b/core/math/basis.h index bc4f0eeea..871199cce 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -36,17 +36,17 @@ class _NO_DISCARD_CLASS_ Basis { public: - Vector3 elements[3] = { + Vector3 rows[3] = { Vector3(1, 0, 0), Vector3(0, 1, 0), Vector3(0, 0, 1) }; _FORCE_INLINE_ const Vector3 &operator[](int axis) const { - return elements[axis]; + return rows[axis]; } _FORCE_INLINE_ Vector3 &operator[](int axis) { - return elements[axis]; + return rows[axis]; } void invert(); @@ -60,14 +60,14 @@ public: void from_z(const Vector3 &p_z); _FORCE_INLINE_ Vector3 get_axis(int p_axis) const { - // get actual basis axis (elements is transposed for performance) - return Vector3(elements[0][p_axis], elements[1][p_axis], elements[2][p_axis]); + // get actual basis axis (rows is transposed for performance) + return Vector3(rows[0][p_axis], rows[1][p_axis], rows[2][p_axis]); } _FORCE_INLINE_ void set_axis(int p_axis, const Vector3 &p_value) { - // get actual basis axis (elements is transposed for performance) - elements[0][p_axis] = p_value.x; - elements[1][p_axis] = p_value.y; - elements[2][p_axis] = p_value.z; + // get actual basis axis (rows is transposed for performance) + rows[0][p_axis] = p_value.x; + rows[1][p_axis] = p_value.y; + rows[2][p_axis] = p_value.z; } void rotate(const Vector3 &p_axis, real_t p_phi); @@ -135,13 +135,13 @@ public: // transposed dot products _FORCE_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]; } _FORCE_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]; } _FORCE_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; @@ -184,15 +184,15 @@ public: /* create / set */ _FORCE_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; - elements[0][1] = xy; - elements[0][2] = xz; - elements[1][0] = yx; - elements[1][1] = yy; - elements[1][2] = yz; - elements[2][0] = zx; - elements[2][1] = zy; - elements[2][2] = zz; + rows[0][0] = xx; + rows[0][1] = xy; + rows[0][2] = xz; + rows[1][0] = yx; + rows[1][1] = yy; + rows[1][2] = yz; + rows[2][0] = zx; + rows[2][1] = zy; + rows[2][2] = zz; } _FORCE_INLINE_ void set(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z) { set_axis(0, p_x); @@ -200,46 +200,46 @@ public: set_axis(2, p_z); } _FORCE_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]); } _FORCE_INLINE_ void set_column(int p_index, const Vector3 &p_value) { // Set actual basis axis column (we store transposed as rows for performance). - elements[0][p_index] = p_value.x; - elements[1][p_index] = p_value.y; - elements[2][p_index] = p_value.z; + rows[0][p_index] = p_value.x; + rows[1][p_index] = p_value.y; + rows[2][p_index] = p_value.z; } _FORCE_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]); } _FORCE_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]); } _FORCE_INLINE_ void set_row(int i, const Vector3 &p_row) { - elements[i][0] = p_row.x; - elements[i][1] = p_row.y; - elements[i][2] = p_row.z; + rows[i][0] = p_row.x; + rows[i][1] = p_row.y; + rows[i][2] = p_row.z; } _FORCE_INLINE_ void set_zero() { - elements[0].zero(); - elements[1].zero(); - elements[2].zero(); + rows[0].zero(); + rows[1].zero(); + rows[2].zero(); } _FORCE_INLINE_ Basis transpose_xform(const Basis &m) const { return Basis( - elements[0].x * m[0].x + elements[1].x * m[1].x + elements[2].x * m[2].x, - elements[0].x * m[0].y + elements[1].x * m[1].y + elements[2].x * m[2].y, - elements[0].x * m[0].z + elements[1].x * m[1].z + elements[2].x * m[2].z, - elements[0].y * m[0].x + elements[1].y * m[1].x + elements[2].y * m[2].x, - elements[0].y * m[0].y + elements[1].y * m[1].y + elements[2].y * m[2].y, - elements[0].y * m[0].z + elements[1].y * m[1].z + elements[2].y * m[2].z, - elements[0].z * m[0].x + elements[1].z * m[1].x + elements[2].z * m[2].x, - elements[0].z * m[0].y + elements[1].z * m[1].y + elements[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].x * m[0].x + rows[1].x * m[1].x + rows[2].x * m[2].x, + rows[0].x * m[0].y + rows[1].x * m[1].y + rows[2].x * m[2].y, + rows[0].x * m[0].z + rows[1].x * m[1].z + rows[2].x * m[2].z, + rows[0].y * m[0].x + rows[1].y * m[1].x + rows[2].y * m[2].x, + rows[0].y * m[0].y + rows[1].y * m[1].y + rows[2].y * m[2].y, + rows[0].y * m[0].z + rows[1].y * m[1].z + rows[2].y * m[2].z, + rows[0].z * m[0].x + rows[1].z * m[1].x + rows[2].z * m[2].x, + rows[0].z * m[0].y + rows[1].z * m[1].y + rows[2].z * m[2].y, + 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) { set(xx, xy, xz, yx, yy, yz, zx, zy, zz); @@ -277,9 +277,9 @@ public: Basis(const Vector3 &p_axis, real_t p_phi, const Vector3 &p_scale) { set_axis_angle_scale(p_axis, p_phi, p_scale); } _FORCE_INLINE_ Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) { - elements[0] = row0; - elements[1] = row1; - elements[2] = row2; + rows[0] = row0; + rows[1] = row1; + rows[2] = row2; } _FORCE_INLINE_ Basis() {} @@ -287,22 +287,22 @@ public: _FORCE_INLINE_ void Basis::operator*=(const Basis &p_matrix) { set( - p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), - p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]), - p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2])); + p_matrix.tdotx(rows[0]), p_matrix.tdoty(rows[0]), p_matrix.tdotz(rows[0]), + p_matrix.tdotx(rows[1]), p_matrix.tdoty(rows[1]), p_matrix.tdotz(rows[1]), + p_matrix.tdotx(rows[2]), p_matrix.tdoty(rows[2]), p_matrix.tdotz(rows[2])); } _FORCE_INLINE_ Basis Basis::operator*(const Basis &p_matrix) const { return Basis( - p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), - p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]), - p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2])); + p_matrix.tdotx(rows[0]), p_matrix.tdoty(rows[0]), p_matrix.tdotz(rows[0]), + p_matrix.tdotx(rows[1]), p_matrix.tdoty(rows[1]), p_matrix.tdotz(rows[1]), + p_matrix.tdotx(rows[2]), p_matrix.tdoty(rows[2]), p_matrix.tdotz(rows[2])); } _FORCE_INLINE_ void Basis::operator+=(const Basis &p_matrix) { - elements[0] += p_matrix.elements[0]; - elements[1] += p_matrix.elements[1]; - elements[2] += p_matrix.elements[2]; + rows[0] += p_matrix.rows[0]; + rows[1] += p_matrix.rows[1]; + rows[2] += p_matrix.rows[2]; } _FORCE_INLINE_ Basis Basis::operator+(const Basis &p_matrix) const { @@ -312,9 +312,9 @@ _FORCE_INLINE_ Basis Basis::operator+(const Basis &p_matrix) const { } _FORCE_INLINE_ void Basis::operator-=(const Basis &p_matrix) { - elements[0] -= p_matrix.elements[0]; - elements[1] -= p_matrix.elements[1]; - elements[2] -= p_matrix.elements[2]; + rows[0] -= p_matrix.rows[0]; + rows[1] -= p_matrix.rows[1]; + rows[2] -= p_matrix.rows[2]; } _FORCE_INLINE_ Basis Basis::operator-(const Basis &p_matrix) const { @@ -324,9 +324,9 @@ _FORCE_INLINE_ Basis Basis::operator-(const Basis &p_matrix) const { } _FORCE_INLINE_ void Basis::operator*=(real_t p_val) { - elements[0] *= p_val; - elements[1] *= p_val; - elements[2] *= p_val; + rows[0] *= p_val; + rows[1] *= p_val; + rows[2] *= p_val; } _FORCE_INLINE_ Basis Basis::operator*(real_t p_val) const { @@ -337,43 +337,43 @@ _FORCE_INLINE_ Basis Basis::operator*(real_t p_val) const { Vector3 Basis::xform(const Vector3 &p_vector) const { return Vector3( - elements[0].dot(p_vector), - elements[1].dot(p_vector), - elements[2].dot(p_vector)); + rows[0].dot(p_vector), + rows[1].dot(p_vector), + rows[2].dot(p_vector)); } Vector3i Basis::xform_inv(const Vector3i &p_vector) const { return Vector3i( - (elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z), - (elements[0][1] * p_vector.x) + (elements[1][1] * p_vector.y) + (elements[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][0] * p_vector.x) + (rows[1][0] * p_vector.y) + (rows[2][0] * p_vector.z), + (rows[0][1] * p_vector.x) + (rows[1][1] * p_vector.y) + (rows[2][1] * p_vector.z), + (rows[0][2] * p_vector.x) + (rows[1][2] * p_vector.y) + (rows[2][2] * p_vector.z)); } Vector3i Basis::xform(const Vector3i &p_vector) const { return Vector3i( - elements[0].dot(p_vector), - elements[1].dot(p_vector), - elements[2].dot(p_vector)); + rows[0].dot(p_vector), + rows[1].dot(p_vector), + rows[2].dot(p_vector)); } Vector3 Basis::xform_inv(const Vector3 &p_vector) const { return Vector3( - (elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z), - (elements[0][1] * p_vector.x) + (elements[1][1] * p_vector.y) + (elements[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][0] * p_vector.x) + (rows[1][0] * p_vector.y) + (rows[2][0] * p_vector.z), + (rows[0][1] * p_vector.x) + (rows[1][1] * p_vector.y) + (rows[2][1] * 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 { - return elements[0][0] * (elements[1][1] * elements[2][2] - elements[2][1] * elements[1][2]) - - elements[1][0] * (elements[0][1] * elements[2][2] - elements[2][1] * elements[0][2]) + - elements[2][0] * (elements[0][1] * elements[1][2] - elements[1][1] * elements[0][2]); + return rows[0][0] * (rows[1][1] * rows[2][2] - rows[2][1] * rows[1][2]) - + rows[1][0] * (rows[0][1] * rows[2][2] - rows[2][1] * rows[0][2]) + + rows[2][0] * (rows[0][1] * rows[1][2] - rows[1][1] * rows[0][2]); } Basis Basis::lerp(const Basis &p_to, const real_t &p_weight) const { Basis b; - b.elements[0] = elements[0].linear_interpolate(p_to.elements[0], p_weight); - b.elements[1] = elements[1].linear_interpolate(p_to.elements[1], p_weight); - b.elements[2] = elements[2].linear_interpolate(p_to.elements[2], p_weight); + b.rows[0] = rows[0].linear_interpolate(p_to.rows[0], p_weight); + b.rows[1] = rows[1].linear_interpolate(p_to.rows[1], p_weight); + b.rows[2] = rows[2].linear_interpolate(p_to.rows[2], p_weight); return b; } diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 30084be59..c67c4852e 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -620,17 +620,17 @@ CameraMatrix::operator Transform() const { Transform tr; const real_t *m = &matrix[0][0]; - tr.basis.elements[0][0] = m[0]; - tr.basis.elements[1][0] = m[1]; - tr.basis.elements[2][0] = m[2]; + tr.basis.rows[0][0] = m[0]; + tr.basis.rows[1][0] = m[1]; + tr.basis.rows[2][0] = m[2]; - tr.basis.elements[0][1] = m[4]; - tr.basis.elements[1][1] = m[5]; - tr.basis.elements[2][1] = m[6]; + tr.basis.rows[0][1] = m[4]; + tr.basis.rows[1][1] = m[5]; + tr.basis.rows[2][1] = m[6]; - tr.basis.elements[0][2] = m[8]; - tr.basis.elements[1][2] = m[9]; - tr.basis.elements[2][2] = m[10]; + tr.basis.rows[0][2] = m[8]; + tr.basis.rows[1][2] = m[9]; + tr.basis.rows[2][2] = m[10]; tr.origin.x = m[12]; tr.origin.y = m[13]; @@ -643,17 +643,17 @@ CameraMatrix::CameraMatrix(const Transform &p_transform) { const Transform &tr = p_transform; real_t *m = &matrix[0][0]; - m[0] = tr.basis.elements[0][0]; - m[1] = tr.basis.elements[1][0]; - m[2] = tr.basis.elements[2][0]; + m[0] = tr.basis.rows[0][0]; + m[1] = tr.basis.rows[1][0]; + m[2] = tr.basis.rows[2][0]; m[3] = 0.0; - m[4] = tr.basis.elements[0][1]; - m[5] = tr.basis.elements[1][1]; - m[6] = tr.basis.elements[2][1]; + m[4] = tr.basis.rows[0][1]; + m[5] = tr.basis.rows[1][1]; + m[6] = tr.basis.rows[2][1]; m[7] = 0.0; - m[8] = tr.basis.elements[0][2]; - m[9] = tr.basis.elements[1][2]; - m[10] = tr.basis.elements[2][2]; + m[8] = tr.basis.rows[0][2]; + m[9] = tr.basis.rows[1][2]; + m[10] = tr.basis.rows[2][2]; m[11] = 0.0; m[12] = tr.origin.x; m[13] = tr.origin.y; diff --git a/core/math/math_fieldwise.cpp b/core/math/math_fieldwise.cpp index a97f697dc..a97511d8a 100644 --- a/core/math/math_fieldwise.cpp +++ b/core/math/math_fieldwise.cpp @@ -137,15 +137,15 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const SETUP_TYPE(Basis) - /**/ TRY_TRANSFER_FIELD("xx", elements[0][0]) - else TRY_TRANSFER_FIELD("xy", elements[0][1]) - else TRY_TRANSFER_FIELD("xz", elements[0][2]) - else TRY_TRANSFER_FIELD("yx", elements[1][0]) - else TRY_TRANSFER_FIELD("yy", elements[1][1]) - else TRY_TRANSFER_FIELD("yz", elements[1][2]) - else TRY_TRANSFER_FIELD("zx", elements[2][0]) - else TRY_TRANSFER_FIELD("zy", elements[2][1]) - else TRY_TRANSFER_FIELD("zz", elements[2][2]) + /**/ TRY_TRANSFER_FIELD("xx", rows[0][0]) + else TRY_TRANSFER_FIELD("xy", rows[0][1]) + else TRY_TRANSFER_FIELD("xz", rows[0][2]) + else TRY_TRANSFER_FIELD("yx", rows[1][0]) + else TRY_TRANSFER_FIELD("yy", rows[1][1]) + else TRY_TRANSFER_FIELD("yz", rows[1][2]) + else TRY_TRANSFER_FIELD("zx", rows[2][0]) + else TRY_TRANSFER_FIELD("zy", rows[2][1]) + else TRY_TRANSFER_FIELD("zz", rows[2][2]) return target; } @@ -154,15 +154,15 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const SETUP_TYPE(Transform) - /**/ TRY_TRANSFER_FIELD("xx", basis.elements[0][0]) - else TRY_TRANSFER_FIELD("xy", basis.elements[0][1]) - else TRY_TRANSFER_FIELD("xz", basis.elements[0][2]) - else TRY_TRANSFER_FIELD("yx", basis.elements[1][0]) - else TRY_TRANSFER_FIELD("yy", basis.elements[1][1]) - else TRY_TRANSFER_FIELD("yz", basis.elements[1][2]) - else TRY_TRANSFER_FIELD("zx", basis.elements[2][0]) - else TRY_TRANSFER_FIELD("zy", basis.elements[2][1]) - else TRY_TRANSFER_FIELD("zz", basis.elements[2][2]) + /**/ TRY_TRANSFER_FIELD("xx", basis.rows[0][0]) + else TRY_TRANSFER_FIELD("xy", basis.rows[0][1]) + else TRY_TRANSFER_FIELD("xz", basis.rows[0][2]) + else TRY_TRANSFER_FIELD("yx", basis.rows[1][0]) + else TRY_TRANSFER_FIELD("yy", basis.rows[1][1]) + else TRY_TRANSFER_FIELD("yz", basis.rows[1][2]) + else TRY_TRANSFER_FIELD("zx", basis.rows[2][0]) + else TRY_TRANSFER_FIELD("zy", basis.rows[2][1]) + else TRY_TRANSFER_FIELD("zz", basis.rows[2][2]) else TRY_TRANSFER_FIELD("xo", origin.x) else TRY_TRANSFER_FIELD("yo", origin.y) else TRY_TRANSFER_FIELD("zo", origin.z) diff --git a/core/math/projection.cpp b/core/math/projection.cpp index a27b9d7e5..da6789feb 100644 --- a/core/math/projection.cpp +++ b/core/math/projection.cpp @@ -881,17 +881,17 @@ Projection::operator Transform() const { Transform tr; const real_t *m = &matrix[0][0]; - tr.basis.elements[0][0] = m[0]; - tr.basis.elements[1][0] = m[1]; - tr.basis.elements[2][0] = m[2]; + tr.basis.rows[0][0] = m[0]; + tr.basis.rows[1][0] = m[1]; + tr.basis.rows[2][0] = m[2]; - tr.basis.elements[0][1] = m[4]; - tr.basis.elements[1][1] = m[5]; - tr.basis.elements[2][1] = m[6]; + tr.basis.rows[0][1] = m[4]; + tr.basis.rows[1][1] = m[5]; + tr.basis.rows[2][1] = m[6]; - tr.basis.elements[0][2] = m[8]; - tr.basis.elements[1][2] = m[9]; - tr.basis.elements[2][2] = m[10]; + tr.basis.rows[0][2] = m[8]; + tr.basis.rows[1][2] = m[9]; + tr.basis.rows[2][2] = m[10]; tr.origin.x = m[12]; tr.origin.y = m[13]; @@ -909,17 +909,17 @@ Projection::Projection(const Transform &p_transform) { const Transform &tr = p_transform; real_t *m = &matrix[0][0]; - m[0] = tr.basis.elements[0][0]; - m[1] = tr.basis.elements[1][0]; - m[2] = tr.basis.elements[2][0]; + m[0] = tr.basis.rows[0][0]; + m[1] = tr.basis.rows[1][0]; + m[2] = tr.basis.rows[2][0]; m[3] = 0.0; - m[4] = tr.basis.elements[0][1]; - m[5] = tr.basis.elements[1][1]; - m[6] = tr.basis.elements[2][1]; + m[4] = tr.basis.rows[0][1]; + m[5] = tr.basis.rows[1][1]; + m[6] = tr.basis.rows[2][1]; m[7] = 0.0; - m[8] = tr.basis.elements[0][2]; - m[9] = tr.basis.elements[1][2]; - m[10] = tr.basis.elements[2][2]; + m[8] = tr.basis.rows[0][2]; + m[9] = tr.basis.rows[1][2]; + m[10] = tr.basis.rows[2][2]; m[11] = 0.0; m[12] = tr.origin.x; m[13] = tr.origin.y; diff --git a/core/math/transform.h b/core/math/transform.h index c5e371679..74cfda48b 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -135,9 +135,9 @@ _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const { Vector3 v = p_vector - origin; return Vector3( - (basis.elements[0][0] * v.x) + (basis.elements[1][0] * v.y) + (basis.elements[2][0] * v.z), - (basis.elements[0][1] * v.x) + (basis.elements[1][1] * v.y) + (basis.elements[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][0] * v.x) + (basis.rows[1][0] * v.y) + (basis.rows[2][0] * v.z), + (basis.rows[0][1] * v.x) + (basis.rows[1][1] * v.y) + (basis.rows[2][1] * v.z), + (basis.rows[0][2] * v.x) + (basis.rows[1][2] * v.y) + (basis.rows[2][2] * v.z)); } _FORCE_INLINE_ Vector3i Transform::xform(const Vector3i &p_vector) const { @@ -154,9 +154,9 @@ _FORCE_INLINE_ Vector3i Transform::xform_inv(const Vector3i &p_vector) const { v.z -= origin.z; return Vector3i( - (basis.elements[0][0] * v.x) + (basis.elements[1][0] * v.y) + (basis.elements[2][0] * v.z), - (basis.elements[0][1] * v.x) + (basis.elements[1][1] * v.y) + (basis.elements[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][0] * v.x) + (basis.rows[1][0] * v.y) + (basis.rows[2][0] * v.z), + (basis.rows[0][1] * v.x) + (basis.rows[1][1] * v.y) + (basis.rows[2][1] * v.z), + (basis.rows[0][2] * v.x) + (basis.rows[1][2] * v.y) + (basis.rows[2][2] * v.z)); } // Neither the plane regular xform or xform_inv are particularly efficient, diff --git a/core/math/transform_interpolator.cpp b/core/math/transform_interpolator.cpp index cd85a419e..b5d9aad7c 100644 --- a/core/math/transform_interpolator.cpp +++ b/core/math/transform_interpolator.cpp @@ -61,7 +61,7 @@ void TransformInterpolator::interpolate_basis_via_method(const Basis &p_prev, co Quaternion TransformInterpolator::_basis_to_quat_unchecked(const Basis &p_basis) { Basis m = p_basis; - 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]; if (trace > 0) { @@ -69,23 +69,23 @@ Quaternion TransformInterpolator::_basis_to_quat_unchecked(const Basis &p_basis) temp[3] = (s * 0.5f); s = 0.5f / s; - temp[0] = ((m.elements[2][1] - m.elements[1][2]) * s); - temp[1] = ((m.elements[0][2] - m.elements[2][0]) * s); - temp[2] = ((m.elements[1][0] - m.elements[0][1]) * s); + temp[0] = ((m.rows[2][1] - m.rows[1][2]) * s); + temp[1] = ((m.rows[0][2] - m.rows[2][0]) * s); + temp[2] = ((m.rows[1][0] - m.rows[0][1]) * s); } else { - int i = m.elements[0][0] < m.elements[1][1] - ? (m.elements[1][1] < m.elements[2][2] ? 2 : 1) - : (m.elements[0][0] < m.elements[2][2] ? 2 : 0); + int i = m.rows[0][0] < m.rows[1][1] + ? (m.rows[1][1] < m.rows[2][2] ? 2 : 1) + : (m.rows[0][0] < m.rows[2][2] ? 2 : 0); int j = (i + 1) % 3; int k = (i + 2) % 3; - real_t s = Math::sqrt(m.elements[i][i] - m.elements[j][j] - m.elements[k][k] + 1.0f); + real_t s = Math::sqrt(m.rows[i][i] - m.rows[j][j] - m.rows[k][k] + 1.0f); temp[i] = s * 0.5f; s = 0.5f / s; - temp[3] = (m.elements[k][j] - m.elements[j][k]) * s; - temp[j] = (m.elements[j][i] + m.elements[i][j]) * s; - temp[k] = (m.elements[k][i] + m.elements[i][k]) * s; + temp[3] = (m.rows[k][j] - m.rows[j][k]) * s; + temp[j] = (m.rows[j][i] + m.rows[i][j]) * s; + temp[k] = (m.rows[k][i] + m.rows[i][k]) * s; } return Quaternion(temp[0], temp[1], temp[2], temp[3]); @@ -188,9 +188,9 @@ void TransformInterpolator::interpolate_basis_linear(const Basis &p_prev, const real_t TransformInterpolator::checksum_transform(const Transform &p_transform) { // just a really basic checksum, this can probably be improved real_t sum = vec3_sum(p_transform.origin); - sum -= vec3_sum(p_transform.basis.elements[0]); - sum += vec3_sum(p_transform.basis.elements[1]); - sum -= vec3_sum(p_transform.basis.elements[2]); + sum -= vec3_sum(p_transform.basis.rows[0]); + sum += vec3_sum(p_transform.basis.rows[1]); + sum -= vec3_sum(p_transform.basis.rows[2]); return sum; } diff --git a/core/variant.cpp b/core/variant.cpp index 3a27e7cd1..cdc0b17ad 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -1680,7 +1680,7 @@ String Variant::stringify(List &stack) const { mtx += ", "; } - mtx += Variant(mat3.elements[i][j]).operator String(); + mtx += Variant(mat3.rows[i][j]).operator String(); } mtx += ")"; @@ -1912,10 +1912,10 @@ Variant::operator Transform() const { } else if (type == TRANSFORM2D) { const Transform2D &t = *_data._transform2d; Transform m; - m.basis.elements[0][0] = t.elements[0][0]; - m.basis.elements[1][0] = t.elements[0][1]; - m.basis.elements[0][1] = t.elements[1][0]; - m.basis.elements[1][1] = t.elements[1][1]; + m.basis.rows[0][0] = t.elements[0][0]; + m.basis.rows[1][0] = t.elements[0][1]; + m.basis.rows[0][1] = t.elements[1][0]; + m.basis.rows[1][1] = t.elements[1][1]; m.origin[0] = t.elements[2][0]; m.origin[1] = t.elements[2][1]; return m; @@ -1930,10 +1930,10 @@ Variant::operator Transform2D() const { } else if (type == TRANSFORM) { const Transform &t = *_data._transform; Transform2D m; - m.elements[0][0] = t.basis.elements[0][0]; - m.elements[0][1] = t.basis.elements[1][0]; - m.elements[1][0] = t.basis.elements[0][1]; - m.elements[1][1] = t.basis.elements[1][1]; + m.elements[0][0] = t.basis.rows[0][0]; + m.elements[0][1] = t.basis.rows[1][0]; + m.elements[1][0] = t.basis.rows[0][1]; + m.elements[1][1] = t.basis.rows[1][1]; m.elements[2][0] = t.origin[0]; m.elements[2][1] = t.origin[1]; return m; @@ -3038,7 +3038,7 @@ uint32_t Variant::hash() const { uint32_t hash = 5831; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - hash = hash_djb2_one_float(_data._basis->elements[i][j], hash); + hash = hash_djb2_one_float(_data._basis->rows[i][j], hash); } } @@ -3049,7 +3049,7 @@ uint32_t Variant::hash() const { uint32_t hash = 5831; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - hash = hash_djb2_one_float(_data._transform->basis.elements[i][j], hash); + hash = hash_djb2_one_float(_data._transform->basis.rows[i][j], hash); } hash = hash_djb2_one_float(_data._transform->origin[i], hash); } @@ -3380,7 +3380,7 @@ bool Variant::hash_compare(const Variant &p_variant) const { const Basis *r = p_variant._data._basis; for (int i = 0; i < 3; i++) { - if (!(hash_compare_vector3(l->elements[i], r->elements[i]))) { + if (!(hash_compare_vector3(l->rows[i], r->rows[i]))) { return false; } } @@ -3393,7 +3393,7 @@ bool Variant::hash_compare(const Variant &p_variant) const { const Transform *r = p_variant._data._transform; for (int i = 0; i < 3; i++) { - if (!(hash_compare_vector3(l->basis.elements[i], r->basis.elements[i]))) { + if (!(hash_compare_vector3(l->basis.rows[i], r->basis.rows[i]))) { return false; } } diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index d3ffd4024..2e3766e09 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -1730,7 +1730,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str if (i != 0 || j != 0) { s += ", "; } - s += rtos_fix(m3.elements[i][j]); + s += rtos_fix(m3.rows[i][j]); } } @@ -1746,7 +1746,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str if (i != 0 || j != 0) { s += ", "; } - s += rtos_fix(m3.elements[i][j]); + s += rtos_fix(m3.rows[i][j]); } } diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 0cb20e7b4..8a1615f6f 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -3095,17 +3095,17 @@ void RasterizerStorageGLES2::_multimesh_instance_set_transform(RID p_multimesh, float *dataptr = &multimesh->data.write[stride * p_index]; - dataptr[0] = p_transform.basis.elements[0][0]; - dataptr[1] = p_transform.basis.elements[0][1]; - dataptr[2] = p_transform.basis.elements[0][2]; + dataptr[0] = p_transform.basis.rows[0][0]; + dataptr[1] = p_transform.basis.rows[0][1]; + dataptr[2] = p_transform.basis.rows[0][2]; dataptr[3] = p_transform.origin.x; - dataptr[4] = p_transform.basis.elements[1][0]; - dataptr[5] = p_transform.basis.elements[1][1]; - dataptr[6] = p_transform.basis.elements[1][2]; + dataptr[4] = p_transform.basis.rows[1][0]; + dataptr[5] = p_transform.basis.rows[1][1]; + dataptr[6] = p_transform.basis.rows[1][2]; dataptr[7] = p_transform.origin.y; - dataptr[8] = p_transform.basis.elements[2][0]; - dataptr[9] = p_transform.basis.elements[2][1]; - dataptr[10] = p_transform.basis.elements[2][2]; + dataptr[8] = p_transform.basis.rows[2][0]; + dataptr[9] = p_transform.basis.rows[2][1]; + dataptr[10] = p_transform.basis.rows[2][2]; dataptr[11] = p_transform.origin.z; multimesh->dirty_data = true; @@ -3224,17 +3224,17 @@ Transform RasterizerStorageGLES2::_multimesh_instance_get_transform(RID p_multim Transform xform; - xform.basis.elements[0][0] = dataptr[0]; - xform.basis.elements[0][1] = dataptr[1]; - xform.basis.elements[0][2] = dataptr[2]; + xform.basis.rows[0][0] = dataptr[0]; + xform.basis.rows[0][1] = dataptr[1]; + xform.basis.rows[0][2] = dataptr[2]; xform.origin.x = dataptr[3]; - xform.basis.elements[1][0] = dataptr[4]; - xform.basis.elements[1][1] = dataptr[5]; - xform.basis.elements[1][2] = dataptr[6]; + xform.basis.rows[1][0] = dataptr[4]; + xform.basis.rows[1][1] = dataptr[5]; + xform.basis.rows[1][2] = dataptr[6]; xform.origin.y = dataptr[7]; - xform.basis.elements[2][0] = dataptr[8]; - xform.basis.elements[2][1] = dataptr[9]; - xform.basis.elements[2][2] = dataptr[10]; + xform.basis.rows[2][0] = dataptr[8]; + xform.basis.rows[2][1] = dataptr[9]; + xform.basis.rows[2][2] = dataptr[10]; xform.origin.z = dataptr[11]; return xform; @@ -3423,17 +3423,17 @@ void RasterizerStorageGLES2::update_dirty_multimeshes() { float *dataptr = &data[i]; Transform xform; - xform.basis.elements[0][0] = dataptr[0]; - xform.basis.elements[0][1] = dataptr[1]; - xform.basis.elements[0][2] = dataptr[2]; + xform.basis.rows[0][0] = dataptr[0]; + xform.basis.rows[0][1] = dataptr[1]; + xform.basis.rows[0][2] = dataptr[2]; xform.origin.x = dataptr[3]; - xform.basis.elements[1][0] = dataptr[4]; - xform.basis.elements[1][1] = dataptr[5]; - xform.basis.elements[1][2] = dataptr[6]; + xform.basis.rows[1][0] = dataptr[4]; + xform.basis.rows[1][1] = dataptr[5]; + xform.basis.rows[1][2] = dataptr[6]; xform.origin.y = dataptr[7]; - xform.basis.elements[2][0] = dataptr[8]; - xform.basis.elements[2][1] = dataptr[9]; - xform.basis.elements[2][2] = dataptr[10]; + xform.basis.rows[2][0] = dataptr[8]; + xform.basis.rows[2][1] = dataptr[9]; + xform.basis.rows[2][2] = dataptr[10]; xform.origin.z = dataptr[11]; AABB laabb = xform.xform(mesh_aabb); diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/gles2/shader_gles2.cpp index 0fd09ed6e..104285e30 100644 --- a/drivers/gles2/shader_gles2.cpp +++ b/drivers/gles2/shader_gles2.cpp @@ -798,15 +798,15 @@ void ShaderGLES2::use_material(void *p_material) { Basis val = V->get(); GLfloat mat[9] = { - val.elements[0][0], - val.elements[1][0], - val.elements[2][0], - val.elements[0][1], - val.elements[1][1], - val.elements[2][1], - val.elements[0][2], - val.elements[1][2], - val.elements[2][2], + val.rows[0][0], + val.rows[1][0], + val.rows[2][0], + val.rows[0][1], + val.rows[1][1], + val.rows[2][1], + val.rows[0][2], + val.rows[1][2], + val.rows[2][2], }; glUniformMatrix3fv(location, 1, GL_FALSE, mat); @@ -817,17 +817,17 @@ void ShaderGLES2::use_material(void *p_material) { if (V->get().get_type() == Variant::TRANSFORM) { Transform tr = V->get(); GLfloat matrix[16] = { /* build a 16x16 matrix */ - tr.basis.elements[0][0], - tr.basis.elements[1][0], - tr.basis.elements[2][0], + tr.basis.rows[0][0], + tr.basis.rows[1][0], + tr.basis.rows[2][0], 0, - tr.basis.elements[0][1], - tr.basis.elements[1][1], - tr.basis.elements[2][1], + tr.basis.rows[0][1], + tr.basis.rows[1][1], + tr.basis.rows[2][1], 0, - tr.basis.elements[0][2], - tr.basis.elements[1][2], - tr.basis.elements[2][2], + tr.basis.rows[0][2], + tr.basis.rows[1][2], + tr.basis.rows[2][2], 0, tr.origin.x, tr.origin.y, diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 73684985a..438ff9d75 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -805,9 +805,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: field_names.push_back("oy"); config_value_editors(6, 2, 16, field_names); - Transform2D basis = v; + Transform2D t = v; for (int i = 0; i < 6; i++) { - value_editor[i]->set_text(String::num(basis.elements[i / 2][i % 2])); + value_editor[i]->set_text(String::num(t.elements[i / 2][i % 2])); } } break; @@ -825,7 +825,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: Basis basis = v; for (int i = 0; i < 9; i++) { - value_editor[i]->set_text(String::num(basis.elements[i / 3][i % 3])); + value_editor[i]->set_text(String::num(basis.rows[i / 3][i % 3])); } } break; @@ -846,7 +846,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: Transform tr = v; for (int i = 0; i < 9; i++) { - value_editor[(i / 3) * 4 + i % 3]->set_text(String::num(tr.basis.elements[i / 3][i % 3])); + value_editor[(i / 3) * 4 + i % 3]->set_text(String::num(tr.basis.rows[i / 3][i % 3])); } value_editor[3]->set_text(String::num(tr.origin.x)); @@ -1591,7 +1591,7 @@ void CustomPropertyEditor::_modified(String p_string) { case Variant::BASIS: { Basis m; for (int i = 0; i < 9; i++) { - m.elements[i / 3][i % 3] = _parse_real_expression(value_editor[i]->get_text()); + m.rows[i / 3][i % 3] = _parse_real_expression(value_editor[i]->get_text()); } v = m; @@ -1601,7 +1601,7 @@ void CustomPropertyEditor::_modified(String p_string) { case Variant::TRANSFORM: { Basis basis; for (int i = 0; i < 9; i++) { - basis.elements[i / 3][i % 3] = _parse_real_expression(value_editor[(i / 3) * 4 + i % 3]->get_text()); + basis.rows[i / 3][i % 3] = _parse_real_expression(value_editor[(i / 3) * 4 + i % 3]->get_text()); } Vector3 origin; diff --git a/gles_builders.py b/gles_builders.py index 8ab782241..7dcecad31 100644 --- a/gles_builders.py +++ b/gles_builders.py @@ -296,17 +296,17 @@ def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2 const Transform &tr = p_transform; GLfloat matrix[16]={ /* build a 16x16 matrix */ - tr.basis.elements[0][0], - tr.basis.elements[1][0], - tr.basis.elements[2][0], + tr.basis.rows[0][0], + tr.basis.rows[1][0], + tr.basis.rows[2][0], 0, - tr.basis.elements[0][1], - tr.basis.elements[1][1], - tr.basis.elements[2][1], + tr.basis.rows[0][1], + tr.basis.rows[1][1], + tr.basis.rows[2][1], 0, - tr.basis.elements[0][2], - tr.basis.elements[1][2], - tr.basis.elements[2][2], + tr.basis.rows[0][2], + tr.basis.rows[1][2], + tr.basis.rows[2][2], 0, tr.origin.x, tr.origin.y, diff --git a/modules/network_synchronizer/scene_synchronizer.cpp b/modules/network_synchronizer/scene_synchronizer.cpp index d9f2f51f5..7d499abce 100644 --- a/modules/network_synchronizer/scene_synchronizer.cpp +++ b/modules/network_synchronizer/scene_synchronizer.cpp @@ -1369,9 +1369,9 @@ bool SceneSynchronizer::compare(const Variant &p_first, const Variant &p_second, case Variant::BASIS: { const Basis a = p_first; const Basis b = p_second; - if (compare(a.elements[0], b.elements[0], p_tolerance)) { - if (compare(a.elements[1], b.elements[1], p_tolerance)) { - if (compare(a.elements[2], b.elements[2], p_tolerance)) { + if (compare(a.rows[0], b.rows[0], p_tolerance)) { + if (compare(a.rows[1], b.rows[1], p_tolerance)) { + if (compare(a.rows[2], b.rows[2], p_tolerance)) { return true; } } @@ -1382,9 +1382,9 @@ bool SceneSynchronizer::compare(const Variant &p_first, const Variant &p_second, const Transform a = p_first; const Transform b = p_second; if (compare(a.origin, b.origin, p_tolerance)) { - if (compare(a.basis.elements[0], b.basis.elements[0], p_tolerance)) { - if (compare(a.basis.elements[1], b.basis.elements[1], p_tolerance)) { - if (compare(a.basis.elements[2], b.basis.elements[2], p_tolerance)) { + if (compare(a.basis.rows[0], b.basis.rows[0], p_tolerance)) { + if (compare(a.basis.rows[1], b.basis.rows[1], p_tolerance)) { + if (compare(a.basis.rows[2], b.basis.rows[2], p_tolerance)) { return true; } } diff --git a/scene/3d/cpu_particles.h b/scene/3d/cpu_particles.h index 80cfd9982..9e185736a 100644 --- a/scene/3d/cpu_particles.h +++ b/scene/3d/cpu_particles.h @@ -222,17 +222,17 @@ private: const Transform &t = p_source.transform; if (p_active) { - r_dest[0] = t.basis.elements[0][0]; - r_dest[1] = t.basis.elements[0][1]; - r_dest[2] = t.basis.elements[0][2]; + r_dest[0] = t.basis.rows[0][0]; + r_dest[1] = t.basis.rows[0][1]; + r_dest[2] = t.basis.rows[0][2]; r_dest[3] = t.origin.x; - r_dest[4] = t.basis.elements[1][0]; - r_dest[5] = t.basis.elements[1][1]; - r_dest[6] = t.basis.elements[1][2]; + r_dest[4] = t.basis.rows[1][0]; + r_dest[5] = t.basis.rows[1][1]; + r_dest[6] = t.basis.rows[1][2]; r_dest[7] = t.origin.y; - r_dest[8] = t.basis.elements[2][0]; - r_dest[9] = t.basis.elements[2][1]; - r_dest[10] = t.basis.elements[2][2]; + r_dest[8] = t.basis.rows[2][0]; + r_dest[9] = t.basis.rows[2][1]; + r_dest[10] = t.basis.rows[2][2]; r_dest[11] = t.origin.z; } else { memset(r_dest, 0, sizeof(float) * 12); diff --git a/scene/animation/scene_tree_tween.cpp b/scene/animation/scene_tree_tween.cpp index 5a789e8ef..bc9c7bc6c 100644 --- a/scene/animation/scene_tree_tween.cpp +++ b/scene/animation/scene_tree_tween.cpp @@ -450,15 +450,15 @@ Variant SceneTreeTween::interpolate_variant(Variant p_initial_val, Variant p_del Basis d = p_delta_val; Basis r; - APPLY_EQUATION(elements[0][0]); - APPLY_EQUATION(elements[0][1]); - APPLY_EQUATION(elements[0][2]); - APPLY_EQUATION(elements[1][0]); - APPLY_EQUATION(elements[1][1]); - APPLY_EQUATION(elements[1][2]); - APPLY_EQUATION(elements[2][0]); - APPLY_EQUATION(elements[2][1]); - APPLY_EQUATION(elements[2][2]); + APPLY_EQUATION(rows[0][0]); + APPLY_EQUATION(rows[0][1]); + APPLY_EQUATION(rows[0][2]); + APPLY_EQUATION(rows[1][0]); + APPLY_EQUATION(rows[1][1]); + APPLY_EQUATION(rows[1][2]); + APPLY_EQUATION(rows[2][0]); + APPLY_EQUATION(rows[2][1]); + APPLY_EQUATION(rows[2][2]); return r; } @@ -467,15 +467,15 @@ Variant SceneTreeTween::interpolate_variant(Variant p_initial_val, Variant p_del Transform d = p_delta_val; Transform r; - APPLY_EQUATION(basis.elements[0][0]); - APPLY_EQUATION(basis.elements[0][1]); - APPLY_EQUATION(basis.elements[0][2]); - APPLY_EQUATION(basis.elements[1][0]); - APPLY_EQUATION(basis.elements[1][1]); - APPLY_EQUATION(basis.elements[1][2]); - APPLY_EQUATION(basis.elements[2][0]); - APPLY_EQUATION(basis.elements[2][1]); - APPLY_EQUATION(basis.elements[2][2]); + APPLY_EQUATION(basis.rows[0][0]); + APPLY_EQUATION(basis.rows[0][1]); + APPLY_EQUATION(basis.rows[0][2]); + APPLY_EQUATION(basis.rows[1][0]); + APPLY_EQUATION(basis.rows[1][1]); + APPLY_EQUATION(basis.rows[1][2]); + APPLY_EQUATION(basis.rows[2][0]); + APPLY_EQUATION(basis.rows[2][1]); + APPLY_EQUATION(basis.rows[2][2]); APPLY_EQUATION(origin.x); APPLY_EQUATION(origin.y); APPLY_EQUATION(origin.z); @@ -535,29 +535,29 @@ Variant SceneTreeTween::calculate_delta_value(Variant p_intial_val, Variant p_fi case Variant::BASIS: { Basis i = p_intial_val; Basis f = p_final_val; - return Basis(f.elements[0][0] - i.elements[0][0], - f.elements[0][1] - i.elements[0][1], - f.elements[0][2] - i.elements[0][2], - f.elements[1][0] - i.elements[1][0], - f.elements[1][1] - i.elements[1][1], - f.elements[1][2] - i.elements[1][2], - f.elements[2][0] - i.elements[2][0], - f.elements[2][1] - i.elements[2][1], - f.elements[2][2] - i.elements[2][2]); + return Basis(f.rows[0][0] - i.rows[0][0], + f.rows[0][1] - i.rows[0][1], + f.rows[0][2] - i.rows[0][2], + f.rows[1][0] - i.rows[1][0], + f.rows[1][1] - i.rows[1][1], + f.rows[1][2] - i.rows[1][2], + f.rows[2][0] - i.rows[2][0], + f.rows[2][1] - i.rows[2][1], + f.rows[2][2] - i.rows[2][2]); } case Variant::TRANSFORM: { Transform i = p_intial_val; Transform f = p_final_val; - return Transform(f.basis.elements[0][0] - i.basis.elements[0][0], - f.basis.elements[0][1] - i.basis.elements[0][1], - f.basis.elements[0][2] - i.basis.elements[0][2], - f.basis.elements[1][0] - i.basis.elements[1][0], - f.basis.elements[1][1] - i.basis.elements[1][1], - f.basis.elements[1][2] - i.basis.elements[1][2], - f.basis.elements[2][0] - i.basis.elements[2][0], - f.basis.elements[2][1] - i.basis.elements[2][1], - f.basis.elements[2][2] - i.basis.elements[2][2], + return Transform(f.basis.rows[0][0] - i.basis.rows[0][0], + f.basis.rows[0][1] - i.basis.rows[0][1], + f.basis.rows[0][2] - i.basis.rows[0][2], + f.basis.rows[1][0] - i.basis.rows[1][0], + f.basis.rows[1][1] - i.basis.rows[1][1], + f.basis.rows[1][2] - i.basis.rows[1][2], + f.basis.rows[2][0] - i.basis.rows[2][0], + f.basis.rows[2][1] - i.basis.rows[2][1], + f.basis.rows[2][2] - i.basis.rows[2][2], f.origin.x - i.origin.x, f.origin.y - i.origin.y, f.origin.z - i.origin.z); diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 4b56b804b..b3019b8e2 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -587,15 +587,15 @@ Variant Tween::_run_equation(InterpolateData &p_data) { // Execute the equation on all the basis and mutate the r basis // This uses the custom APPLY_EQUATION macro defined above - APPLY_EQUATION(elements[0][0]); - APPLY_EQUATION(elements[0][1]); - APPLY_EQUATION(elements[0][2]); - APPLY_EQUATION(elements[1][0]); - APPLY_EQUATION(elements[1][1]); - APPLY_EQUATION(elements[1][2]); - APPLY_EQUATION(elements[2][0]); - APPLY_EQUATION(elements[2][1]); - APPLY_EQUATION(elements[2][2]); + APPLY_EQUATION(rows[0][0]); + APPLY_EQUATION(rows[0][1]); + APPLY_EQUATION(rows[0][2]); + APPLY_EQUATION(rows[1][0]); + APPLY_EQUATION(rows[1][1]); + APPLY_EQUATION(rows[1][2]); + APPLY_EQUATION(rows[2][0]); + APPLY_EQUATION(rows[2][1]); + APPLY_EQUATION(rows[2][2]); result = r; } break; @@ -607,15 +607,15 @@ Variant Tween::_run_equation(InterpolateData &p_data) { // Execute the equation for each of the transforms and their origin and mutate the r transform // This uses the custom APPLY_EQUATION macro defined above - APPLY_EQUATION(basis.elements[0][0]); - APPLY_EQUATION(basis.elements[0][1]); - APPLY_EQUATION(basis.elements[0][2]); - APPLY_EQUATION(basis.elements[1][0]); - APPLY_EQUATION(basis.elements[1][1]); - APPLY_EQUATION(basis.elements[1][2]); - APPLY_EQUATION(basis.elements[2][0]); - APPLY_EQUATION(basis.elements[2][1]); - APPLY_EQUATION(basis.elements[2][2]); + APPLY_EQUATION(basis.rows[0][0]); + APPLY_EQUATION(basis.rows[0][1]); + APPLY_EQUATION(basis.rows[0][2]); + APPLY_EQUATION(basis.rows[1][0]); + APPLY_EQUATION(basis.rows[1][1]); + APPLY_EQUATION(basis.rows[1][2]); + APPLY_EQUATION(basis.rows[2][0]); + APPLY_EQUATION(basis.rows[2][1]); + APPLY_EQUATION(basis.rows[2][2]); APPLY_EQUATION(origin.x); APPLY_EQUATION(origin.y); APPLY_EQUATION(origin.z); @@ -1274,15 +1274,15 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final // Build a new basis which is the delta between the initial and final values Basis i = initial_val; Basis f = final_val; - delta_val = Basis(f.elements[0][0] - i.elements[0][0], - f.elements[0][1] - i.elements[0][1], - f.elements[0][2] - i.elements[0][2], - f.elements[1][0] - i.elements[1][0], - f.elements[1][1] - i.elements[1][1], - f.elements[1][2] - i.elements[1][2], - f.elements[2][0] - i.elements[2][0], - f.elements[2][1] - i.elements[2][1], - f.elements[2][2] - i.elements[2][2]); + delta_val = Basis(f.rows[0][0] - i.rows[0][0], + f.rows[0][1] - i.rows[0][1], + f.rows[0][2] - i.rows[0][2], + f.rows[1][0] - i.rows[1][0], + f.rows[1][1] - i.rows[1][1], + f.rows[1][2] - i.rows[1][2], + f.rows[2][0] - i.rows[2][0], + f.rows[2][1] - i.rows[2][1], + f.rows[2][2] - i.rows[2][2]); } break; case Variant::TRANSFORM: { @@ -1290,15 +1290,15 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final Transform i = initial_val; Transform f = final_val; Transform d; - d.set(f.basis.elements[0][0] - i.basis.elements[0][0], - f.basis.elements[0][1] - i.basis.elements[0][1], - f.basis.elements[0][2] - i.basis.elements[0][2], - f.basis.elements[1][0] - i.basis.elements[1][0], - f.basis.elements[1][1] - i.basis.elements[1][1], - f.basis.elements[1][2] - i.basis.elements[1][2], - f.basis.elements[2][0] - i.basis.elements[2][0], - f.basis.elements[2][1] - i.basis.elements[2][1], - f.basis.elements[2][2] - i.basis.elements[2][2], + d.set(f.basis.rows[0][0] - i.basis.rows[0][0], + f.basis.rows[0][1] - i.basis.rows[0][1], + f.basis.rows[0][2] - i.basis.rows[0][2], + f.basis.rows[1][0] - i.basis.rows[1][0], + f.basis.rows[1][1] - i.basis.rows[1][1], + f.basis.rows[1][2] - i.basis.rows[1][2], + f.basis.rows[2][0] - i.basis.rows[2][0], + f.basis.rows[2][1] - i.basis.rows[2][1], + f.basis.rows[2][2] - i.basis.rows[2][2], f.origin.x - i.origin.x, f.origin.y - i.origin.y, f.origin.z - i.origin.z); diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp index 3afcea28f..d6bfe656c 100644 --- a/servers/visual/rasterizer.cpp +++ b/servers/visual/rasterizer.cpp @@ -170,43 +170,43 @@ void RasterizerStorage::update_interpolation_frame(bool p_process) { } else { // Silly swizzling, this will slow things down. no idea why it is using this format // .. maybe due to the shader. - tp.basis.elements[0][0] = pf_prev[0]; - tp.basis.elements[0][1] = pf_prev[1]; - tp.basis.elements[0][2] = pf_prev[2]; - tp.basis.elements[1][0] = pf_prev[4]; - tp.basis.elements[1][1] = pf_prev[5]; - tp.basis.elements[1][2] = pf_prev[6]; - tp.basis.elements[2][0] = pf_prev[8]; - tp.basis.elements[2][1] = pf_prev[9]; - tp.basis.elements[2][2] = pf_prev[10]; + tp.basis.rows[0][0] = pf_prev[0]; + tp.basis.rows[0][1] = pf_prev[1]; + tp.basis.rows[0][2] = pf_prev[2]; + tp.basis.rows[1][0] = pf_prev[4]; + tp.basis.rows[1][1] = pf_prev[5]; + tp.basis.rows[1][2] = pf_prev[6]; + tp.basis.rows[2][0] = pf_prev[8]; + tp.basis.rows[2][1] = pf_prev[9]; + tp.basis.rows[2][2] = pf_prev[10]; tp.origin.x = pf_prev[3]; tp.origin.y = pf_prev[7]; tp.origin.z = pf_prev[11]; - tc.basis.elements[0][0] = pf_curr[0]; - tc.basis.elements[0][1] = pf_curr[1]; - tc.basis.elements[0][2] = pf_curr[2]; - tc.basis.elements[1][0] = pf_curr[4]; - tc.basis.elements[1][1] = pf_curr[5]; - tc.basis.elements[1][2] = pf_curr[6]; - tc.basis.elements[2][0] = pf_curr[8]; - tc.basis.elements[2][1] = pf_curr[9]; - tc.basis.elements[2][2] = pf_curr[10]; + tc.basis.rows[0][0] = pf_curr[0]; + tc.basis.rows[0][1] = pf_curr[1]; + tc.basis.rows[0][2] = pf_curr[2]; + tc.basis.rows[1][0] = pf_curr[4]; + tc.basis.rows[1][1] = pf_curr[5]; + tc.basis.rows[1][2] = pf_curr[6]; + tc.basis.rows[2][0] = pf_curr[8]; + tc.basis.rows[2][1] = pf_curr[9]; + tc.basis.rows[2][2] = pf_curr[10]; tc.origin.x = pf_curr[3]; tc.origin.y = pf_curr[7]; tc.origin.z = pf_curr[11]; TransformInterpolator::interpolate_transform(tp, tc, tr, f); - pf_int[0] = tr.basis.elements[0][0]; - pf_int[1] = tr.basis.elements[0][1]; - pf_int[2] = tr.basis.elements[0][2]; - pf_int[4] = tr.basis.elements[1][0]; - pf_int[5] = tr.basis.elements[1][1]; - pf_int[6] = tr.basis.elements[1][2]; - pf_int[8] = tr.basis.elements[2][0]; - pf_int[9] = tr.basis.elements[2][1]; - pf_int[10] = tr.basis.elements[2][2]; + pf_int[0] = tr.basis.rows[0][0]; + pf_int[1] = tr.basis.rows[0][1]; + pf_int[2] = tr.basis.rows[0][2]; + pf_int[4] = tr.basis.rows[1][0]; + pf_int[5] = tr.basis.rows[1][1]; + pf_int[6] = tr.basis.rows[1][2]; + pf_int[8] = tr.basis.rows[2][0]; + pf_int[9] = tr.basis.rows[2][1]; + pf_int[10] = tr.basis.rows[2][2]; pf_int[3] = tr.origin.x; pf_int[7] = tr.origin.y; pf_int[11] = tr.origin.z; @@ -336,17 +336,17 @@ void RasterizerStorage::multimesh_instance_set_transform(RID p_multimesh, int p_ ptr += start; const Transform &t = p_transform; - ptr[0] = t.basis.elements[0][0]; - ptr[1] = t.basis.elements[0][1]; - ptr[2] = t.basis.elements[0][2]; + ptr[0] = t.basis.rows[0][0]; + ptr[1] = t.basis.rows[0][1]; + ptr[2] = t.basis.rows[0][2]; ptr[3] = t.origin.x; - ptr[4] = t.basis.elements[1][0]; - ptr[5] = t.basis.elements[1][1]; - ptr[6] = t.basis.elements[1][2]; + ptr[4] = t.basis.rows[1][0]; + ptr[5] = t.basis.rows[1][1]; + ptr[6] = t.basis.rows[1][2]; ptr[7] = t.origin.y; - ptr[8] = t.basis.elements[2][0]; - ptr[9] = t.basis.elements[2][1]; - ptr[10] = t.basis.elements[2][2]; + ptr[8] = t.basis.rows[2][0]; + ptr[9] = t.basis.rows[2][1]; + ptr[10] = t.basis.rows[2][2]; ptr[11] = t.origin.z; _multimesh_add_to_interpolation_lists(p_multimesh, *mmi); diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 82a8e0319..30976e3d4 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -704,7 +704,7 @@ void VisualServerScene::instance_set_transform(RID p_instance, const Transform & #ifdef DEBUG_ENABLED for (int i = 0; i < 4; i++) { - const Vector3 &v = i < 3 ? p_transform.basis.elements[i] : p_transform.origin; + const Vector3 &v = i < 3 ? p_transform.basis.rows[i] : p_transform.origin; ERR_FAIL_COND(Math::is_inf(v.x)); ERR_FAIL_COND(Math::is_nan(v.x)); ERR_FAIL_COND(Math::is_inf(v.y)); @@ -735,7 +735,7 @@ void VisualServerScene::instance_set_transform(RID p_instance, const Transform & #ifdef DEBUG_ENABLED for (int i = 0; i < 4; i++) { - const Vector3 &v = i < 3 ? p_transform.basis.elements[i] : p_transform.origin; + const Vector3 &v = i < 3 ? p_transform.basis.rows[i] : p_transform.origin; ERR_FAIL_COND(Math::is_inf(v.x)); ERR_FAIL_COND(Math::is_nan(v.x)); ERR_FAIL_COND(Math::is_inf(v.y));