summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/geometry.h21
-rw-r--r--core/math/math_funcs.cpp6
-rw-r--r--core/math/math_funcs.h2
3 files changed, 14 insertions, 15 deletions
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 2469e799a0..909d8164c3 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -105,23 +105,23 @@ public:
}
static void get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2, Vector3 &c1, Vector3 &c2) {
-#if 0
- //do the function 'd' as defined by pb. I think is is dot product of some sort
+#if 1
+//do the function 'd' as defined by pb. I think is is dot product of some sort
#define d_of(m, n, o, p) ((m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z))
//calculate the parametric position on the 2 curves, mua and mub
- real_t mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) );
- real_t mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1);
+ real_t mua = (d_of(p1, q1, q2, q1) * d_of(q2, q1, p2, p1) - d_of(p1, q1, p2, p1) * d_of(q2, q1, q2, q1)) / (d_of(p2, p1, p2, p1) * d_of(q2, q1, q2, q1) - d_of(q2, q1, p2, p1) * d_of(q2, q1, p2, p1));
+ real_t mub = (d_of(p1, q1, q2, q1) + mua * d_of(q2, q1, p2, p1)) / d_of(q2, q1, q2, q1);
//clip the value between [0..1] constraining the solution to lie on the original curves
if (mua < 0) mua = 0;
if (mub < 0) mub = 0;
if (mua > 1) mua = 1;
if (mub > 1) mub = 1;
- c1 = p1.linear_interpolate(p2,mua);
- c2 = q1.linear_interpolate(q2,mub);
-#endif
-
+ c1 = p1.linear_interpolate(p2, mua);
+ c2 = q1.linear_interpolate(q2, mub);
+#else
+ //this is broken do not use
Vector3 u = p2 - p1;
Vector3 v = q2 - q1;
Vector3 w = p1 - q1;
@@ -144,8 +144,9 @@ public:
c1 = w + sc * u;
c2 = w + tc * v;
- // get the difference of the two closest points
- //Vector dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc)
+// get the difference of the two closest points
+//Vector dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc)
+#endif
}
static real_t get_closest_distance_between_segments(const Vector3 &p_from_a, const Vector3 &p_to_a, const Vector3 &p_from_b, const Vector3 &p_to_b) {
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 6a46b9fbe3..9f5a9c193a 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -30,7 +30,7 @@
#include "math_funcs.h"
#include "core/os/os.h"
-pcg32_random_t Math::default_pcg = { 1, PCG_DEFAULT_INC_64 };
+pcg32_random_t Math::default_pcg = { 12047754176567800795ULL, PCG_DEFAULT_INC_64 };
#define PHI 0x9e3779b9
@@ -51,9 +51,7 @@ void Math::seed(uint64_t x) {
}
void Math::randomize() {
-
- OS::Time time = OS::get_singleton()->get_time();
- seed(OS::get_singleton()->get_ticks_usec() * (time.hour + 1) * (time.min + 1) * (time.sec + 1) * rand()); // TODO: can be simplified.
+ seed(OS::get_singleton()->get_ticks_usec() * default_pcg.state + PCG_DEFAULT_INC_64);
}
uint32_t Math::rand() {
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 10426c9243..d71d9bd792 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -157,7 +157,7 @@ public:
static uint32_t larger_prime(uint32_t p_val);
- static void seed(uint64_t x = 0);
+ static void seed(uint64_t x);
static void randomize();
static uint32_t rand_from_seed(uint64_t *seed);
static uint32_t rand();