summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/camera_matrix.cpp14
-rw-r--r--core/math/geometry.h29
-rw-r--r--core/math/math_2d.cpp27
-rw-r--r--core/math/math_2d.h1
-rw-r--r--core/math/math_funcs.cpp5
-rw-r--r--core/math/octree.h23
-rw-r--r--core/math/quat.cpp90
-rw-r--r--core/math/rect3.h38
-rw-r--r--core/math/transform.h30
-rw-r--r--core/math/vector3.cpp45
10 files changed, 5 insertions, 297 deletions
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 24004ff849..0512cdd798 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -180,19 +180,7 @@ 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) {
-#if 0
- ///@TODO, give a check to this. I'm not sure if it's working.
- set_identity();
- matrix[0][0]=(2*p_near) / (p_right-p_left);
- matrix[0][2]=(p_right+p_left) / (p_right-p_left);
- matrix[1][1]=(2*p_near) / (p_top-p_bottom);
- matrix[1][2]=(p_top+p_bottom) / (p_top-p_bottom);
- matrix[2][2]=-(p_far+p_near) / ( p_far-p_near);
- matrix[2][3]=-(2*p_far*p_near) / (p_far-p_near);
- matrix[3][2]=-1;
- matrix[3][3]=0;
-#else
real_t *te = &matrix[0][0];
real_t x = 2 * p_near / (p_right - p_left);
real_t y = 2 * p_near / (p_top - p_bottom);
@@ -218,8 +206,6 @@ void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, r
te[13] = 0;
te[14] = d;
te[15] = 0;
-
-#endif
}
real_t CameraMatrix::get_z_far() const {
diff --git a/core/math/geometry.h b/core/math/geometry.h
index bba6997012..cd069bd7a3 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -105,7 +105,7 @@ 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 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))
@@ -120,33 +120,6 @@ public:
if (mub > 1) mub = 1;
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;
- float a = u.dot(u);
- float b = u.dot(v);
- float c = v.dot(v); // always >= 0
- float d = u.dot(w);
- float e = v.dot(w);
- float D = a * c - b * b; // always >= 0
- float sc, tc;
-
- // compute the line parameters of the two closest points
- if (D < CMP_EPSILON) { // the lines are almost parallel
- sc = 0.0;
- tc = (b > c ? d / b : e / c); // use the largest denominator
- } else {
- sc = (b * e - c * d) / D;
- tc = (a * e - b * d) / D;
- }
-
- 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)
-#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_2d.cpp b/core/math/math_2d.cpp
index ddfa0d424c..c77fe96ff2 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -205,33 +205,6 @@ Vector2 Vector2::clamped(real_t p_len) const {
return v;
}
-Vector2 Vector2::cubic_interpolate_soft(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const {
-#if 0
- k[0] = ((*this) (vi[0] + 1, vi[1], vi[2])) - ((*this) (vi[0],
- vi[1],vi[2])); //fk = a0
- k[1] = (((*this) (vi[0] + 1, vi[1], vi[2])) - ((*this) ((int) (v(0) -
- 1), vi[1],vi[2])))*0.5; //dk = a1
- k[2] = (((*this) ((int) (v(0) + 2), vi[1], vi[2])) - ((*this) (vi[0],
- vi[1],vi[2])))*0.5; //dk+1
- k[3] = k[0]*3 - k[1]*2 - k[2];//a2
- k[4] = k[1] + k[2] - k[0]*2;//a3
-
- //ip = a3(t-tk)³ + a2(t-tk)² + a1(t-tk) + a0
- //
- //a3 = dk + dk+1 - Dk
- //a2 = 3Dk - 2dk - dk+1
- //a1 = dk
- //a0 = fk
- //
- //dk = (fk+1 - fk-1)*0.5
- //Dk = (fk+1 - fk)
-
- real_t dk =
-#endif
-
- return Vector2();
-}
-
Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const {
Vector2 p0 = p_pre_a;
diff --git a/core/math/math_2d.h b/core/math/math_2d.h
index 8b7acf514a..d215df8a43 100644
--- a/core/math/math_2d.h
+++ b/core/math/math_2d.h
@@ -113,7 +113,6 @@ struct Vector2 {
_FORCE_INLINE_ static Vector2 linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t);
_FORCE_INLINE_ Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const;
Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
- Vector2 cubic_interpolate_soft(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
Vector2 slide(const Vector2 &p_normal) const;
Vector2 bounce(const Vector2 &p_normal) const;
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 7a8489b518..6fb688f16b 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -28,16 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "math_funcs.h"
+
#include "core/os/os.h"
pcg32_random_t Math::default_pcg = { 12047754176567800795ULL, PCG_DEFAULT_INC_64 };
#define PHI 0x9e3779b9
-#if 0
-static uint32_t Q[4096];
-#endif
-
// TODO: we should eventually expose pcg.inc too
uint32_t Math::rand_from_seed(uint64_t *seed) {
pcg32_random_t pcg = { *seed, PCG_DEFAULT_INC_64 };
diff --git a/core/math/octree.h b/core/math/octree.h
index 2b0dc83050..95a67943fd 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -851,28 +851,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const Rect3 &p_aabb) {
ERR_FAIL_COND(!E);
Element &e = E->get();
-#if 0
-
- pass++;
- if (!e.aabb.has_no_surface()) {
- _remove_element(&e);
- }
-
- e.aabb=p_aabb;
-
- if (!e.aabb.has_no_surface()) {
- _ensure_valid_root(p_aabb);
-
- _insert_element(&e,root);
- if (use_pairs)
- _element_check_pairs(&e);
-
- }
-
- _optimize();
-
-#else
-
bool old_has_surf = !e.aabb.has_no_surface();
bool new_has_surf = !p_aabb.has_no_surface();
@@ -979,7 +957,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const Rect3 &p_aabb) {
}
_optimize();
-#endif
}
template <class T, bool use_pairs, class AL>
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index e813d93e9f..cebc5b9522 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -139,48 +139,6 @@ Quat Quat::inverse() const {
Quat Quat::slerp(const Quat &q, const real_t &t) const {
-#if 0
-
-
- Quat dst=q;
- Quat src=*this;
-
- src.normalize();
- dst.normalize();
-
- real_t cosine = dst.dot(src);
-
- if (cosine < 0 && true) {
- cosine = -cosine;
- dst = -dst;
- } else {
- dst = dst;
- }
-
- if (Math::abs(cosine) < 1 - CMP_EPSILON) {
- // Standard case (slerp)
- real_t sine = Math::sqrt(1 - cosine*cosine);
- real_t angle = Math::atan2(sine, cosine);
- real_t inv_sine = 1.0 / sine;
- real_t coeff_0 = Math::sin((1.0 - t) * angle) * inv_sine;
- real_t coeff_1 = Math::sin(t * angle) * inv_sine;
- Quat ret= src * coeff_0 + dst * coeff_1;
-
- return ret;
- } else {
- // There are two situations:
- // 1. "rkP" and "q" are very close (cosine ~= +1), so we can do a linear
- // interpolation safely.
- // 2. "rkP" and "q" are almost invedste of each other (cosine ~= -1), there
- // are an infinite number of possibilities interpolation. but we haven't
- // have method to fix this case, so just use linear interpolation here.
- Quat ret = src * (1.0 - t) + dst *t;
- // taking the complement requires renormalisation
- ret.normalize();
- return ret;
- }
-#else
-
Quat to1;
real_t omega, cosom, sinom, scale0, scale1;
@@ -221,7 +179,6 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
scale0 * y + scale1 * to1.y,
scale0 * z + scale1 * to1.z,
scale0 * w + scale1 * to1.w);
-#endif
}
Quat Quat::slerpni(const Quat &q, const real_t &t) const {
@@ -241,53 +198,6 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const {
invFactor * from.y + newFactor * q.y,
invFactor * from.z + newFactor * q.z,
invFactor * from.w + newFactor * q.w);
-
-#if 0
- real_t to1[4];
- real_t omega, cosom, sinom, scale0, scale1;
-
-
- // calc cosine
- cosom = x * q.x + y * q.y + z * q.z
- + w * q.w;
-
-
- // adjust signs (if necessary)
- if ( cosom <0.0 && false) {
- cosom = -cosom;to1[0] = - q.x;
- to1[1] = - q.y;
- to1[2] = - q.z;
- to1[3] = - q.w;
- } else {
- to1[0] = q.x;
- to1[1] = q.y;
- to1[2] = q.z;
- to1[3] = q.w;
- }
-
-
- // calculate coefficients
-
- if ( (1.0 - cosom) > CMP_EPSILON ) {
- // standard case (slerp)
- omega = Math::acos(cosom);
- sinom = Math::sin(omega);
- scale0 = Math::sin((1.0 - t) * omega) / sinom;
- scale1 = Math::sin(t * omega) / sinom;
- } else {
- // "from" and "to" quaternions are very close
- // ... so we can do a linear interpolation
- scale0 = 1.0 - t;
- scale1 = t;
- }
- // calculate final values
- return Quat(
- scale0 * x + scale1 * to1[0],
- scale0 * y + scale1 * to1[1],
- scale0 * z + scale1 * to1[2],
- scale0 * w + scale1 * to1[3]
- );
-#endif
}
Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const {
diff --git a/core/math/rect3.h b/core/math/rect3.h
index 642595979d..c3a2f5fbfb 100644
--- a/core/math/rect3.h
+++ b/core/math/rect3.h
@@ -189,8 +189,6 @@ Vector3 Rect3::get_endpoint(int p_point) const {
bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const {
-#if 1
-
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@@ -206,42 +204,6 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co
}
return true;
-#else
- //cache all points to check against!
- // #warning should be easy to optimize, just use the same as when taking the support and use only that point
- Vector3 points[8] = {
- Vector3(position.x, position.y, position.z),
- Vector3(position.x, position.y, position.z + size.z),
- Vector3(position.x, position.y + size.y, position.z),
- Vector3(position.x, position.y + size.y, position.z + size.z),
- Vector3(position.x + size.x, position.y, position.z),
- Vector3(position.x + size.x, position.y, position.z + size.z),
- Vector3(position.x + size.x, position.y + size.y, position.z),
- Vector3(position.x + size.x, position.y + size.y, position.z + size.z),
- };
-
- for (int i = 0; i < p_plane_count; i++) { //for each plane
-
- const Plane &plane = p_planes[i];
- bool all_points_over = true;
- //test if it has all points over!
-
- for (int j = 0; j < 8; j++) {
-
- if (!plane.is_point_over(points[j])) {
-
- all_points_over = false;
- break;
- }
- }
-
- if (all_points_over) {
-
- return false;
- }
- }
- return true;
-#endif
}
bool Rect3::has_point(const Vector3 &p_point) const {
diff --git a/core/math/transform.h b/core/math/transform.h
index 15deeaa8eb..566bf482a9 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -154,8 +154,7 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const {
}
_FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const {
-/* define vertices */
-#if 1
+ /* define vertices */
Vector3 x = basis.get_axis(0) * p_aabb.size.x;
Vector3 y = basis.get_axis(1) * p_aabb.size.y;
Vector3 z = basis.get_axis(2) * p_aabb.size.z;
@@ -171,31 +170,8 @@ _FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const {
new_aabb.expand_to(pos + y + z);
new_aabb.expand_to(pos + x + y + z);
return new_aabb;
-#else
-
- 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),
- Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
- Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
- Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z),
- Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
- Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
- Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
- Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z)
- };
-
- AABB ret;
-
- ret.pos = xform(vertices[0]);
-
- for (int i = 1; i < 8; i++) {
-
- ret.expand_to(xform(vertices[i]));
- }
-
- return ret;
-#endif
}
+
_FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3 &p_aabb) const {
/* define vertices */
@@ -222,4 +198,4 @@ _FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3 &p_aabb) const {
return ret;
}
-#endif
+#endif // TRANSFORM_H
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 39ef05b78a..144234f4d1 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -125,51 +125,6 @@ Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, c
return out;
}
-#if 0
-Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
-
- Vector3 p0=p_pre_a;
- Vector3 p1=*this;
- Vector3 p2=p_b;
- Vector3 p3=p_post_b;
-
- if (true) {
-
- real_t ab = p0.distance_to(p1);
- real_t bc = p1.distance_to(p2);
- real_t cd = p2.distance_to(p3);
-
- //if (ab>bc) {
- if (ab>0)
- p0 = p1+(p0-p1)*(bc/ab);
- //}
-
- //if (cd>bc) {
- if (cd>0)
- p3 = p2+(p3-p2)*(bc/cd);
- //}
- }
-
- real_t t = p_t;
- real_t t2 = t * t;
- real_t t3 = t2 * t;
-
- Vector3 out;
- out.x = 0.5 * ( ( 2.0 * p1.x ) +
- ( -p0.x + p2.x ) * t +
- ( 2.0 * p0.x - 5.0 * p1.x + 4 * p2.x - p3.x ) * t2 +
- ( -p0.x + 3.0 * p1.x - 3.0 * p2.x + p3.x ) * t3 );
- out.y = 0.5 * ( ( 2.0 * p1.y ) +
- ( -p0.y + p2.y ) * t +
- ( 2.0 * p0.y - 5.0 * p1.y + 4 * p2.y - p3.y ) * t2 +
- ( -p0.y + 3.0 * p1.y - 3.0 * p2.y + p3.y ) * t3 );
- out.z = 0.5 * ( ( 2.0 * p1.z ) +
- ( -p0.z + p2.z ) * t +
- ( 2.0 * p0.z - 5.0 * p1.z + 4 * p2.z - p3.z ) * t2 +
- ( -p0.z + 3.0 * p1.z - 3.0 * p2.z + p3.z ) * t3 );
- return out;
-}
-#endif
Vector3::operator String() const {
return (rtos(x) + ", " + rtos(y) + ", " + rtos(z));