diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-06-21 18:11:55 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-06-21 21:31:11 +0700 |
commit | 325dca9f212f9fd44cd10a8180529970c7a08c72 (patch) | |
tree | e1cfaec078dfa49f4d51d05eef8a5b0967843a41 /src/PhysicsMath.h | |
parent | 10f5376de856ecead4e8bbf66f19157f36f7a382 (diff) | |
download | blackshades-1.2.0.tar.gz |
Remove trailing whitespaces and duplicated blank lines 1.2.0
Diffstat (limited to 'src/PhysicsMath.h')
-rw-r--r-- | src/PhysicsMath.h | 289 |
1 files changed, 25 insertions, 264 deletions
diff --git a/src/PhysicsMath.h b/src/PhysicsMath.h index 99ef76f..758931b 100644 --- a/src/PhysicsMath.h +++ b/src/PhysicsMath.h @@ -2,33 +2,23 @@ #define _PHYSICSMATH_H_ - - #include <cmath> #include "Quaternions.h" - - //------------------------------------------------------------------------// // Misc. Constants //------------------------------------------------------------------------// - - float const pi = 3.14159265f; float const g = -32.174f; // acceleration due to gravity, ft/s^2 float const rho = 0.0023769f; // desity of air at sea level, slugs/ft^3 -float const tol = 0.0000000001f; // float type tolerance - - - - +float const tol = 0.0000000001f; // float type tolerance //------------------------------------------------------------------------// @@ -40,28 +30,20 @@ inline float DegreesToRadians(float deg); inline float RadiansToDegrees(float rad); - - inline float DegreesToRadians(float deg) { - return deg * pi / 180.0f; - } - - inline float RadiansToDegrees(float rad) -{ +{ return rad * 180.0f / pi; } - - //------------------------------------------------------------------------// // Vector Class and vector functions @@ -78,22 +60,16 @@ public: float z; - - Vector(void); Vector(float xi, float yi, float zi); - - float Magnitude(void); void Normalize(void); void Reverse(void); - - Vector& operator+=(Vector u); // vector addition Vector& operator-=(Vector u); // vector subtraction @@ -102,16 +78,10 @@ public: Vector& operator/=(float s); // scalar divide - - Vector operator-(void); - - }; - - inline Vector operator+(Vector u, Vector v); inline Vector operator-(Vector u, Vector v); @@ -128,8 +98,6 @@ inline Vector operator/(Vector u, float s); inline float TripleScalarProduct(Vector u, Vector v, Vector w); - - inline Vector::Vector(void) { @@ -142,8 +110,6 @@ inline Vector::Vector(void) } - - inline Vector::Vector(float xi, float yi, float zi) { @@ -156,8 +122,6 @@ inline Vector::Vector(float xi, float yi, float zi) } - - inline float Vector::Magnitude(void) { @@ -166,8 +130,6 @@ inline float Vector::Magnitude(void) } - - inline void Vector::Normalize(void) { @@ -180,9 +142,7 @@ inline void Vector::Normalize(void) y /= m; - z /= m; - - + z /= m; if (fabs(x) < tol) x = 0.0f; @@ -192,8 +152,6 @@ inline void Vector::Normalize(void) } - - inline void Vector::Reverse(void) { @@ -206,8 +164,6 @@ inline void Vector::Reverse(void) } - - inline Vector& Vector::operator+=(Vector u) { @@ -222,8 +178,6 @@ inline Vector& Vector::operator+=(Vector u) } - - inline Vector& Vector::operator-=(Vector u) { @@ -238,8 +192,6 @@ inline Vector& Vector::operator-=(Vector u) } - - inline Vector& Vector::operator*=(float s) { @@ -254,8 +206,6 @@ inline Vector& Vector::operator*=(float s) } - - inline Vector& Vector::operator/=(float s) { @@ -270,8 +220,6 @@ inline Vector& Vector::operator/=(float s) } - - inline Vector Vector::operator-(void) { @@ -280,10 +228,6 @@ inline Vector Vector::operator-(void) } - - - - inline Vector operator+(Vector u, Vector v) { @@ -292,8 +236,6 @@ inline Vector operator+(Vector u, Vector v) } - - inline Vector operator-(Vector u, Vector v) { @@ -302,8 +244,6 @@ inline Vector operator-(Vector u, Vector v) } - - // Vector cross product (u cross v) inline Vector operator^(Vector u, Vector v) @@ -318,8 +258,6 @@ inline Vector operator^(Vector u, Vector v) } - - // Vector dot product inline float operator*(Vector u, Vector v) @@ -330,8 +268,6 @@ inline float operator*(Vector u, Vector v) } - - inline Vector operator*(float s, Vector u) { @@ -340,8 +276,6 @@ inline Vector operator*(float s, Vector u) } - - inline Vector operator*(Vector u, float s) { @@ -350,8 +284,6 @@ inline Vector operator*(Vector u, float s) } - - inline Vector operator/(Vector u, float s) { @@ -360,8 +292,6 @@ inline Vector operator/(Vector u, float s) } - - // triple scalar product (u dot (v cross w)) inline float TripleScalarProduct(Vector u, Vector v, Vector w) @@ -376,52 +306,36 @@ inline float TripleScalarProduct(Vector u, Vector v, Vector w) //return u*(v^w); - - } - - - - - - //------------------------------------------------------------------------// // Matrix Class and matrix functions //------------------------------------------------------------------------// - - class Matrix3x3 { public: // elements eij: i -> row, j -> column - float e11, e12, e13, e21, e22, e23, e31, e32, e33; - - + float e11, e12, e13, e21, e22, e23, e31, e32, e33; Matrix3x3(void); - Matrix3x3( float r1c1, float r1c2, float r1c3, + Matrix3x3( float r1c1, float r1c2, float r1c3, - float r2c1, float r2c2, float r2c3, + float r2c1, float r2c2, float r2c3, float r3c1, float r3c2, float r3c3 ); - - float det(void); Matrix3x3 Transpose(void); Matrix3x3 Inverse(void); - - Matrix3x3& operator+=(Matrix3x3 m); Matrix3x3& operator-=(Matrix3x3 m); @@ -432,8 +346,6 @@ public: }; - - inline Matrix3x3 operator+(Matrix3x3 m1, Matrix3x3 m2); inline Matrix3x3 operator-(Matrix3x3 m1, Matrix3x3 m2); @@ -450,16 +362,6 @@ inline Vector operator*(Matrix3x3 m, Vector u); inline Vector operator*(Vector u, Matrix3x3 m); - - - - - - - - - - inline Matrix3x3::Matrix3x3(void) { @@ -484,11 +386,9 @@ inline Matrix3x3::Matrix3x3(void) } +inline Matrix3x3::Matrix3x3( float r1c1, float r1c2, float r1c3, - -inline Matrix3x3::Matrix3x3( float r1c1, float r1c2, float r1c3, - - float r2c1, float r2c2, float r2c3, + float r2c1, float r2c2, float r2c3, float r3c1, float r3c2, float r3c3 ) @@ -514,28 +414,24 @@ inline Matrix3x3::Matrix3x3( float r1c1, float r1c2, float r1c3, } - - inline float Matrix3x3::det(void) { - return e11*e22*e33 - + return e11*e22*e33 - - e11*e32*e23 + + e11*e32*e23 + - e21*e32*e13 - + e21*e32*e13 - - e21*e12*e33 + + e21*e12*e33 + - e31*e12*e23 - + e31*e12*e23 - - e31*e22*e13; + e31*e22*e13; } - - inline Matrix3x3 Matrix3x3::Transpose(void) { @@ -544,30 +440,24 @@ inline Matrix3x3 Matrix3x3::Transpose(void) } - - inline Matrix3x3 Matrix3x3::Inverse(void) { - float d = e11*e22*e33 - + float d = e11*e22*e33 - - e11*e32*e23 + + e11*e32*e23 + - e21*e32*e13 - + e21*e32*e13 - - e21*e12*e33 + + e21*e12*e33 + - e31*e12*e23 - + e31*e12*e23 - e31*e22*e13; - - if (d == 0) d = 1; - - return Matrix3x3( (e22*e33-e23*e32)/d, -(e12*e33-e13*e32)/d, @@ -584,12 +474,10 @@ inline Matrix3x3 Matrix3x3::Inverse(void) -(e11*e32-e12*e31)/d, - (e11*e22-e12*e21)/d ); + (e11*e22-e12*e21)/d ); } - - inline Matrix3x3& Matrix3x3::operator+=(Matrix3x3 m) { @@ -616,8 +504,6 @@ inline Matrix3x3& Matrix3x3::operator+=(Matrix3x3 m) } - - inline Matrix3x3& Matrix3x3::operator-=(Matrix3x3 m) { @@ -644,8 +530,6 @@ inline Matrix3x3& Matrix3x3::operator-=(Matrix3x3 m) } - - inline Matrix3x3& Matrix3x3::operator*=(float s) { @@ -672,8 +556,6 @@ inline Matrix3x3& Matrix3x3::operator*=(float s) } - - inline Matrix3x3& Matrix3x3::operator/=(float s) { @@ -700,8 +582,6 @@ inline Matrix3x3& Matrix3x3::operator/=(float s) } - - inline Matrix3x3 operator+(Matrix3x3 m1, Matrix3x3 m2) { @@ -726,8 +606,6 @@ inline Matrix3x3 operator+(Matrix3x3 m1, Matrix3x3 m2) } - - inline Matrix3x3 operator-(Matrix3x3 m1, Matrix3x3 m2) { @@ -752,11 +630,9 @@ inline Matrix3x3 operator-(Matrix3x3 m1, Matrix3x3 m2) } - - inline Matrix3x3 operator/(Matrix3x3 m, float s) -{ +{ return Matrix3x3( m.e11/s, @@ -778,8 +654,6 @@ inline Matrix3x3 operator/(Matrix3x3 m, float s) } - - inline Matrix3x3 operator*(Matrix3x3 m1, Matrix3x3 m2) { @@ -804,8 +678,6 @@ inline Matrix3x3 operator*(Matrix3x3 m1, Matrix3x3 m2) } - - inline Matrix3x3 operator*(Matrix3x3 m, float s) { @@ -830,8 +702,6 @@ inline Matrix3x3 operator*(Matrix3x3 m, float s) } - - inline Matrix3x3 operator*(float s, Matrix3x3 m) { @@ -856,8 +726,6 @@ inline Matrix3x3 operator*(float s, Matrix3x3 m) } - - inline Vector operator*(Matrix3x3 m, Vector u) { @@ -866,12 +734,10 @@ inline Vector operator*(Matrix3x3 m, Vector u) m.e21*u.x + m.e22*u.y + m.e23*u.z, - m.e31*u.x + m.e32*u.y + m.e33*u.z); + m.e31*u.x + m.e32*u.y + m.e33*u.z); } - - inline Vector operator*(Vector u, Matrix3x3 m) { @@ -884,16 +750,12 @@ inline Vector operator*(Vector u, Matrix3x3 m) } - - //------------------------------------------------------------------------// // Quaternion Class and Quaternion functions //------------------------------------------------------------------------// - - class Quaternion { public: @@ -902,14 +764,10 @@ public: Vector v; // vector part: v.x, v.y, v.z - - Quaternion(void); Quaternion(float e0, float e1, float e2, float e3); - - float Magnitude(void); Vector GetVector(void); @@ -928,8 +786,6 @@ public: }; - - inline Quaternion operator+(Quaternion q1, Quaternion q2); inline Quaternion operator-(Quaternion q1, Quaternion q2); @@ -958,10 +814,6 @@ inline Quaternion MakeQFromEulerAngles(float x, float y, float z); inline Vector MakeEulerAnglesFromQ(Quaternion q); - - - - inline Quaternion::Quaternion(void) { @@ -976,8 +828,6 @@ inline Quaternion::Quaternion(void) } - - inline Quaternion::Quaternion(float e0, float e1, float e2, float e3) { @@ -992,8 +842,6 @@ inline Quaternion::Quaternion(float e0, float e1, float e2, float e3) } - - inline float Quaternion::Magnitude(void) { @@ -1002,8 +850,6 @@ inline float Quaternion::Magnitude(void) } - - inline Vector Quaternion::GetVector(void) { @@ -1012,8 +858,6 @@ inline Vector Quaternion::GetVector(void) } - - inline float Quaternion::GetScalar(void) { @@ -1022,8 +866,6 @@ inline float Quaternion::GetScalar(void) } - - inline Quaternion Quaternion::operator+=(Quaternion q) { @@ -1040,8 +882,6 @@ inline Quaternion Quaternion::operator+=(Quaternion q) } - - inline Quaternion Quaternion::operator-=(Quaternion q) { @@ -1058,8 +898,6 @@ inline Quaternion Quaternion::operator-=(Quaternion q) } - - inline Quaternion Quaternion::operator*=(float s) { @@ -1076,8 +914,6 @@ inline Quaternion Quaternion::operator*=(float s) } - - inline Quaternion Quaternion::operator/=(float s) { @@ -1094,8 +930,6 @@ inline Quaternion Quaternion::operator/=(float s) } - - /*inline Quaternion Quaternion::operator~() { @@ -1104,8 +938,6 @@ inline Quaternion Quaternion::operator/=(float s) }*/ - - inline Quaternion operator+(Quaternion q1, Quaternion q2) { @@ -1120,8 +952,6 @@ inline Quaternion operator+(Quaternion q1, Quaternion q2) } - - inline Quaternion operator-(Quaternion q1, Quaternion q2) { @@ -1136,8 +966,6 @@ inline Quaternion operator-(Quaternion q1, Quaternion q2) } - - inline Quaternion operator*(Quaternion q1, Quaternion q2) { @@ -1148,12 +976,10 @@ inline Quaternion operator*(Quaternion q1, Quaternion q2) q1.n*q2.v.y + q1.v.y*q2.n + q1.v.z*q2.v.x - q1.v.x*q2.v.z, - q1.n*q2.v.z + q1.v.z*q2.n + q1.v.x*q2.v.y - q1.v.y*q2.v.x); + q1.n*q2.v.z + q1.v.z*q2.n + q1.v.x*q2.v.y - q1.v.y*q2.v.x); } - - inline Quaternion operator*(Quaternion q, float s) { @@ -1162,8 +988,6 @@ inline Quaternion operator*(Quaternion q, float s) } - - inline Quaternion operator*(float s, Quaternion q) { @@ -1172,8 +996,6 @@ inline Quaternion operator*(float s, Quaternion q) } - - inline Quaternion operator*(Quaternion q, Vector v) { @@ -1188,8 +1010,6 @@ inline Quaternion operator*(Quaternion q, Vector v) } - - inline Quaternion operator*(Vector v, Quaternion q) { @@ -1204,8 +1024,6 @@ inline Quaternion operator*(Vector v, Quaternion q) } - - inline Quaternion operator/(Quaternion q, float s) { @@ -1214,8 +1032,6 @@ inline Quaternion operator/(Quaternion q, float s) } - - inline float QGetAngle(Quaternion q) { @@ -1224,8 +1040,6 @@ inline float QGetAngle(Quaternion q) } - - inline Vector QGetAxis(Quaternion q) { @@ -1234,26 +1048,20 @@ inline Vector QGetAxis(Quaternion q) float m; - - v = q.GetVector(); m = v.Magnitude(); - - if (m <= tol) return Vector(); else - return v/m; + return v/m; } - - inline Quaternion QRotate(Quaternion q1, Quaternion q2) { @@ -1262,28 +1070,18 @@ inline Quaternion QRotate(Quaternion q1, Quaternion q2) } - - inline Vector QVRotate(Quaternion q, Vector v) { Quaternion t; - - - - t = q*v*(~q); - - return t.GetVector(); } - - inline Quaternion MakeQFromEulerAngles(float x, float y, float z) { @@ -1296,14 +1094,10 @@ inline Quaternion MakeQFromEulerAngles(float x, float y, float z) double yaw = DegreesToRadians(z); - - double cyaw, cpitch, croll, syaw, spitch, sroll; double cyawcpitch, syawspitch, cyawspitch, syawcpitch; - - cyaw = cos(0.5f * yaw); cpitch = cos(0.5f * pitch); @@ -1316,8 +1110,6 @@ inline Quaternion MakeQFromEulerAngles(float x, float y, float z) sroll = sin(0.5f * roll); - - cyawcpitch = cyaw*cpitch; syawspitch = syaw*spitch; @@ -1326,24 +1118,18 @@ inline Quaternion MakeQFromEulerAngles(float x, float y, float z) syawcpitch = syaw*cpitch; - - q.n = (float) (cyawcpitch * croll + syawspitch * sroll); - q.v.x = (float) (cyawcpitch * sroll - syawspitch * croll); + q.v.x = (float) (cyawcpitch * sroll - syawspitch * croll); q.v.y = (float) (cyawspitch * croll + syawcpitch * sroll); q.v.z = (float) (syawcpitch * croll - cyawspitch * sroll); - - return q; } - - inline Vector MakeEulerAnglesFromQ(Quaternion q) { @@ -1356,8 +1142,6 @@ inline Vector MakeEulerAnglesFromQ(Quaternion q) Vector u; - - q00 = q.n * q.n; q11 = q.v.x * q.v.x; @@ -1366,8 +1150,6 @@ inline Vector MakeEulerAnglesFromQ(Quaternion q) q33 = q.v.z * q.v.z; - - r11 = q00 + q11 - q22 - q33; r21 = 2 * (q.v.x*q.v.y + q.n*q.v.z); @@ -1378,8 +1160,6 @@ inline Vector MakeEulerAnglesFromQ(Quaternion q) r33 = q00 - q11 - q22 + q33; - - tmp = fabs(r31); if(tmp > 0.999999) @@ -1390,8 +1170,6 @@ inline Vector MakeEulerAnglesFromQ(Quaternion q) r13 = 2 * (q.v.x*q.v.z + q.n*q.v.y); - - u.x = RadiansToDegrees(0.0f); //roll u.y = RadiansToDegrees((float) (-(pi/2) * r31/tmp)); // pitch @@ -1402,8 +1180,6 @@ inline Vector MakeEulerAnglesFromQ(Quaternion q) } - - u.x = RadiansToDegrees((float) atan2(r32, r33)); // roll u.y = RadiansToDegrees((float) asin(-r31)); // pitch @@ -1412,21 +1188,6 @@ inline Vector MakeEulerAnglesFromQ(Quaternion q) return u; - - - - } - - - - - - - - - - #endif - |