diff options
author | George Marques <george@gmarqu.es> | 2021-02-28 16:52:06 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2021-02-28 16:57:34 -0300 |
commit | cba90d630177ce6c57b5537e74ef3eab4e9c1ea2 (patch) | |
tree | 439897c2673d4f0af2635abffe73699d0cae6a01 /src | |
parent | 77d41fa179e40560f1e264ed483638bf51713779 (diff) | |
download | redot-cpp-cba90d630177ce6c57b5537e74ef3eab4e9c1ea2.tar.gz |
Update clang-format to version 11
This is taken from the Godot repository, so formatting is similar. This
updates the style rules as well.
Also fix style in files to conform with this version.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/AABB.cpp | 70 | ||||
-rw-r--r-- | src/core/Basis.cpp | 29 | ||||
-rw-r--r-- | src/core/CameraMatrix.cpp | 40 | ||||
-rw-r--r-- | src/core/Color.cpp | 23 | ||||
-rw-r--r-- | src/core/GodotGlobal.cpp | 21 | ||||
-rw-r--r-- | src/core/Plane.cpp | 21 | ||||
-rw-r--r-- | src/core/Quat.cpp | 8 | ||||
-rw-r--r-- | src/core/Rect2.cpp | 5 | ||||
-rw-r--r-- | src/core/String.cpp | 2 | ||||
-rw-r--r-- | src/core/TagDB.cpp | 2 | ||||
-rw-r--r-- | src/core/Transform.cpp | 30 | ||||
-rw-r--r-- | src/core/Transform2D.cpp | 30 |
12 files changed, 40 insertions, 241 deletions
diff --git a/src/core/AABB.cpp b/src/core/AABB.cpp index a67d459..2016cc7 100644 --- a/src/core/AABB.cpp +++ b/src/core/AABB.cpp @@ -7,7 +7,6 @@ namespace godot { bool AABB::intersects(const AABB &p_aabb) const { - if (position.x >= (p_aabb.position.x + p_aabb.size.x)) return false; if ((position.x + size.x) <= p_aabb.position.x) @@ -25,7 +24,6 @@ bool AABB::intersects(const AABB &p_aabb) const { } bool AABB::intersects_inclusive(const AABB &p_aabb) const { - if (position.x > (p_aabb.position.x + p_aabb.size.x)) return false; if ((position.x + size.x) < p_aabb.position.x) @@ -43,7 +41,6 @@ bool AABB::intersects_inclusive(const AABB &p_aabb) const { } bool AABB::encloses(const AABB &p_aabb) const { - Vector3 src_min = position; Vector3 src_max = position + size; Vector3 dst_min = p_aabb.position; @@ -59,7 +56,6 @@ bool AABB::encloses(const AABB &p_aabb) const { } Vector3 AABB::get_support(const Vector3 &p_normal) const { - Vector3 half_extents = size * 0.5; Vector3 ofs = position + half_extents; @@ -71,23 +67,29 @@ Vector3 AABB::get_support(const Vector3 &p_normal) const { } Vector3 AABB::get_endpoint(int p_point) const { - switch (p_point) { - case 0: return Vector3(position.x, position.y, position.z); - case 1: return Vector3(position.x, position.y, position.z + size.z); - case 2: return Vector3(position.x, position.y + size.y, position.z); - case 3: return Vector3(position.x, position.y + size.y, position.z + size.z); - case 4: return Vector3(position.x + size.x, position.y, position.z); - case 5: return Vector3(position.x + size.x, position.y, position.z + size.z); - case 6: return Vector3(position.x + size.x, position.y + size.y, position.z); - case 7: return Vector3(position.x + size.x, position.y + size.y, position.z + size.z); + case 0: + return Vector3(position.x, position.y, position.z); + case 1: + return Vector3(position.x, position.y, position.z + size.z); + case 2: + return Vector3(position.x, position.y + size.y, position.z); + case 3: + return Vector3(position.x, position.y + size.y, position.z + size.z); + case 4: + return Vector3(position.x + size.x, position.y, position.z); + case 5: + return Vector3(position.x + size.x, position.y, position.z + size.z); + case 6: + return Vector3(position.x + size.x, position.y + size.y, position.z); + case 7: + return Vector3(position.x + size.x, position.y + size.y, position.z + size.z); }; ERR_FAIL_V(Vector3()); } bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const { - Vector3 half_extents = size * 0.5; Vector3 ofs = position + half_extents; @@ -106,7 +108,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) con } bool AABB::has_point(const Vector3 &p_point) const { - if (p_point.x < position.x) return false; if (p_point.y < position.y) @@ -124,7 +125,6 @@ bool AABB::has_point(const Vector3 &p_point) const { } void AABB::expand_to(const Vector3 &p_vector) { - Vector3 begin = position; Vector3 end = position + size; @@ -147,7 +147,6 @@ void AABB::expand_to(const Vector3 &p_vector) { } void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const { - Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5); Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z); @@ -158,7 +157,6 @@ void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r } real_t AABB::get_longest_axis_size() const { - real_t max_size = size.x; if (size.y > max_size) { @@ -173,7 +171,6 @@ real_t AABB::get_longest_axis_size() const { } real_t AABB::get_shortest_axis_size() const { - real_t max_size = size.x; if (size.y < max_size) { @@ -188,7 +185,6 @@ real_t AABB::get_shortest_axis_size() const { } bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t0, real_t t1) const { - real_t divx = 1.0 / dir.x; real_t divy = 1.0 / dir.y; real_t divz = 1.0 / dir.z; @@ -232,7 +228,6 @@ bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t } void AABB::grow_by(real_t p_amount) { - position.x -= p_amount; position.y -= p_amount; position.z -= p_amount; @@ -242,21 +237,17 @@ void AABB::grow_by(real_t p_amount) { } real_t AABB::get_area() const { - return size.x * size.y * size.z; } bool AABB::operator==(const AABB &p_rval) const { - return ((position == p_rval.position) && (size == p_rval.size)); } bool AABB::operator!=(const AABB &p_rval) const { - return ((position != p_rval.position) || (size != p_rval.size)); } void AABB::merge_with(const AABB &p_aabb) { - Vector3 beg_1, beg_2; Vector3 end_1, end_2; Vector3 min, max; @@ -279,7 +270,6 @@ void AABB::merge_with(const AABB &p_aabb) { } AABB AABB::intersection(const AABB &p_aabb) const { - Vector3 src_min = position; Vector3 src_max = position + size; Vector3 dst_min = p_aabb.position; @@ -290,7 +280,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { if (src_min.x > dst_max.x || src_max.x < dst_min.x) return AABB(); else { - min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x; max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x; } @@ -298,7 +287,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { if (src_min.y > dst_max.y || src_max.y < dst_min.y) return AABB(); else { - min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y; max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y; } @@ -306,7 +294,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { if (src_min.z > dst_max.z || src_max.z < dst_min.z) return AABB(); else { - min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z; max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z; } @@ -315,7 +302,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { } bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const { - Vector3 c1, c2; Vector3 end = position + size; real_t near = -1e20; @@ -358,7 +344,6 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 * } bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip, Vector3 *r_normal) const { - real_t min = 0, max = 1; int axis = 0; real_t sign = 0; @@ -372,7 +357,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector real_t csign; if (seg_from < seg_to) { - if (seg_from > box_end || seg_to < box_begin) return false; real_t length = seg_to - seg_from; @@ -381,7 +365,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector csign = -1.0; } else { - if (seg_to > box_end || seg_from < box_begin) return false; real_t length = seg_to - seg_from; @@ -416,7 +399,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector } bool AABB::intersects_plane(const Plane &p_plane) const { - Vector3 points[8] = { Vector3(position.x, position.y, position.z), Vector3(position.x, position.y, position.z + size.z), @@ -432,7 +414,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const { bool under = false; for (int i = 0; i < 8; i++) { - if (p_plane.distance_to(points[i]) > 0) over = true; else @@ -443,7 +424,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const { } Vector3 AABB::get_longest_axis() const { - Vector3 axis(1, 0, 0); real_t max_size = size.x; @@ -460,7 +440,6 @@ Vector3 AABB::get_longest_axis() const { return axis; } int AABB::get_longest_axis_index() const { - int axis = 0; real_t max_size = size.x; @@ -478,7 +457,6 @@ int AABB::get_longest_axis_index() const { } Vector3 AABB::get_shortest_axis() const { - Vector3 axis(1, 0, 0); real_t max_size = size.x; @@ -495,7 +473,6 @@ Vector3 AABB::get_shortest_axis() const { return axis; } int AABB::get_shortest_axis_index() const { - int axis = 0; real_t max_size = size.x; @@ -513,7 +490,6 @@ int AABB::get_shortest_axis_index() const { } AABB AABB::merge(const AABB &p_with) const { - AABB aabb = *this; aabb.merge_with(p_with); return aabb; @@ -524,24 +500,19 @@ AABB AABB::expand(const Vector3 &p_vector) const { return aabb; } AABB AABB::grow(real_t p_by) const { - AABB aabb = *this; aabb.grow_by(p_by); return aabb; } void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { - ERR_FAIL_INDEX(p_edge, 12); switch (p_edge) { - case 0: { - r_from = Vector3(position.x + size.x, position.y, position.z); r_to = Vector3(position.x, position.y, position.z); } break; case 1: { - r_from = Vector3(position.x + size.x, position.y, position.z + size.z); r_to = Vector3(position.x + size.x, position.y, position.z); } break; @@ -551,18 +522,15 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } break; case 3: { - r_from = Vector3(position.x, position.y, position.z); r_to = Vector3(position.x, position.y, position.z + size.z); } break; case 4: { - r_from = Vector3(position.x, position.y + size.y, position.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z); } break; case 5: { - r_from = Vector3(position.x + size.x, position.y + size.y, position.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z); } break; @@ -572,31 +540,26 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } break; case 7: { - r_from = Vector3(position.x, position.y + size.y, position.z + size.z); r_to = Vector3(position.x, position.y + size.y, position.z); } break; case 8: { - r_from = Vector3(position.x, position.y, position.z + size.z); r_to = Vector3(position.x, position.y + size.y, position.z + size.z); } break; case 9: { - r_from = Vector3(position.x, position.y, position.z); r_to = Vector3(position.x, position.y + size.y, position.z); } break; case 10: { - r_from = Vector3(position.x + size.x, position.y, position.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z); } break; case 11: { - r_from = Vector3(position.x + size.x, position.y, position.z + size.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z); @@ -605,7 +568,6 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } AABB::operator String() const { - return String() + position + " - " + size; } diff --git a/src/core/Basis.cpp b/src/core/Basis.cpp index 903566c..92d2dbe 100644 --- a/src/core/Basis.cpp +++ b/src/core/Basis.cpp @@ -19,12 +19,10 @@ Basis::Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) { } Basis::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); } Basis::Basis() { - elements[0][0] = 1; elements[0][1] = 0; elements[0][2] = 0; @@ -58,7 +56,6 @@ void Basis::invert() { #undef cofac bool Basis::isequal_approx(const Basis &a, const Basis &b) const { - for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if ((::fabs(a.elements[i][j] - b.elements[i][j]) < CMP_EPSILON) == false) @@ -174,7 +171,6 @@ Basis Basis::slerp(Basis b, float t) const { // the angles in the decomposition R = X(a1).Y(a2).Z(a3) where Z(a) rotates // around the z-axis by a and so on. Vector3 Basis::get_euler_xyz() const { - // Euler angles in XYZ convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -218,7 +214,6 @@ Vector3 Basis::get_euler_xyz() const { // and similar for other axes. // The current implementation uses XYZ convention (Z is the first rotation). void Basis::set_euler_xyz(const Vector3 &p_euler) { - real_t c, s; c = ::cos(p_euler.x); @@ -241,7 +236,6 @@ void Basis::set_euler_xyz(const Vector3 &p_euler) { // as in first-Z, then-X, last-Y. The angles for X, Y, and Z rotations are returned // as the x, y, and z components of a Vector3 respectively. Vector3 Basis::get_euler_yxz() const { - // Euler angles in YXZ convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -287,7 +281,6 @@ Vector3 Basis::get_euler_yxz() const { // and similar for other axes. // The current implementation uses YXZ convention (Z is the first rotation). void Basis::set_euler_yxz(const Vector3 &p_euler) { - real_t c, s; c = ::cos(p_euler.x); @@ -333,7 +326,6 @@ bool Basis::operator!=(const Basis &p_matrix) const { } Vector3 Basis::xform(const Vector3 &p_vector) const { - return Vector3( elements[0].dot(p_vector), elements[1].dot(p_vector), @@ -341,7 +333,6 @@ Vector3 Basis::xform(const Vector3 &p_vector) const { } 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), @@ -362,42 +353,36 @@ Basis Basis::operator*(const Basis &p_matrix) const { } 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]; } Basis Basis::operator+(const Basis &p_matrix) const { - Basis ret(*this); ret += p_matrix; return ret; } 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]; } Basis Basis::operator-(const Basis &p_matrix) const { - Basis ret(*this); ret -= p_matrix; return ret; } void Basis::operator*=(real_t p_val) { - elements[0] *= p_val; elements[1] *= p_val; elements[2] *= p_val; } Basis Basis::operator*(real_t p_val) const { - Basis ret(*this); ret *= p_val; return ret; @@ -406,9 +391,7 @@ Basis Basis::operator*(real_t p_val) const { Basis::operator String() const { String s; for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - if (i != 0 || j != 0) s += ", "; @@ -421,7 +404,6 @@ Basis::operator String() const { /* create / set */ void Basis::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; @@ -433,12 +415,10 @@ void Basis::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz elements[2][2] = zz; } Vector3 Basis::get_column(int i) const { - return Vector3(elements[0][i], elements[1][i], elements[2][i]); } Vector3 Basis::get_row(int i) const { - return Vector3(elements[i][0], elements[i][1], elements[i][2]); } Vector3 Basis::get_main_diagonal() const { @@ -593,7 +573,6 @@ int Basis::get_orthogonal_index() const { Basis orth = *this; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - real_t v = orth[i][j]; if (v > 0.5) v = 1.0; @@ -607,7 +586,6 @@ int Basis::get_orthogonal_index() const { } for (int i = 0; i < 24; i++) { - if (_ortho_bases[i] == orth) return i; } @@ -616,7 +594,6 @@ int Basis::get_orthogonal_index() const { } void Basis::set_orthogonal_index(int p_index) { - //there only exist 24 orthogonal bases in r3 ERR_FAIL_COND(p_index >= 24); @@ -624,7 +601,6 @@ void Basis::set_orthogonal_index(int p_index) { } Basis::Basis(const Vector3 &p_euler) { - set_euler(p_euler); } @@ -635,7 +611,6 @@ Basis::Basis(const Vector3 &p_euler) { namespace godot { Basis::Basis(const Quat &p_quat) { - real_t d = p_quat.length_squared(); real_t s = 2.0 / d; real_t xs = p_quat.x * s, ys = p_quat.y * s, zs = p_quat.z * s; @@ -685,8 +660,8 @@ Basis::operator Quat() const { temp[2] = ((elements[1][0] - elements[0][1]) * s); } else { int i = elements[0][0] < elements[1][1] ? - (elements[1][1] < elements[2][2] ? 2 : 1) : - (elements[0][0] < elements[2][2] ? 2 : 0); + (elements[1][1] < elements[2][2] ? 2 : 1) : + (elements[0][0] < elements[2][2] ? 2 : 0); int j = (i + 1) % 3; int k = (i + 2) % 3; diff --git a/src/core/CameraMatrix.cpp b/src/core/CameraMatrix.cpp index b1b7f20..9f4c72a 100644 --- a/src/core/CameraMatrix.cpp +++ b/src/core/CameraMatrix.cpp @@ -31,29 +31,22 @@ #include "CameraMatrix.hpp" void CameraMatrix::set_identity() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - matrix[i][j] = (i == j) ? 1 : 0; } } } void CameraMatrix::set_zero() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - matrix[i][j] = 0; } } } Plane CameraMatrix::xform4(const Plane &p_vec4) const { - Plane ret; ret.normal.x = matrix[0][0] * p_vec4.normal.x + matrix[1][0] * p_vec4.normal.y + matrix[2][0] * p_vec4.normal.z + matrix[3][0] * p_vec4.d; @@ -64,7 +57,6 @@ Plane CameraMatrix::xform4(const Plane &p_vec4) const { } void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) { - if (p_flip_fov) { p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect); } @@ -157,7 +149,6 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_ }; void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) { - set_identity(); matrix[0][0] = 2.0 / (p_right - p_left); @@ -170,7 +161,6 @@ void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom } void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) { - if (!p_flip_fov) { p_size *= p_aspect; } @@ -179,7 +169,6 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear } void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) { - ERR_FAIL_COND(p_right <= p_left); ERR_FAIL_COND(p_top <= p_bottom); ERR_FAIL_COND(p_far <= p_near); @@ -220,7 +209,6 @@ void CameraMatrix::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, } real_t CameraMatrix::get_z_far() const { - const real_t *matrix = (const real_t *)this->matrix; Plane new_plane = Plane(matrix[3] - matrix[2], matrix[7] - matrix[6], @@ -233,7 +221,6 @@ real_t CameraMatrix::get_z_far() const { return new_plane.d; } real_t CameraMatrix::get_z_near() const { - const real_t *matrix = (const real_t *)this->matrix; Plane new_plane = Plane(matrix[3] + matrix[2], matrix[7] + matrix[6], @@ -245,7 +232,6 @@ real_t CameraMatrix::get_z_near() const { } Vector2 CameraMatrix::get_viewport_half_extents() const { - const real_t *matrix = (const real_t *)this->matrix; ///////--- Near Plane ---/////// Plane near_plane = Plane(matrix[3] + matrix[2], @@ -274,7 +260,6 @@ Vector2 CameraMatrix::get_viewport_half_extents() const { } bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const { - std::vector<Plane> planes = get_projection_planes(Transform()); const Planes intersections[8][3] = { { PLANE_FAR, PLANE_LEFT, PLANE_TOP }, @@ -288,7 +273,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point }; for (int i = 0; i < 8; i++) { - Vector3 point; bool res = planes[intersections[i][0]].intersect_3(planes[intersections[i][1]], planes[intersections[i][2]], &point); ERR_FAIL_COND_V(!res, false); @@ -299,7 +283,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point } std::vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform) const { - /** Fast Plane Extraction from combined modelview/projection matrices. * References: * https://web.archive.org/web/20011221205252/http://www.markmorley.com/opengl/frustumculling.html @@ -382,14 +365,12 @@ std::vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transf } CameraMatrix CameraMatrix::inverse() const { - CameraMatrix cm = *this; cm.invert(); return cm; } void CameraMatrix::invert() { - int i, j, k; int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */ real_t pvt_val; /* Value of current pivot element */ @@ -440,20 +421,23 @@ void CameraMatrix::invert() { /** Divide column by minus pivot value **/ for (i = 0; i < 4; i++) { - if (i != k) matrix[i][k] /= (-pvt_val); + if (i != k) + matrix[i][k] /= (-pvt_val); } /** Reduce the matrix **/ for (i = 0; i < 4; i++) { hold = matrix[i][k]; for (j = 0; j < 4; j++) { - if (i != k && j != k) matrix[i][j] += hold * matrix[k][j]; + if (i != k && j != k) + matrix[i][j] += hold * matrix[k][j]; } } /** Divide row by pivot **/ for (j = 0; j < 4; j++) { - if (j != k) matrix[k][j] /= pvt_val; + if (j != k) + matrix[k][j] /= pvt_val; } /** Replace pivot by reciprocal (at last we can touch it). **/ @@ -483,12 +467,10 @@ void CameraMatrix::invert() { } CameraMatrix::CameraMatrix() { - set_identity(); } CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const { - CameraMatrix new_matrix; for (int j = 0; j < 4; j++) { @@ -504,7 +486,6 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const { } void CameraMatrix::set_light_bias() { - real_t *m = &matrix[0][0]; m[0] = 0.5; @@ -526,7 +507,6 @@ void CameraMatrix::set_light_bias() { } void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) { - real_t *m = &matrix[0][0]; m[0] = p_rect.size.width; @@ -548,7 +528,6 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) { } CameraMatrix::operator String() const { - String str; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) @@ -558,20 +537,17 @@ CameraMatrix::operator String() const { } real_t CameraMatrix::get_aspect() const { - Vector2 vp_he = get_viewport_half_extents(); return vp_he.x / vp_he.y; } int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const { - Vector3 result = xform(Vector3(1, 0, -1)); return int((result.x * 0.5 + 0.5) * p_for_pixel_width); } bool CameraMatrix::is_orthogonal() const { - return matrix[3][3] == 1.0; } @@ -599,7 +575,6 @@ real_t CameraMatrix::get_fov() const { } void CameraMatrix::make_scale(const Vector3 &p_scale) { - set_identity(); matrix[0][0] = p_scale.x; matrix[1][1] = p_scale.y; @@ -607,7 +582,6 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) { } void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) { - Vector3 min = p_aabb.position; Vector3 max = p_aabb.position + p_aabb.size; @@ -633,7 +607,6 @@ void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) { } CameraMatrix::operator Transform() const { - Transform tr; const real_t *m = &matrix[0][0]; @@ -657,7 +630,6 @@ CameraMatrix::operator Transform() const { } CameraMatrix::CameraMatrix(const Transform &p_transform) { - const Transform &tr = p_transform; real_t *m = &matrix[0][0]; diff --git a/src/core/Color.cpp b/src/core/Color.cpp index 23b77eb..16e4008 100644 --- a/src/core/Color.cpp +++ b/src/core/Color.cpp @@ -13,11 +13,9 @@ namespace godot { static String _to_hex(float p_val); static float _parse_col(const String &p_str, int p_ofs) { - int ig = 0; for (int i = 0; i < 2; i++) { - int c = (int)(wchar_t)p_str[i + p_ofs]; int v = 0; @@ -43,7 +41,6 @@ static float _parse_col(const String &p_str, int p_ofs) { } uint32_t Color::to_32() const { - uint32_t c = (uint8_t)(a * 255); c <<= 8; c |= (uint8_t)(r * 255); @@ -148,7 +145,6 @@ uint8_t Color::get_a8() const { } float Color::get_h() const { - float min = MIN(r, g); min = MIN(min, b); float max = MAX(r, g); @@ -334,7 +330,6 @@ Color Color::contrasted() const { } Color Color::linear_interpolate(const Color &p_b, float p_t) const { - Color res = *this; res.r += (p_t * (p_b.r - r)); @@ -346,7 +341,6 @@ Color Color::linear_interpolate(const Color &p_b, float p_t) const { } Color Color::blend(const Color &p_over) const { - Color res; float sa = 1.0 - p_over.a; res.a = a * sa + p_over.a; @@ -361,7 +355,6 @@ Color Color::blend(const Color &p_over) const { } Color Color::to_linear() const { - return Color( r < 0.04045 ? r * (1.0 / 12.92) : ::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4), g < 0.04045 ? g * (1.0 / 12.92) : ::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4), @@ -477,13 +470,11 @@ bool Color::html_is_valid(const String &p_color) { #define CLAMP(m_a, m_min, m_max) (((m_a) < (m_min)) ? (m_min) : (((m_a) > (m_max)) ? m_max : m_a)) #endif static String _to_hex(float p_val) { - int v = p_val * 255; v = CLAMP(v, 0, 255); String ret; for (int i = 0; i < 2; i++) { - wchar_t c[2] = { 0, 0 }; int lv = v & 0xF; if (lv < 10) @@ -514,7 +505,6 @@ Color::operator String() const { } bool Color::operator<(const Color &p_color) const { - if (r == p_color.r) { if (g == p_color.g) { if (b == p_color.b) { @@ -528,7 +518,6 @@ bool Color::operator<(const Color &p_color) const { } Color Color::operator+(const Color &p_color) const { - return Color( r + p_color.r, g + p_color.g, @@ -537,7 +526,6 @@ Color Color::operator+(const Color &p_color) const { } void Color::operator+=(const Color &p_color) { - r = r + p_color.r; g = g + p_color.g; b = b + p_color.b; @@ -545,7 +533,6 @@ void Color::operator+=(const Color &p_color) { } Color Color::operator-(const Color &p_color) const { - return Color( r - p_color.r, g - p_color.g, @@ -554,7 +541,6 @@ Color Color::operator-(const Color &p_color) const { } void Color::operator-=(const Color &p_color) { - r = r - p_color.r; g = g - p_color.g; b = b - p_color.b; @@ -562,7 +548,6 @@ void Color::operator-=(const Color &p_color) { } Color Color::operator*(const Color &p_color) const { - return Color( r * p_color.r, g * p_color.g, @@ -571,7 +556,6 @@ Color Color::operator*(const Color &p_color) const { } Color Color::operator*(const real_t &rvalue) const { - return Color( r * rvalue, g * rvalue, @@ -580,7 +564,6 @@ Color Color::operator*(const real_t &rvalue) const { } void Color::operator*=(const Color &p_color) { - r = r * p_color.r; g = g * p_color.g; b = b * p_color.b; @@ -588,7 +571,6 @@ void Color::operator*=(const Color &p_color) { } void Color::operator*=(const real_t &rvalue) { - r = r * rvalue; g = g * rvalue; b = b * rvalue; @@ -596,7 +578,6 @@ void Color::operator*=(const real_t &rvalue) { } Color Color::operator/(const Color &p_color) const { - return Color( r / p_color.r, g / p_color.g, @@ -605,7 +586,6 @@ Color Color::operator/(const Color &p_color) const { } Color Color::operator/(const real_t &rvalue) const { - return Color( r / rvalue, g / rvalue, @@ -614,7 +594,6 @@ Color Color::operator/(const real_t &rvalue) const { } void Color::operator/=(const Color &p_color) { - r = r / p_color.r; g = g / p_color.g; b = b / p_color.b; @@ -622,7 +601,6 @@ void Color::operator/=(const Color &p_color) { } void Color::operator/=(const real_t &rvalue) { - if (rvalue == 0) { r = 1.0; g = 1.0; @@ -637,7 +615,6 @@ void Color::operator/=(const real_t &rvalue) { } Color Color::operator-() const { - return Color( 1.0 - r, 1.0 - g, diff --git a/src/core/GodotGlobal.cpp b/src/core/GodotGlobal.cpp index c7cae20..a73a064 100644 --- a/src/core/GodotGlobal.cpp +++ b/src/core/GodotGlobal.cpp @@ -55,9 +55,12 @@ void Godot::print_warning(const String &description, const String &function, con godot::api->godot_print_warning(c_desc, c_func, c_file, line); }; - if (c_desc != nullptr) godot::api->godot_free(c_desc); - if (c_func != nullptr) godot::api->godot_free(c_func); - if (c_file != nullptr) godot::api->godot_free(c_file); + if (c_desc != nullptr) + godot::api->godot_free(c_desc); + if (c_func != nullptr) + godot::api->godot_free(c_func); + if (c_file != nullptr) + godot::api->godot_free(c_file); } void Godot::print_error(const String &description, const String &function, const String &file, int line) { @@ -71,9 +74,12 @@ void Godot::print_error(const String &description, const String &function, const godot::api->godot_print_error(c_desc, c_func, c_file, line); }; - if (c_desc != nullptr) godot::api->godot_free(c_desc); - if (c_func != nullptr) godot::api->godot_free(c_func); - if (c_file != nullptr) godot::api->godot_free(c_file); + if (c_desc != nullptr) + godot::api->godot_free(c_desc); + if (c_func != nullptr) + godot::api->godot_free(c_func); + if (c_file != nullptr) + godot::api->godot_free(c_file); } void ___register_types(); @@ -136,7 +142,8 @@ void Godot::gdnative_init(godot_gdnative_init_options *options) { } } break; - default: break; + default: + break; } } diff --git a/src/core/Plane.cpp b/src/core/Plane.cpp index 8e5e30b..0291335 100644 --- a/src/core/Plane.cpp +++ b/src/core/Plane.cpp @@ -10,12 +10,10 @@ void Plane::set_normal(const Vector3 &p_normal) { } Vector3 Plane::project(const Vector3 &p_point) const { - return p_point - normal * distance_to(p_point); } void Plane::normalize() { - real_t l = normal.length(); if (l == 0) { *this = Plane(0, 0, 0, 0); @@ -26,19 +24,16 @@ void Plane::normalize() { } Plane Plane::normalized() const { - Plane p = *this; p.normalize(); return p; } Vector3 Plane::get_any_point() const { - return get_normal() * d; } Vector3 Plane::get_any_perpendicular_normal() const { - static const Vector3 p1 = Vector3(1, 0, 0); static const Vector3 p2 = Vector3(0, 1, 0); Vector3 p; @@ -57,7 +52,6 @@ Vector3 Plane::get_any_perpendicular_normal() const { /* intersections */ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result) const { - const Plane &p_plane0 = *this; Vector3 normal0 = p_plane0.normal; Vector3 normal1 = p_plane1.normal; @@ -79,13 +73,11 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r } bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const { - Vector3 segment = p_dir; real_t den = normal.dot(segment); //printf("den is %i\n",den); if (::fabs(den) <= CMP_EPSILON) { - return false; } @@ -104,13 +96,11 @@ bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersectio } bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const { - Vector3 segment = p_begin - p_end; real_t den = normal.dot(segment); //printf("den is %i\n",den); if (::fabs(den) <= CMP_EPSILON) { - return false; } @@ -118,7 +108,6 @@ bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_inters //printf("dist is %i\n",dist); if (dist < -CMP_EPSILON || dist > (1.0 + CMP_EPSILON)) { - return false; } @@ -131,47 +120,39 @@ bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_inters /* misc */ bool Plane::is_almost_like(const Plane &p_plane) const { - return (normal.dot(p_plane.normal) > _PLANE_EQ_DOT_EPSILON && ::fabs(d - p_plane.d) < _PLANE_EQ_D_EPSILON); } Plane::operator String() const { - // return normal.operator String() + ", " + rtos(d); return String(); // @Todo } bool Plane::is_point_over(const Vector3 &p_point) const { - return (normal.dot(p_point) > d); } real_t Plane::distance_to(const Vector3 &p_point) const { - return (normal.dot(p_point) - d); } bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const { - real_t dist = normal.dot(p_point) - d; dist = ::fabs(dist); return (dist <= _epsilon); } Plane::Plane(const Vector3 &p_normal, real_t p_d) { - normal = p_normal; d = p_d; } Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) { - normal = p_normal; d = p_normal.dot(p_point); } Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir) { - if (p_dir == CLOCKWISE) normal = (p_point1 - p_point3).cross(p_point1 - p_point2); else @@ -182,12 +163,10 @@ Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_ } bool Plane::operator==(const Plane &p_plane) const { - return normal == p_plane.normal && d == p_plane.d; } bool Plane::operator!=(const Plane &p_plane) const { - return normal != p_plane.normal || d != p_plane.d; } diff --git a/src/core/Quat.cpp b/src/core/Quat.cpp index dc179e2..9e3cfe7 100644 --- a/src/core/Quat.cpp +++ b/src/core/Quat.cpp @@ -100,7 +100,6 @@ Quat Quat::inverse() const { } Quat Quat::slerp(const Quat &q, const real_t &t) const { - Quat to1; real_t omega, cosom, sinom, scale0, scale1; @@ -144,12 +143,12 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const { } Quat Quat::slerpni(const Quat &q, const real_t &t) const { - const Quat &from = *this; real_t dot = from.dot(q); - if (::fabs(dot) > 0.9999) return from; + if (::fabs(dot) > 0.9999) + return from; real_t theta = ::acos(dot), sinT = 1.0 / ::sin(theta), @@ -200,7 +199,6 @@ Quat Quat::operator*(const Vector3 &v) const { } Vector3 Quat::xform(const Vector3 &v) const { - Quat q = *this * v; q *= this->inverse(); return Vector3(q.x, q.y, q.z); @@ -234,7 +232,6 @@ Quat::Quat(const Vector3 &v0, const Vector3 &v1) // shortest arc z = 0; w = 0; } else { - real_t s = ::sqrt((1.0 + d) * 2.0); real_t rs = 1.0 / s; @@ -282,7 +279,6 @@ void Quat::operator*=(const real_t &s) { } void Quat::operator/=(const real_t &s) { - *this *= 1.0 / s; } diff --git a/src/core/Rect2.cpp b/src/core/Rect2.cpp index a041d30..b49d991 100644 --- a/src/core/Rect2.cpp +++ b/src/core/Rect2.cpp @@ -16,7 +16,6 @@ namespace godot { #endif real_t Rect2::distance_to(const Vector2 &p_point) const { - real_t dist = 1e20; if (p_point.x < position.x) { @@ -77,7 +76,6 @@ Rect2::operator String() const { } bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_position, Point2 *r_normal) const { - real_t min = 0, max = 1; int axis = 0; real_t sign = 0; @@ -91,7 +89,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 real_t csign; if (seg_from < seg_to) { - if (seg_from > box_end || seg_to < box_begin) return false; real_t length = seg_to - seg_from; @@ -100,7 +97,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 csign = -1.0; } else { - if (seg_to > box_end || seg_from < box_begin) return false; real_t length = seg_to - seg_from; @@ -135,7 +131,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 } bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const { - //SAT intersection between local and transformed rect2 Vector2 xf_points[4] = { diff --git a/src/core/String.cpp b/src/core/String.cpp index 9db8462..c1efee5 100644 --- a/src/core/String.cpp +++ b/src/core/String.cpp @@ -141,7 +141,6 @@ const wchar_t *String::unicode_str() const { } char *String::alloc_c_string() const { - godot_char_string contents = godot::api->godot_string_utf8(&_godot_string); int length = godot::api->godot_char_string_length(&contents); @@ -166,7 +165,6 @@ CharString String::utf8() const { } CharString String::ascii(bool p_extended) const { - CharString ret; if (p_extended) diff --git a/src/core/TagDB.cpp b/src/core/TagDB.cpp index 8c0b717..e2afe66 100644 --- a/src/core/TagDB.cpp +++ b/src/core/TagDB.cpp @@ -22,14 +22,12 @@ bool is_type_known(size_t type_tag) { } void register_global_type(const char *name, size_t type_tag, size_t base_type_tag) { - godot::nativescript_1_1_api->godot_nativescript_set_global_type_tag(godot::_RegisterState::language_index, name, (const void *)type_tag); register_type(type_tag, base_type_tag); } bool is_type_compatible(size_t ask_tag, size_t have_tag) { - if (have_tag == 0) return false; diff --git a/src/core/Transform.cpp b/src/core/Transform.cpp index 1eca983..8ce7ceb 100644 --- a/src/core/Transform.cpp +++ b/src/core/Transform.cpp @@ -15,14 +15,12 @@ const Transform Transform::FLIP_Y = Transform(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, const Transform Transform::FLIP_Z = Transform(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0); Transform Transform::inverse_xform(const Transform &t) const { - Vector3 v = t.origin - origin; return Transform(basis.transpose_xform(t.basis), basis.xform(v)); } void Transform::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, real_t tx, real_t ty, real_t tz) { - basis.elements[0][0] = xx; basis.elements[0][1] = xy; basis.elements[0][2] = xz; @@ -38,14 +36,12 @@ void Transform::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_ } Vector3 Transform::xform(const Vector3 &p_vector) const { - return Vector3( basis.elements[0].dot(p_vector) + origin.x, basis.elements[1].dot(p_vector) + origin.y, basis.elements[2].dot(p_vector) + origin.z); } Vector3 Transform::xform_inv(const Vector3 &p_vector) const { - Vector3 v = p_vector - origin; return Vector3( @@ -55,7 +51,6 @@ Vector3 Transform::xform_inv(const Vector3 &p_vector) const { } Plane Transform::xform(const Plane &p_plane) const { - Vector3 point = p_plane.normal * p_plane.d; Vector3 point_dir = point + p_plane.normal; point = xform(point); @@ -68,7 +63,6 @@ Plane Transform::xform(const Plane &p_plane) const { return Plane(normal, d); } Plane Transform::xform_inv(const Plane &p_plane) const { - Vector3 point = p_plane.normal * p_plane.d; Vector3 point_dir = point + p_plane.normal; point = xform_inv(point); @@ -100,7 +94,6 @@ AABB Transform::xform(const AABB &p_aabb) const { return new_aabb; } AABB Transform::xform_inv(const AABB &p_aabb) const { - /* define vertices */ Vector3 vertices[8] = { Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z), @@ -118,7 +111,6 @@ AABB Transform::xform_inv(const AABB &p_aabb) const { ret.position = xform_inv(vertices[0]); for (int i = 1; i < 8; i++) { - ret.expand_to(xform_inv(vertices[i])); } @@ -126,20 +118,17 @@ AABB Transform::xform_inv(const AABB &p_aabb) const { } void Transform::affine_invert() { - basis.invert(); origin = basis.xform(-origin); } Transform Transform::affine_inverse() const { - Transform ret = *this; ret.affine_invert(); return ret; } void Transform::invert() { - basis.transpose(); origin = basis.xform(-origin); } @@ -153,29 +142,24 @@ Transform Transform::inverse() const { } void Transform::rotate(const Vector3 &p_axis, real_t p_phi) { - *this = rotated(p_axis, p_phi); } Transform Transform::rotated(const Vector3 &p_axis, real_t p_phi) const { - return Transform(Basis(p_axis, p_phi), Vector3()) * (*this); } void Transform::rotate_basis(const Vector3 &p_axis, real_t p_phi) { - basis.rotate(p_axis, p_phi); } Transform Transform::looking_at(const Vector3 &p_target, const Vector3 &p_up) const { - Transform t = *this; t.set_look_at(origin, p_target, p_up); return t; } void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up) { - // Reference: MESA source code Vector3 v_x, v_y, v_z; @@ -203,7 +187,6 @@ void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const } Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) const { - /* not sure if very "efficient" but good enough? */ Vector3 src_scale = basis.get_scale(); @@ -223,20 +206,17 @@ Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) } void Transform::scale(const Vector3 &p_scale) { - basis.scale(p_scale); origin *= p_scale; } Transform Transform::scaled(const Vector3 &p_scale) const { - Transform t = *this; t.scale(p_scale); return t; } void Transform::scale_basis(const Vector3 &p_scale) { - basis.scale(p_scale); } @@ -244,60 +224,50 @@ void Transform::translate(real_t p_tx, real_t p_ty, real_t p_tz) { translate(Vector3(p_tx, p_ty, p_tz)); } void Transform::translate(const Vector3 &p_translation) { - for (int i = 0; i < 3; i++) { origin[i] += basis.elements[i].dot(p_translation); } } Transform Transform::translated(const Vector3 &p_translation) const { - Transform t = *this; t.translate(p_translation); return t; } void Transform::orthonormalize() { - basis.orthonormalize(); } Transform Transform::orthonormalized() const { - Transform _copy = *this; _copy.orthonormalize(); return _copy; } bool Transform::operator==(const Transform &p_transform) const { - return (basis == p_transform.basis && origin == p_transform.origin); } bool Transform::operator!=(const Transform &p_transform) const { - return (basis != p_transform.basis || origin != p_transform.origin); } void Transform::operator*=(const Transform &p_transform) { - origin = xform(p_transform.origin); basis *= p_transform.basis; } Transform Transform::operator*(const Transform &p_transform) const { - Transform t = *this; t *= p_transform; return t; } Transform::operator String() const { - return basis.operator String() + " - " + origin.operator String(); } Transform::Transform(const Basis &p_basis, const Vector3 &p_origin) { - basis = p_basis; origin = p_origin; } diff --git a/src/core/Transform2D.cpp b/src/core/Transform2D.cpp index 6395c3d..ad4691b 100644 --- a/src/core/Transform2D.cpp +++ b/src/core/Transform2D.cpp @@ -12,7 +12,6 @@ const Transform2D Transform2D::FLIP_X = Transform2D(-1, 0, 0, 1, 0, 0); const Transform2D Transform2D::FLIP_Y = Transform2D(1, 0, 0, -1, 0, 0); Transform2D::Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) { - elements[0][0] = xx; elements[0][1] = xy; elements[1][0] = yx; @@ -22,28 +21,24 @@ Transform2D::Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, } Vector2 Transform2D::basis_xform(const Vector2 &v) const { - return Vector2( tdotx(v), tdoty(v)); } Vector2 Transform2D::basis_xform_inv(const Vector2 &v) const { - return Vector2( elements[0].dot(v), elements[1].dot(v)); } Vector2 Transform2D::xform(const Vector2 &v) const { - return Vector2( tdotx(v), tdoty(v)) + elements[2]; } Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { - Vector2 v = p_vec - elements[2]; return Vector2( @@ -51,7 +46,6 @@ Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { elements[1].dot(v)); } Rect2 Transform2D::xform(const Rect2 &p_rect) const { - Vector2 x = elements[0] * p_rect.size.x; Vector2 y = elements[1] * p_rect.size.y; Vector2 position = xform(p_rect.position); @@ -65,7 +59,6 @@ Rect2 Transform2D::xform(const Rect2 &p_rect) const { } void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) { - elements[0][0] = ::cos(p_rot) * p_scale.x; elements[1][1] = ::cos(p_rot) * p_scale.y; elements[1][0] = -::sin(p_rot) * p_scale.y; @@ -73,7 +66,6 @@ void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) { } Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const { - Vector2 ends[4] = { xform_inv(p_rect.position), xform_inv(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)), @@ -98,14 +90,12 @@ void Transform2D::invert() { } Transform2D Transform2D::inverse() const { - Transform2D inv = *this; inv.invert(); return inv; } void Transform2D::affine_invert() { - real_t det = basis_determinant(); ERR_FAIL_COND(det == 0); real_t idet = 1.0 / det; @@ -118,7 +108,6 @@ void Transform2D::affine_invert() { } Transform2D Transform2D::affine_inverse() const { - Transform2D inv = *this; inv.affine_invert(); return inv; @@ -138,7 +127,6 @@ real_t Transform2D::get_rotation() const { } void Transform2D::set_rotation(real_t p_rot) { - real_t cr = ::cos(p_rot); real_t sr = ::sin(p_rot); elements[0][0] = cr; @@ -148,7 +136,6 @@ void Transform2D::set_rotation(real_t p_rot) { } Transform2D::Transform2D(real_t p_rot, const Vector2 &p_position) { - real_t cr = ::cos(p_rot); real_t sr = ::sin(p_rot); elements[0][0] = cr; @@ -168,23 +155,19 @@ void Transform2D::scale(const Size2 &p_scale) { elements[2] *= p_scale; } void Transform2D::scale_basis(const Size2 &p_scale) { - elements[0][0] *= p_scale.x; elements[0][1] *= p_scale.y; elements[1][0] *= p_scale.x; elements[1][1] *= p_scale.y; } void Transform2D::translate(real_t p_tx, real_t p_ty) { - translate(Vector2(p_tx, p_ty)); } void Transform2D::translate(const Vector2 &p_translation) { - elements[2] += basis_xform(p_translation); } void Transform2D::orthonormalize() { - // Gram-Schmidt Process Vector2 x = elements[0]; @@ -198,14 +181,12 @@ void Transform2D::orthonormalize() { elements[1] = y; } Transform2D Transform2D::orthonormalized() const { - Transform2D on = *this; on.orthonormalize(); return on; } bool Transform2D::operator==(const Transform2D &p_transform) const { - for (int i = 0; i < 3; i++) { if (elements[i] != p_transform.elements[i]) return false; @@ -215,7 +196,6 @@ bool Transform2D::operator==(const Transform2D &p_transform) const { } bool Transform2D::operator!=(const Transform2D &p_transform) const { - for (int i = 0; i < 3; i++) { if (elements[i] != p_transform.elements[i]) return true; @@ -225,7 +205,6 @@ bool Transform2D::operator!=(const Transform2D &p_transform) const { } void Transform2D::operator*=(const Transform2D &p_transform) { - elements[2] = xform(p_transform.elements[2]); real_t x0, x1, y0, y1; @@ -242,54 +221,46 @@ void Transform2D::operator*=(const Transform2D &p_transform) { } Transform2D Transform2D::operator*(const Transform2D &p_transform) const { - Transform2D t = *this; t *= p_transform; return t; } Transform2D Transform2D::scaled(const Size2 &p_scale) const { - Transform2D copy = *this; copy.scale(p_scale); return copy; } Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const { - Transform2D copy = *this; copy.scale_basis(p_scale); return copy; } Transform2D Transform2D::untranslated() const { - Transform2D copy = *this; copy.elements[2] = Vector2(); return copy; } Transform2D Transform2D::translated(const Vector2 &p_offset) const { - Transform2D copy = *this; copy.translate(p_offset); return copy; } Transform2D Transform2D::rotated(real_t p_phi) const { - Transform2D copy = *this; copy.rotate(p_phi); return copy; } real_t Transform2D::basis_determinant() const { - return elements[0].x * elements[1].y - elements[0].y * elements[1].x; } Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t p_c) const { - //extract parameters Vector2 p1 = get_origin(); Vector2 p2 = p_transform.get_origin(); @@ -325,7 +296,6 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t } Transform2D::operator String() const { - return String(String() + elements[0] + ", " + elements[1] + ", " + elements[2]); } |