diff options
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/aabb.cpp | 1 | ||||
-rw-r--r-- | core/math/aabb.h | 2 | ||||
-rw-r--r-- | core/math/basis.cpp | 4 | ||||
-rw-r--r-- | core/math/color.h | 3 | ||||
-rw-r--r-- | core/math/expression.cpp | 54 | ||||
-rw-r--r-- | core/math/plane.cpp | 2 | ||||
-rw-r--r-- | core/math/projection.cpp | 17 | ||||
-rw-r--r-- | core/math/projection.h | 7 | ||||
-rw-r--r-- | core/math/quaternion.h | 4 | ||||
-rw-r--r-- | core/math/rect2.h | 2 | ||||
-rw-r--r-- | core/math/transform_3d.h | 1 | ||||
-rw-r--r-- | core/math/triangle_mesh.cpp | 18 | ||||
-rw-r--r-- | core/math/vector4.h | 6 |
13 files changed, 59 insertions, 62 deletions
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index 4c89be7f4d..483b0d10ec 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -403,6 +403,7 @@ Variant AABB::intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to } return Variant(); } + Variant AABB::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const { Vector3 inters; if (intersects_ray(p_from, p_dir, &inters)) { diff --git a/core/math/aabb.h b/core/math/aabb.h index acf903eeba..dfeb5b3291 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -101,7 +101,7 @@ struct _NO_DISCARD_ AABB { _FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */ _FORCE_INLINE_ AABB abs() const { - return AABB(Vector3(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0), position.z + MIN(size.z, 0)), size.abs()); + return AABB(Vector3(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0), position.z + MIN(size.z, (real_t)0)), size.abs()); } Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const; diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 4b163409ce..743a206ae7 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -142,8 +142,8 @@ bool Basis::is_symmetric() const { #endif Basis Basis::diagonalize() { -//NOTE: only implemented for symmetric matrices -//with the Jacobi iterative method +// NOTE: only implemented for symmetric matrices +// with the Jacobi iterative method #ifdef MATH_CHECKS ERR_FAIL_COND_V(!is_symmetric(), Basis()); #endif diff --git a/core/math/color.h b/core/math/color.h index 65036f74cc..bb8aa9a529 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -32,7 +32,8 @@ #define COLOR_H #include "core/math/math_funcs.h" -#include "core/string/ustring.h" + +class String; struct _NO_DISCARD_ Color { union { diff --git a/core/math/expression.cpp b/core/math/expression.cpp index e230b69dc9..dcec3929fe 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -560,7 +560,7 @@ const char *Expression::token_name[TK_MAX] = { }; Expression::ENode *Expression::_parse_expression() { - Vector<ExpressionNode> expression; + Vector<ExpressionNode> expression_nodes; while (true) { //keep appending stuff to expression @@ -838,14 +838,14 @@ Expression::ENode *Expression::_parse_expression() { ExpressionNode e; e.is_op = true; e.op = Variant::OP_NEGATE; - expression.push_back(e); + expression_nodes.push_back(e); continue; } break; case TK_OP_NOT: { ExpressionNode e; e.is_op = true; e.op = Variant::OP_NOT; - expression.push_back(e); + expression_nodes.push_back(e); continue; } break; @@ -960,7 +960,7 @@ Expression::ENode *Expression::_parse_expression() { ExpressionNode e; e.is_op = false; e.node = expr; - expression.push_back(e); + expression_nodes.push_back(e); } //ok finally look for an operator @@ -1054,19 +1054,19 @@ Expression::ENode *Expression::_parse_expression() { ExpressionNode e; e.is_op = true; e.op = op; - expression.push_back(e); + expression_nodes.push_back(e); } } /* Reduce the set of expressions and place them in an operator tree, respecting precedence */ - while (expression.size() > 1) { + while (expression_nodes.size() > 1) { int next_op = -1; int min_priority = 0xFFFFF; bool is_unary = false; - for (int i = 0; i < expression.size(); i++) { - if (!expression[i].is_op) { + for (int i = 0; i < expression_nodes.size(); i++) { + if (!expression_nodes[i].is_op) { continue; } @@ -1074,7 +1074,7 @@ Expression::ENode *Expression::_parse_expression() { bool unary = false; - switch (expression[i].op) { + switch (expression_nodes[i].op) { case Variant::OP_POWER: priority = 0; break; @@ -1130,7 +1130,7 @@ Expression::ENode *Expression::_parse_expression() { priority = 14; break; default: { - _set_error("Parser bug, invalid operator in expression: " + itos(expression[i].op)); + _set_error("Parser bug, invalid operator in expression: " + itos(expression_nodes[i].op)); return nullptr; } } @@ -1153,9 +1153,9 @@ Expression::ENode *Expression::_parse_expression() { // OK! create operator.. if (is_unary) { int expr_pos = next_op; - while (expression[expr_pos].is_op) { + while (expression_nodes[expr_pos].is_op) { expr_pos++; - if (expr_pos == expression.size()) { + if (expr_pos == expression_nodes.size()) { //can happen.. _set_error("Unexpected end of expression..."); return nullptr; @@ -1165,29 +1165,29 @@ Expression::ENode *Expression::_parse_expression() { //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { OperatorNode *op = alloc_node<OperatorNode>(); - op->op = expression[i].op; - op->nodes[0] = expression[i + 1].node; + op->op = expression_nodes[i].op; + op->nodes[0] = expression_nodes[i + 1].node; op->nodes[1] = nullptr; - expression.write[i].is_op = false; - expression.write[i].node = op; - expression.remove_at(i + 1); + expression_nodes.write[i].is_op = false; + expression_nodes.write[i].node = op; + expression_nodes.remove_at(i + 1); } } else { - if (next_op < 1 || next_op >= (expression.size() - 1)) { + if (next_op < 1 || next_op >= (expression_nodes.size() - 1)) { _set_error("Parser bug..."); ERR_FAIL_V(nullptr); } OperatorNode *op = alloc_node<OperatorNode>(); - op->op = expression[next_op].op; + op->op = expression_nodes[next_op].op; - if (expression[next_op - 1].is_op) { + if (expression_nodes[next_op - 1].is_op) { _set_error("Parser bug..."); ERR_FAIL_V(nullptr); } - if (expression[next_op + 1].is_op) { + if (expression_nodes[next_op + 1].is_op) { // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by a unary op in a valid combination, @@ -1197,17 +1197,17 @@ Expression::ENode *Expression::_parse_expression() { return nullptr; } - op->nodes[0] = expression[next_op - 1].node; //expression goes as left - op->nodes[1] = expression[next_op + 1].node; //next expression goes as right + op->nodes[0] = expression_nodes[next_op - 1].node; //expression goes as left + op->nodes[1] = expression_nodes[next_op + 1].node; //next expression goes as right //replace all 3 nodes by this operator and make it an expression - expression.write[next_op - 1].node = op; - expression.remove_at(next_op); - expression.remove_at(next_op); + expression_nodes.write[next_op - 1].node = op; + expression_nodes.remove_at(next_op); + expression_nodes.remove_at(next_op); } } - return expression[0].node; + return expression_nodes[0].node; } bool Expression::_compile_expression() { diff --git a/core/math/plane.cpp b/core/math/plane.cpp index 6881ad4014..3b2eab4ae2 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -147,6 +147,7 @@ Variant Plane::intersect_3_bind(const Plane &p_plane1, const Plane &p_plane2) co return Variant(); } } + Variant Plane::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const { Vector3 inters; if (intersects_ray(p_from, p_dir, &inters)) { @@ -155,6 +156,7 @@ Variant Plane::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) return Variant(); } } + Variant Plane::intersects_segment_bind(const Vector3 &p_begin, const Vector3 &p_end) const { Vector3 inters; if (intersects_segment(p_begin, p_end, &inters)) { diff --git a/core/math/projection.cpp b/core/math/projection.cpp index d579b641a7..30c4f12795 100644 --- a/core/math/projection.cpp +++ b/core/math/projection.cpp @@ -169,7 +169,7 @@ Projection Projection::perspective_znear_adjusted(real_t p_new_znear) const { } Plane Projection::get_projection_plane(Planes p_plane) const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; switch (p_plane) { case PLANE_NEAR: { @@ -402,7 +402,7 @@ void Projection::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, r } real_t Projection::get_z_far() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; Plane new_plane = Plane(matrix[3] - matrix[2], matrix[7] - matrix[6], matrix[11] - matrix[10], @@ -415,7 +415,7 @@ real_t Projection::get_z_far() const { } real_t Projection::get_z_near() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; Plane new_plane = Plane(matrix[3] + matrix[2], matrix[7] + matrix[6], matrix[11] + matrix[10], @@ -426,7 +426,7 @@ real_t Projection::get_z_near() const { } Vector2 Projection::get_viewport_half_extents() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; ///////--- Near Plane ---/////// Plane near_plane = Plane(matrix[3] + matrix[2], matrix[7] + matrix[6], @@ -454,7 +454,7 @@ Vector2 Projection::get_viewport_half_extents() const { } Vector2 Projection::get_far_plane_half_extents() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; ///////--- Far Plane ---/////// Plane far_plane = Plane(matrix[3] - matrix[2], matrix[7] - matrix[6], @@ -514,7 +514,7 @@ Vector<Plane> Projection::get_projection_planes(const Transform3D &p_transform) Vector<Plane> planes; planes.resize(6); - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; Plane new_plane; @@ -807,7 +807,7 @@ bool Projection::is_orthogonal() const { } real_t Projection::get_fov() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; Plane right_plane = Plane(matrix[3] - matrix[0], matrix[7] - matrix[4], @@ -838,8 +838,9 @@ float Projection::get_lod_multiplier() const { return 1.0 / (zn / width); } - //usage is lod_size / (lod_distance * multiplier) < threshold + // Usage is lod_size / (lod_distance * multiplier) < threshold } + void Projection::make_scale(const Vector3 &p_scale) { set_identity(); columns[0][0] = p_scale.x; diff --git a/core/math/projection.h b/core/math/projection.h index 1bf5d8b2ed..38fb9781ae 100644 --- a/core/math/projection.h +++ b/core/math/projection.h @@ -31,10 +31,11 @@ #ifndef PROJECTION_H #define PROJECTION_H -#include "core/math/math_defs.h" #include "core/math/vector3.h" #include "core/math/vector4.h" -#include "core/templates/vector.h" + +template <class T> +class Vector; struct AABB; struct Plane; @@ -42,7 +43,7 @@ struct Rect2; struct Transform3D; struct Vector2; -struct Projection { +struct _NO_DISCARD_ Projection { enum Planes { PLANE_NEAR, PLANE_FAR, diff --git a/core/math/quaternion.h b/core/math/quaternion.h index 43d7bffcfc..077fe5f189 100644 --- a/core/math/quaternion.h +++ b/core/math/quaternion.h @@ -31,10 +31,10 @@ #ifndef QUATERNION_H #define QUATERNION_H -#include "core/math/math_defs.h" #include "core/math/math_funcs.h" #include "core/math/vector3.h" -#include "core/string/ustring.h" + +class String; struct _NO_DISCARD_ Quaternion { union { diff --git a/core/math/rect2.h b/core/math/rect2.h index 2d1be3d4f3..5ed2f8236c 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -281,7 +281,7 @@ struct _NO_DISCARD_ Rect2 { } _FORCE_INLINE_ Rect2 abs() const { - return Rect2(Point2(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs()); + return Rect2(Point2(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0)), size.abs()); } Vector2 get_support(const Vector2 &p_normal) const { diff --git a/core/math/transform_3d.h b/core/math/transform_3d.h index c62e4a7b0e..44d6d826f3 100644 --- a/core/math/transform_3d.h +++ b/core/math/transform_3d.h @@ -34,6 +34,7 @@ #include "core/math/aabb.h" #include "core/math/basis.h" #include "core/math/plane.h" +#include "core/templates/vector.h" struct _NO_DISCARD_ Transform3D { Basis basis; diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 4433559e6d..6515c55a85 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -215,10 +215,8 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects(p_aabb); - if (!valid) { + if (!b.aabb.intersects(p_aabb)) { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; @@ -302,12 +300,8 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_segment(p_begin, p_end); - //bool valid = b.aabb.intersects(ray_aabb); - - if (!valid) { + if (!b.aabb.intersects_segment(p_begin, p_end)) { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; @@ -407,10 +401,8 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_ray(p_begin, p_dir); - if (!valid) { + if (!b.aabb.intersects_ray(p_begin, p_dir)) { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; @@ -508,10 +500,8 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count); - if (!valid) { + if (!b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count)) { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; diff --git a/core/math/vector4.h b/core/math/vector4.h index 426c473e13..ac7b6c3aee 100644 --- a/core/math/vector4.h +++ b/core/math/vector4.h @@ -31,10 +31,10 @@ #ifndef VECTOR4_H #define VECTOR4_H -#include "core/math/math_defs.h" +#include "core/error/error_macros.h" #include "core/math/math_funcs.h" -#include "core/math/vector3.h" -#include "core/string/ustring.h" + +class String; struct _NO_DISCARD_ Vector4 { static const int AXIS_COUNT = 4; |