From db9cc41a1a5c6817aa65415af554a6049368f7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 29 Sep 2020 10:07:20 +0200 Subject: [PATCH] Delete unused math code --- CMakeLists.txt | 5 - UWP/NativeUWP/NativeUWP.vcxproj | 4 - UWP/NativeUWP/NativeUWP.vcxproj.filters | 12 --- ext/native/Android.mk | 2 - ext/native/math/CMakeLists.txt | 5 +- ext/native/math/lin/matrix4x4.cpp | 1 - ext/native/math/lin/plane.cpp | 13 --- ext/native/math/lin/plane.h | 41 -------- ext/native/math/lin/quat.cpp | 129 ------------------------ ext/native/math/lin/quat.h | 96 ------------------ ext/native/math/lin/ray.h | 14 --- ext/native/native.vcxproj | 4 - ext/native/native.vcxproj.filters | 15 --- libretro/Makefile.common | 2 - 14 files changed, 2 insertions(+), 341 deletions(-) delete mode 100644 ext/native/math/lin/plane.cpp delete mode 100644 ext/native/math/lin/plane.h delete mode 100644 ext/native/math/lin/quat.cpp delete mode 100644 ext/native/math/lin/quat.h delete mode 100644 ext/native/math/lin/ray.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 006843ac21..b2804099bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1022,11 +1022,6 @@ add_library(native STATIC ext/native/math/expression_parser.h ext/native/math/lin/matrix4x4.cpp ext/native/math/lin/matrix4x4.h - ext/native/math/lin/plane.cpp - ext/native/math/lin/plane.h - ext/native/math/lin/quat.cpp - ext/native/math/lin/quat.h - ext/native/math/lin/ray.h ext/native/math/lin/vec3.cpp ext/native/math/lin/vec3.h ext/native/math/math_util.cpp diff --git a/UWP/NativeUWP/NativeUWP.vcxproj b/UWP/NativeUWP/NativeUWP.vcxproj index 70bc7f2a6e..0d4f747f02 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj +++ b/UWP/NativeUWP/NativeUWP.vcxproj @@ -434,8 +434,6 @@ - - @@ -1585,8 +1583,6 @@ - - diff --git a/UWP/NativeUWP/NativeUWP.vcxproj.filters b/UWP/NativeUWP/NativeUWP.vcxproj.filters index eed8497fbb..a424450ad6 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj.filters +++ b/UWP/NativeUWP/NativeUWP.vcxproj.filters @@ -166,12 +166,6 @@ math - - math - - - math - math @@ -601,12 +595,6 @@ math - - math - - - math - math diff --git a/ext/native/Android.mk b/ext/native/Android.mk index 75bf2b31be..a922490f88 100644 --- a/ext/native/Android.mk +++ b/ext/native/Android.mk @@ -52,8 +52,6 @@ LOCAL_SRC_FILES :=\ math/math_util.cpp \ math/curves.cpp \ math/expression_parser.cpp \ - math/lin/plane.cpp.arm \ - math/lin/quat.cpp.arm \ math/lin/vec3.cpp.arm \ math/lin/matrix4x4.cpp.arm \ net/http_client.cpp \ diff --git a/ext/native/math/CMakeLists.txt b/ext/native/math/CMakeLists.txt index 4093973f06..3d6e0daa52 100644 --- a/ext/native/math/CMakeLists.txt +++ b/ext/native/math/CMakeLists.txt @@ -1,9 +1,8 @@ set(SRCS lin/matrix4x4.cpp lin/vec3.cpp - lin/quat.cpp - curves.cpp - math_util.cpp + curves.cpp + math_util.cpp ) set(SRCS ${SRCS}) diff --git a/ext/native/math/lin/matrix4x4.cpp b/ext/native/math/lin/matrix4x4.cpp index 007b8a8d17..7b4179bfef 100644 --- a/ext/native/math/lin/matrix4x4.cpp +++ b/ext/native/math/lin/matrix4x4.cpp @@ -3,7 +3,6 @@ #include #include "math/lin/vec3.h" -#include "math/lin/quat.h" #include "math/fast/fast_matrix.h" #ifdef _WIN32 diff --git a/ext/native/math/lin/plane.cpp b/ext/native/math/lin/plane.cpp deleted file mode 100644 index d62277889d..0000000000 --- a/ext/native/math/lin/plane.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "math/lin/matrix4x4.h" -#include "math/lin/plane.h" - -namespace Lin { - -void Plane::TransformByIT(const Matrix4x4 &m, Plane *out) { - out->x = x * m.xx + y * m.yx + z * m.zx + d * m.wx; - out->y = x * m.xy + y * m.yy + z * m.zy + d * m.wy; - out->z = x * m.xz + y * m.yz + z * m.zz + d * m.wz; - out->d = x * m.xw + y * m.yw + z * m.zw + d * m.ww; -} - -} // namespace Lin diff --git a/ext/native/math/lin/plane.h b/ext/native/math/lin/plane.h deleted file mode 100644 index 295c3f250a..0000000000 --- a/ext/native/math/lin/plane.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _PLANE_H -#define _PLANE_H - -#include "math/lin/vec3.h" - -namespace Lin { - -class Matrix4x4; - -class Plane { -public: - float x, y, z, d; - Plane() {} - Plane(float x_, float y_, float z_, float d_) - : x(x_), y(y_), z(z_), d(d_) { } - ~Plane() {} - - float Distance(const Vec3 &v) const { - return x * v.x + y * v.y + z * v.z + d; - } - - float Distance(float px, float py, float pz) const { - return x * px + y * py + z * pz + d; - } - - void Normalize() { - float inv_length = sqrtf(x * x + y * y + z * z); - x *= inv_length; - y *= inv_length; - z *= inv_length; - d *= inv_length; - } - - // Matrix is the inverse transpose of the wanted transform. - // out cannot be equal to this. - void TransformByIT(const Matrix4x4 &matrix, Plane *out); -}; - -} // namespace Lin - -#endif diff --git a/ext/native/math/lin/quat.cpp b/ext/native/math/lin/quat.cpp deleted file mode 100644 index f5479a51f5..0000000000 --- a/ext/native/math/lin/quat.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "math/lin/quat.h" -#include "math/lin/matrix4x4.h" - -namespace Lin { - -void Quaternion::toMatrix(Matrix4x4 *out) const { - Matrix4x4 temp; - temp.setIdentity(); - float ww, xx, yy, zz, wx, wy, wz, xy, xz, yz; - ww = w*w; xx = x*x; yy = y*y; zz = z*z; - wx = w*x*2; wy = w*y*2; wz = w*z*2; - xy = x*y*2; xz = x*z*2; yz = y*z*2; - - temp.xx = ww + xx - yy - zz; - temp.xy = xy + wz; - temp.xz = xz - wy; - - temp.yx = xy - wz; - temp.yy = ww - xx + yy - zz; - temp.yz = yz + wx; - - temp.zx = xz + wy; - temp.zy = yz - wx; - temp.zz = ww - xx - yy + zz; - - *out = temp; -} - -Quaternion Quaternion::fromMatrix(Matrix4x4 &m) -{ - // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes - // article "Quaternion Calculus and Fast Animation". - Quaternion q(0,0,0,1); - /* - float fTrace = m[0][0] + m[1][1] + m[2][2]; - float fRoot; - - if( fTrace > 0.0 ) - { - fRoot = sqrtf( fTrace + 1.0f ); - - q.w = 0.5f * fRoot; - - fRoot = 0.5f / fRoot; - - q.x = ( m[2][1] - m[1][2] ) * fRoot; - q.y = ( m[0][2] - m[2][0] ) * fRoot; - q.z = ( m[1][0] - m[0][1] ) * fRoot; - } - else - { - int iNext[3] = { 1, 2, 0 }; - - int i = 0; - if( m[1][1] > m[0][0] ) - i = 1; - - if( m[2][2] > m[i][i] ) - i = 2; - - int j = iNext[i]; - int k = iNext[j]; - - fRoot = sqrtf( m[i][i] - m[j][j] - m[k][k] + 1.0f ); - - float *apfQuat = &q.x; - - apfQuat[i] = 0.5f * fRoot; - - fRoot = 0.5f / fRoot; - - q.w = ( m[k][j] - m[j][k] ) * fRoot; - - apfQuat[j] = ( m[j][i] + m[i][j] ) * fRoot; - apfQuat[k] = ( m[k][i] + m[i][k] ) * fRoot; - } - q.normalize(); */ - return q; -}; - -// TODO: Allegedly, lerp + normalize can achieve almost as good results. -Quaternion Quaternion::slerp(const Quaternion &to, const float a) const { - Quaternion to2; - float angle, cos_angle, scale_from, scale_to, sin_angle; - - cos_angle = (x * to.x) + (y * to.y) + (z * to.z) + (w * to.w); //4D dot product - - if (cos_angle < 0.0f) - { - cos_angle = -cos_angle; - to2.w = -to.w; to2.x = -to.x; to2.y = -to.y; to2.z = -to.z; - } - else - { - to2 = to; - } - - if ((1.0f - fabsf(cos_angle)) > 0.00001f) - { - /* spherical linear interpolation (SLERP) */ - angle = acosf(cos_angle); - sin_angle = sinf(angle); - scale_from = sinf((1.0f - a) * angle) / sin_angle; - scale_to = sinf(a * angle) / sin_angle; - } - else - { - /* to prevent divide-by-zero, resort to linear interpolation */ - // This is okay in 99% of cases anyway, maybe should be the default? - scale_from = 1.0f - a; - scale_to = a; - } - - return Quaternion( - scale_from*x + scale_to*to2.x, - scale_from*y + scale_to*to2.y, - scale_from*z + scale_to*to2.z, - scale_from*w + scale_to*to2.w - ); -} - -Quaternion Quaternion::multiply(const Quaternion &q) const { - return Quaternion((w * q.x) + (x * q.w) + (y * q.z) - (z * q.y), - (w * q.y) + (y * q.w) + (z * q.x) - (x * q.z), - (w * q.z) + (z * q.w) + (x * q.y) - (y * q.x), - (w * q.w) - (x * q.x) - (y * q.y) - (z * q.z)); -} - -} diff --git a/ext/native/math/lin/quat.h b/ext/native/math/lin/quat.h deleted file mode 100644 index 8be9a94f5c..0000000000 --- a/ext/native/math/lin/quat.h +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef _MATH_LIN_QUAT_H -#define _MATH_LIN_QUAT_H - -#include "math/lin/vec3.h" - -namespace Lin { - -class Matrix4x4; - -class Quaternion -{ -public: - float x,y,z,w; - - Quaternion() { } - Quaternion(const float _x, const float _y, const float _z, const float _w) { - x=_x; y=_y; z=_z; w=_w; - } - void setIdentity() - { - x=y=z=0; w=1.0f; - } - void setXRotation(const float r) { w = cosf(r / 2); x = sinf(r / 2); y = z = 0; } - void setYRotation(const float r) { w = cosf(r / 2); y = sinf(r / 2); x = z = 0; } - void setZRotation(const float r) { w = cosf(r / 2); z = sinf(r / 2); x = y = 0; } - void toMatrix(Matrix4x4 *out) const; - static Quaternion fromMatrix(Matrix4x4 &m); - - Quaternion operator *(Quaternion &q) const - { - return Quaternion( - (w * q.w) - (x * q.x) - (y * q.y) - (z * q.z), - (w * q.x) + (x * q.w) + (y * q.z) - (z * q.y), - (w * q.y) + (y * q.w) + (z * q.x) - (x * q.z), - (w * q.z) + (z * q.w) + (x * q.y) - (y * q.x) - ); - } - Quaternion operator -() - { - return Quaternion(-x,-y,-z,-w); - } - void setRotation(Vec3 axis, float angle) - { - axis /= axis.length(); - angle *= .5f; - float sine = sinf(angle); - w = cosf(angle); - x = sine * axis.x; - y = sine * axis.y; - z = sine * axis.z; - } - void toAxisAngle(Vec3 &v, float &angle) - { - normalize(); - if (w==1.0f && x==0.0f && y==0.0f && z==0.0f) - { - v = Vec3(0,1,0); - angle = 0.0f; - return; - } - float cos_a = w; - angle = acosf(cos_a) * 2; - float sin_a = sqrtf( 1.0f - cos_a * cos_a ); - if (fabsf(sin_a) < 0.00005f) sin_a = 1; - float inv_sin_a=1.0f/sin_a; - v.x = x * inv_sin_a; - v.y = y * inv_sin_a; - v.z = z * inv_sin_a; - } - enum { - QUAT_SHORT, - QUAT_LONG, - QUAT_CW, - QUAT_CCW - }; - Quaternion slerp(const Quaternion &to, const float a) const; - Quaternion multiply(const Quaternion &q) const; - float &operator [] (int i) { - return *((&x) + i); - } - float operator [] (int i) const { - return *((&x) + i); - } - //not sure about this, maybe mag is supposed to sqrt - float magnitude() const { - return x*x + y*y + z*z + w*w; - } - void normalize() { - float f = 1.0f/sqrtf(magnitude()); - x*=f; y*=f; z*=f; w*=f; - } -}; - -} // namespace Lin - -#endif // _MATH_LIN_QUAT_H diff --git a/ext/native/math/lin/ray.h b/ext/native/math/lin/ray.h deleted file mode 100644 index 2287460fbb..0000000000 --- a/ext/native/math/lin/ray.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "vec3.h" - -/* __declspec(align(16)) */ struct Ray -{ - Vec3 origin; - int pad; - Vec3 dir; - int pad2; - Vec3 invdir; - int pad3; -}; - diff --git a/ext/native/native.vcxproj b/ext/native/native.vcxproj index 7e5e759400..b6653404d0 100644 --- a/ext/native/native.vcxproj +++ b/ext/native/native.vcxproj @@ -454,8 +454,6 @@ - - @@ -1169,8 +1167,6 @@ - - diff --git a/ext/native/native.vcxproj.filters b/ext/native/native.vcxproj.filters index a1f06f8607..d4ce209515 100644 --- a/ext/native/native.vcxproj.filters +++ b/ext/native/native.vcxproj.filters @@ -41,9 +41,6 @@ image - - math - math @@ -125,9 +122,6 @@ ui - - math - util @@ -361,9 +355,6 @@ math - - math - math @@ -430,9 +421,6 @@ ui - - math - math @@ -858,9 +846,6 @@ {d5fa3d62-88bf-4dc4-9814-28f3c0444e62} - - {1e85f968-7106-483c-ae7d-77d0ef58d787} - {6a548b3d-3a4c-4114-aa2f-0b42bf7bf2ce} diff --git a/libretro/Makefile.common b/libretro/Makefile.common index b53cce49a3..87fc689e03 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -301,8 +301,6 @@ SOURCES_CXX += $(NATIVEDIR)/math/dataconv.cpp \ $(NATIVEDIR)/math/curves.cpp \ $(NATIVEDIR)/math/expression_parser.cpp \ $(NATIVEDIR)/math/lin/matrix4x4.cpp \ - $(NATIVEDIR)/math/lin/plane.cpp \ - $(NATIVEDIR)/math/lin/quat.cpp \ $(NATIVEDIR)/math/lin/vec3.cpp \ $(NATIVEDIR)/net/http_client.cpp \ $(NATIVEDIR)/net/resolve.cpp \