Delete unused math code

This commit is contained in:
Henrik Rydgård 2020-09-29 10:07:20 +02:00
parent 1e6c13cb56
commit db9cc41a1a
14 changed files with 2 additions and 341 deletions

View file

@ -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

View file

@ -434,8 +434,6 @@
<ClInclude Include="..\..\ext\native\math\fast\fast_matrix.h" />
<ClInclude Include="..\..\ext\native\math\geom2d.h" />
<ClInclude Include="..\..\ext\native\math\lin\matrix4x4.h" />
<ClInclude Include="..\..\ext\native\math\lin\plane.h" />
<ClInclude Include="..\..\ext\native\math\lin\quat.h" />
<ClInclude Include="..\..\ext\native\math\lin\ray.h" />
<ClInclude Include="..\..\ext\native\math\lin\vec3.h" />
<ClInclude Include="..\..\ext\native\math\math_util.h" />
@ -1585,8 +1583,6 @@
</ForcedIncludeFiles>
</ClCompile>
<ClCompile Include="..\..\ext\native\math\lin\matrix4x4.cpp" />
<ClCompile Include="..\..\ext\native\math\lin\plane.cpp" />
<ClCompile Include="..\..\ext\native\math\lin\quat.cpp" />
<ClCompile Include="..\..\ext\native\math\lin\vec3.cpp" />
<ClCompile Include="..\..\ext\native\math\math_util.cpp" />
<ClCompile Include="..\..\ext\native\net\http_client.cpp" />

View file

@ -166,12 +166,6 @@
<ClCompile Include="..\..\ext\native\math\lin\matrix4x4.cpp">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="..\..\ext\native\math\lin\plane.cpp">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="..\..\ext\native\math\lin\quat.cpp">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="..\..\ext\native\math\lin\vec3.cpp">
<Filter>math</Filter>
</ClCompile>
@ -601,12 +595,6 @@
<ClInclude Include="..\..\ext\native\math\lin\matrix4x4.h">
<Filter>math</Filter>
</ClInclude>
<ClInclude Include="..\..\ext\native\math\lin\plane.h">
<Filter>math</Filter>
</ClInclude>
<ClInclude Include="..\..\ext\native\math\lin\quat.h">
<Filter>math</Filter>
</ClInclude>
<ClInclude Include="..\..\ext\native\math\lin\ray.h">
<Filter>math</Filter>
</ClInclude>

View file

@ -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 \

View file

@ -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})

View file

@ -3,7 +3,6 @@
#include <cstdio>
#include "math/lin/vec3.h"
#include "math/lin/quat.h"
#include "math/fast/fast_matrix.h"
#ifdef _WIN32

View file

@ -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

View file

@ -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

View file

@ -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));
}
}

View file

@ -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

View file

@ -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;
};

View file

@ -454,8 +454,6 @@
<ClInclude Include="math\expression_parser.h" />
<ClInclude Include="math\geom2d.h" />
<ClInclude Include="math\lin\matrix4x4.h" />
<ClInclude Include="math\lin\plane.h" />
<ClInclude Include="math\lin\quat.h" />
<ClInclude Include="math\lin\vec3.h" />
<ClInclude Include="math\math_util.h" />
<ClInclude Include="math\fast\fast_math.h" />
@ -1169,8 +1167,6 @@
<ClCompile Include="math\curves.cpp" />
<ClCompile Include="math\expression_parser.cpp" />
<ClCompile Include="math\lin\matrix4x4.cpp" />
<ClCompile Include="math\lin\plane.cpp" />
<ClCompile Include="math\lin\quat.cpp" />
<ClCompile Include="math\lin\vec3.cpp" />
<ClCompile Include="math\math_util.cpp" />
<ClCompile Include="math\fast\fast_math.c" />

View file

@ -41,9 +41,6 @@
<ClInclude Include="image\zim_save.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="math\lin\quat.h">
<Filter>math</Filter>
</ClInclude>
<ClInclude Include="math\lin\matrix4x4.h">
<Filter>math</Filter>
</ClInclude>
@ -125,9 +122,6 @@
<ClInclude Include="ui\screen.h">
<Filter>ui</Filter>
</ClInclude>
<ClInclude Include="math\lin\plane.h">
<Filter>math</Filter>
</ClInclude>
<ClInclude Include="util\random\rng.h">
<Filter>util</Filter>
</ClInclude>
@ -361,9 +355,6 @@
<ClCompile Include="math\lin\matrix4x4.cpp">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="math\lin\quat.cpp">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="math\lin\vec3.cpp">
<Filter>math</Filter>
</ClCompile>
@ -430,9 +421,6 @@
<ClCompile Include="ui\screen.cpp">
<Filter>ui</Filter>
</ClCompile>
<ClCompile Include="math\lin\plane.cpp">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="math\curves.cpp">
<Filter>math</Filter>
</ClCompile>
@ -858,9 +846,6 @@
<Filter Include="data">
<UniqueIdentifier>{d5fa3d62-88bf-4dc4-9814-28f3c0444e62}</UniqueIdentifier>
</Filter>
<Filter Include="io">
<UniqueIdentifier>{1e85f968-7106-483c-ae7d-77d0ef58d787}</UniqueIdentifier>
</Filter>
<Filter Include="net">
<UniqueIdentifier>{6a548b3d-3a4c-4114-aa2f-0b42bf7bf2ce}</UniqueIdentifier>
</Filter>

View file

@ -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 \