summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/a_star.cpp4
-rw-r--r--core/math/basis.cpp (renamed from core/math/matrix3.cpp)8
-rw-r--r--core/math/basis.h (renamed from core/math/matrix3.h)8
-rw-r--r--core/math/bsp_tree.h2
-rw-r--r--core/math/geometry.h2
-rw-r--r--core/math/math_funcs.h4
-rw-r--r--core/math/quat.cpp2
-rw-r--r--core/math/random_pcg.h5
-rw-r--r--core/math/transform.h2
-rw-r--r--core/math/transform_2d.cpp12
-rw-r--r--core/math/transform_2d.h1
-rw-r--r--core/math/triangle_mesh.cpp2
-rw-r--r--core/math/vector3.cpp2
-rw-r--r--core/math/vector3.h2
14 files changed, 34 insertions, 22 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index a0556ae839..b885a06834 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -260,8 +260,8 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
}
// Check open list
- SelfList<Point> *least_cost_point = NULL;
- real_t least_cost = 1e30;
+ SelfList<Point> *least_cost_point = open_list.first();
+ real_t least_cost = Math_INF;
// TODO: Cache previous results
for (SelfList<Point> *E = open_list.first(); E; E = E->next()) {
diff --git a/core/math/matrix3.cpp b/core/math/basis.cpp
index 0aa67078fb..7f60b7962c 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/basis.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* matrix3.cpp */
+/* basis.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "matrix3.h"
+#include "basis.h"
#include "core/math/math_funcs.h"
#include "core/os/copymem.h"
@@ -258,7 +258,7 @@ Vector3 Basis::get_scale_abs() const {
}
Vector3 Basis::get_scale_local() const {
- real_t det_sign = determinant() > 0 ? 1 : -1;
+ real_t det_sign = SGN(determinant());
return det_sign * Vector3(elements[0].length(), elements[1].length(), elements[2].length());
}
@@ -284,7 +284,7 @@ Vector3 Basis::get_scale() const {
// matrix elements.
//
// The rotation part of this decomposition is returned by get_rotation* functions.
- real_t det_sign = determinant() > 0 ? 1 : -1;
+ real_t det_sign = SGN(determinant());
return det_sign * Vector3(
Vector3(elements[0][0], elements[1][0], elements[2][0]).length(),
Vector3(elements[0][1], elements[1][1], elements[2][1]).length(),
diff --git a/core/math/matrix3.h b/core/math/basis.h
index e7d6ab4522..128e56b494 100644
--- a/core/math/matrix3.h
+++ b/core/math/basis.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* matrix3.h */
+/* basis.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -31,8 +31,8 @@
// Circular dependency between Vector3 and Basis :/
#include "core/math/vector3.h"
-#ifndef MATRIX3_H
-#define MATRIX3_H
+#ifndef BASIS_H
+#define BASIS_H
#include "core/math/quat.h"
@@ -341,4 +341,4 @@ real_t Basis::determinant() const {
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]);
}
-#endif
+#endif // BASIS_H
diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h
index 0af532a2d5..a7a3697990 100644
--- a/core/math/bsp_tree.h
+++ b/core/math/bsp_tree.h
@@ -31,11 +31,11 @@
#ifndef BSP_TREE_H
#define BSP_TREE_H
-#include "core/dvector.h"
#include "core/math/aabb.h"
#include "core/math/face3.h"
#include "core/math/plane.h"
#include "core/method_ptrcall.h"
+#include "core/pool_vector.h"
#include "core/variant.h"
#include "core/vector.h"
/**
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 29493516b8..f927a63ed5 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -31,12 +31,12 @@
#ifndef GEOMETRY_H
#define GEOMETRY_H
-#include "core/dvector.h"
#include "core/math/face3.h"
#include "core/math/rect2.h"
#include "core/math/triangulate.h"
#include "core/math/vector3.h"
#include "core/object.h"
+#include "core/pool_vector.h"
#include "core/print_string.h"
#include "core/vector.h"
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index ea0bfd88cc..629002ced6 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -242,8 +242,8 @@ public:
static void randomize();
static uint32_t rand_from_seed(uint64_t *seed);
static uint32_t rand();
- static _ALWAYS_INLINE_ double randf() { return (double)rand() / (double)Math::RANDOM_MAX; }
- static _ALWAYS_INLINE_ float randd() { return (float)rand() / (float)Math::RANDOM_MAX; }
+ static _ALWAYS_INLINE_ double randd() { return (double)rand() / (double)Math::RANDOM_MAX; }
+ static _ALWAYS_INLINE_ float randf() { return (float)rand() / (float)Math::RANDOM_MAX; }
static double random(double from, double to);
static float random(float from, float to);
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index c1e45f36f0..6833d5de55 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -30,7 +30,7 @@
#include "quat.h"
-#include "core/math/matrix3.h"
+#include "core/math/basis.h"
#include "core/print_string.h"
// set_euler_xyz expects a vector containing the Euler angles in the format
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h
index ef69bf7120..2a69d43904 100644
--- a/core/math/random_pcg.h
+++ b/core/math/random_pcg.h
@@ -45,7 +45,10 @@ public:
RandomPCG(uint64_t seed = DEFAULT_SEED, uint64_t inc = PCG_DEFAULT_INC_64);
- _FORCE_INLINE_ void seed(uint64_t seed) { pcg.state = seed; }
+ _FORCE_INLINE_ void seed(uint64_t seed) {
+ pcg.state = seed;
+ pcg32_random_r(&pcg); // Force changing internal state to avoid initial 0
+ }
_FORCE_INLINE_ uint64_t get_seed() { return pcg.state; }
void randomize();
diff --git a/core/math/transform.h b/core/math/transform.h
index 9b323a6f0f..2f43f6b035 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -32,7 +32,7 @@
#define TRANSFORM_H
#include "core/math/aabb.h"
-#include "core/math/matrix3.h"
+#include "core/math/basis.h"
#include "core/math/plane.h"
/**
diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp
index 295e60babb..7d00158f3d 100644
--- a/core/math/transform_2d.cpp
+++ b/core/math/transform_2d.cpp
@@ -80,13 +80,14 @@ real_t Transform2D::get_rotation() const {
}
void Transform2D::set_rotation(real_t p_rot) {
-
+ Size2 scale = get_scale();
real_t cr = Math::cos(p_rot);
real_t sr = Math::sin(p_rot);
elements[0][0] = cr;
elements[0][1] = sr;
elements[1][0] = -sr;
elements[1][1] = cr;
+ set_scale(scale);
}
Transform2D::Transform2D(real_t p_rot, const Vector2 &p_pos) {
@@ -101,10 +102,17 @@ Transform2D::Transform2D(real_t p_rot, const Vector2 &p_pos) {
}
Size2 Transform2D::get_scale() const {
- real_t det_sign = basis_determinant() > 0 ? 1 : -1;
+ real_t det_sign = SGN(basis_determinant());
return Size2(elements[0].length(), det_sign * elements[1].length());
}
+void Transform2D::set_scale(Size2 &p_scale) {
+ elements[0].normalize();
+ elements[1].normalize();
+ elements[0] *= p_scale.x;
+ elements[1] *= p_scale.y;
+}
+
void Transform2D::scale(const Size2 &p_scale) {
scale_basis(p_scale);
elements[2] *= p_scale;
diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h
index 507e6a16eb..b9e7a36fb3 100644
--- a/core/math/transform_2d.h
+++ b/core/math/transform_2d.h
@@ -81,6 +81,7 @@ struct Transform2D {
real_t basis_determinant() const;
Size2 get_scale() const;
+ void set_scale(Size2 &p_scale);
_FORCE_INLINE_ const Vector2 &get_origin() const { return elements[2]; }
_FORCE_INLINE_ void set_origin(const Vector2 &p_origin) { elements[2] = p_origin; }
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index cdf3d16b72..83784a1fa7 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -30,7 +30,7 @@
#include "triangle_mesh.h"
-#include "core/sort.h"
+#include "core/sort_array.h"
int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc) {
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index b2e89ac7b8..1c28934422 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -30,7 +30,7 @@
#include "vector3.h"
-#include "core/math/matrix3.h"
+#include "core/math/basis.h"
void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) {
diff --git a/core/math/vector3.h b/core/math/vector3.h
index b0eef35635..8d6e093c4c 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -151,7 +151,7 @@ struct Vector3 {
};
// Should be included after class definition, otherwise we get circular refs
-#include "core/math/matrix3.h"
+#include "core/math/basis.h"
Vector3 Vector3::cross(const Vector3 &p_b) const {