Ver código fonte

Renamed Vector3d to Vec3, added math unit test

Thomas Buck 10 anos atrás
pai
commit
fc4324ff3f

+ 4
- 0
ChangeLog.md Ver arquivo

@@ -2,6 +2,10 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20141203 ]
6
+    * Renamed Vector3d to Vec3, small cleanup
7
+    * Added preliminary math unit test
8
+
5 9
     [ 20141202 ]
6 10
     * No longer crashing when LoaderTR2 does not find an SFX file
7 11
     * LoaderTR2 now loads level-wide Sprites (no Room Sprites yet)

+ 4
- 4
include/Sprite.h Ver arquivo

@@ -21,10 +21,10 @@ class Sprite {
21 21
 
22 22
     Sprite(TombRaider& tr, unsigned int item, unsigned int sequence, unsigned int index) :
23 23
         Sprite((tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->tile,
24
-        (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->x,
25
-        (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->y,
26
-        (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->width,
27
-        (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->height) { }
24
+               (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->x,
25
+               (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->y,
26
+               (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->width,
27
+               (tr.Sprite() + ((tr.SpriteSequence() + sequence)->offset) + index)->height) { }
28 28
 
29 29
     void display();
30 30
     void display(float x, float y, float w, float h);

+ 2
- 2
include/math/Matrix.h Ver arquivo

@@ -10,7 +10,7 @@
10 10
 
11 11
 #include "math/math.h"
12 12
 #include "math/Quaternion.h"
13
-#include "math/Vector3d.h"
13
+#include "math/Vec3.h"
14 14
 
15 15
 
16 16
 /*!
@@ -117,7 +117,7 @@ class Matrix {
117 117
      * \param v Vector to multiply with
118 118
      * \returns resultant vector (mult)
119 119
      */
120
-    Vector3d operator *(Vector3d v);
120
+    Vec3 operator *(Vec3 v);
121 121
 
122 122
     /*!
123 123
      * \brief Sets to identity matrix

+ 46
- 0
include/math/Vec3.h Ver arquivo

@@ -0,0 +1,46 @@
1
+/*!
2
+ * \file include/math/Vec3.h
3
+ * \brief 3D Math vector
4
+ *
5
+ * \author xythobuz
6
+ * \author Mongoose
7
+ */
8
+
9
+#ifndef _MATH_VEC3_H_
10
+#define _MATH_VEC3_H_
11
+
12
+#include "math/math.h"
13
+
14
+class Vec3 {
15
+  public:
16
+    Vec3(float _x = 0.0f, float _y = 0.0f, float _z = 0.0f);
17
+    Vec3(float v[3]);
18
+
19
+    float magnitude();
20
+    void normalize();
21
+    Vec3 unit();
22
+
23
+    Vec3 operator +(const Vec3& v);
24
+    Vec3 operator -(const Vec3& v);
25
+    Vec3 operator -();
26
+    Vec3 operator *(float s);
27
+    Vec3 operator /(float s);
28
+    float operator *(const Vec3& v);
29
+
30
+    Vec3& operator +=(const Vec3& v);
31
+    Vec3& operator -=(const Vec3& v);
32
+    Vec3& operator *=(float s);
33
+
34
+    bool operator ==(const Vec3& v);
35
+    bool operator !=(const Vec3& v);
36
+
37
+    float x, y, z;
38
+
39
+    // ----------------------------------------------------------
40
+
41
+    static float dot(const Vec3& u, const Vec3& v);
42
+    static Vec3 cross(const Vec3& u, const Vec3& v);
43
+};
44
+
45
+#endif
46
+

+ 0
- 161
include/math/Vector3d.h Ver arquivo

@@ -1,161 +0,0 @@
1
-/*!
2
- * \file include/math/Vector3d.h
3
- * \brief 3D Math vector
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _MATH_VECTOR3D_H_
9
-#define _MATH_VECTOR3D_H_
10
-
11
-#include "math/math.h"
12
-
13
-/*!
14
- * \brief 3D Math Vector
15
- */
16
-class Vector3d {
17
-  public:
18
-
19
-    /*!
20
-     * \brief Constructs an object of Vector3d
21
-     */
22
-    Vector3d();
23
-
24
-    /*!
25
-     * \brief Constructs an object of Vector3d
26
-     * \param v data to load into new Vector3d
27
-     */
28
-    Vector3d(float v[3]);
29
-
30
-    /*!
31
-     * \brief Constructs an object of Vector3d
32
-     * \param x X part of new Vector3d
33
-     * \param y Y part of new Vector3d
34
-     * \param z Z part of new Vector3d
35
-     */
36
-    Vector3d(float x, float y, float z);
37
-
38
-    /*!
39
-     * \brief Constructs an object of Vector3d
40
-     * \param v contents of new Vector3d
41
-     */
42
-    Vector3d(const Vector3d& v);
43
-
44
-    /*!
45
-     * \brief Calculate dot product
46
-     * \param u first argument
47
-     * \param v second argument
48
-     * \returns dot product of u and v vectors
49
-     */
50
-    static float dot(const Vector3d& u, const Vector3d& v);
51
-
52
-    /*!
53
-     * \brief Calculate cross product
54
-     * \param u first argument
55
-     * \param v second argument
56
-     * \returns cross product of u and v vectors
57
-     */
58
-    static Vector3d cross(const Vector3d& u, const Vector3d& v);
59
-
60
-    /*!
61
-     * \brief Get Magnitude
62
-     * \returns magnitude of this vector
63
-     */
64
-    float magnitude();
65
-
66
-    /*!
67
-     * \brief Normalize
68
-     * \returns normalized copy of this vector
69
-     */
70
-    Vector3d unit();
71
-
72
-    /*!
73
-     * \brief Get the Zero vector
74
-     * \returns (0, 0, 0) vector
75
-     */
76
-    static Vector3d zeroVector();
77
-
78
-    /*!
79
-     * \brief Add to this vector
80
-     * \param v addend
81
-     * \returns a vector = this vector + v
82
-     */
83
-    Vector3d operator +(const Vector3d& v);
84
-
85
-    /*!
86
-     * \brief Subtract from this vector
87
-     * \param v subtrahend
88
-     * \returns a vector = this vector - v
89
-     */
90
-    Vector3d operator -(const Vector3d& v);
91
-
92
-    /*!
93
-     * \brief Negate this vector
94
-     * \returns a copy of this vector, negated
95
-     */
96
-    Vector3d operator -();
97
-
98
-    /*!
99
-     * \brief Scale this vector
100
-     * \param s scaling factor
101
-     * \returns this vector multiplied with s
102
-     */
103
-    Vector3d operator *(float s);
104
-
105
-    /*!
106
-     * \brief Scale this vactor
107
-     * \param s inverse scaling factor
108
-     * \returns this vector divided by s
109
-     */
110
-    Vector3d operator /(float s);
111
-
112
-    /*!
113
-     * \brief Dot product this vector
114
-     * \param v second vector for dot product
115
-     * \returns dot product of V by this vector
116
-     */
117
-    float operator *(const Vector3d& v);
118
-
119
-    /*!
120
-     * \brief Normalizes this vector
121
-     */
122
-    void normalize();
123
-
124
-    /*!
125
-     * \brief Set this vector to Zero (0, 0, 0)
126
-     */
127
-    void zero();
128
-
129
-    /*!
130
-     * \brief Set this vector
131
-     * \param v what this vector will be set to
132
-     * \returns this vector, now equal to v
133
-     */
134
-    Vector3d& operator =(const Vector3d& v);
135
-
136
-    /*!
137
-     * \brief Add to this vector, in place
138
-     * \param v what will be added to this vector
139
-     * \returns this vector, with v added
140
-     */
141
-    Vector3d& operator +=(const Vector3d& v);
142
-
143
-    /*!
144
-     * \brief Subtract from this vector, in place
145
-     * \param v what will be subtracted from this vector
146
-     * \returns this vector, with v subtracted
147
-     */
148
-    Vector3d& operator -=(const Vector3d& v);
149
-
150
-    /*!
151
-     * \brief Scale this vector, in place
152
-     * \param s scaling factor
153
-     * \returns this vactor multiplied by s
154
-     */
155
-    Vector3d& operator *=(float s);
156
-
157
-    float mVec[3]; //!< Vector data
158
-};
159
-
160
-#endif
161
-

+ 2
- 1
src/Render.cpp Ver arquivo

@@ -562,7 +562,8 @@ void Render::debugDisplaySprite(int sprite, int offset, float x, float y, float
562 562
     debugTextile = -1;
563 563
 }
564 564
 
565
-void Render::drawSprite(float x, float y, float w, float h, unsigned int sprite, unsigned int offset) {
565
+void Render::drawSprite(float x, float y, float w, float h, unsigned int sprite,
566
+                        unsigned int offset) {
566 567
     glColor3ubv(WHITE);
567 568
 
568 569
     if (mFlags & Render::fGL_Lights)

+ 4
- 4
src/loader/LoaderTR2.cpp Ver arquivo

@@ -694,7 +694,7 @@ void LoaderTR2::loadBoxesOverlapsZones() {
694 694
     // TODO store zones somewhere
695 695
 
696 696
     if ((numBoxes > 0) || (numOverlaps > 0))
697
-        getLog() << "LoaderTR2: Found NPC NavigationHints, not yet implemented!" << Log::endl;
697
+        getLog() << "LoaderTR2: Found NPC NavigationHints, unimplemented!" << Log::endl;
698 698
 }
699 699
 
700 700
 // ---- Sound ----
@@ -800,7 +800,7 @@ void LoaderTR2::loadExternalSoundFile(std::string f) {
800 800
     }
801 801
 
802 802
     if (riffCount > 0)
803
-        getLog() << "LoaderTR2: Found " << riffCount << " SoundSamples" << Log::endl;
803
+        getLog() << "LoaderTR2: Found " << riffCount << " SoundSamples in SFX" << Log::endl;
804 804
 }
805 805
 
806 806
 // ---- Stuff ----
@@ -839,7 +839,7 @@ void LoaderTR2::loadCinematicFrames() {
839 839
 
840 840
     if (numCinematicFrames > 0)
841 841
         getLog() << "LoaderTR2: Found " << numCinematicFrames
842
-                 << " CinematicFrames, not yet implemented!" << Log::endl;
842
+                 << " CinematicFrames, unimplemented!" << Log::endl;
843 843
 }
844 844
 
845 845
 void LoaderTR2::loadDemoData() {
@@ -849,7 +849,7 @@ void LoaderTR2::loadDemoData() {
849 849
 
850 850
     // TODO store demo data somewhere, find out meaning
851 851
     if (numDemoData > 0)
852
-        getLog() << "LoaderTR2: Found " << numDemoData << " bytes DemoData, not yet implemented!" <<
852
+        getLog() << "LoaderTR2: Found " << numDemoData << " bytes DemoData, unimplemented!" <<
853 853
                  Log::endl;
854 854
 }
855 855
 

+ 1
- 1
src/math/CMakeLists.txt Ver arquivo

@@ -2,7 +2,7 @@
2 2
 set (MATH_SRCS ${MATH_SRCS} "math.cpp")
3 3
 set (MATH_SRCS ${MATH_SRCS} "Matrix.cpp")
4 4
 set (MATH_SRCS ${MATH_SRCS} "Quaternion.cpp")
5
-set (MATH_SRCS ${MATH_SRCS} "Vector3d.cpp")
5
+set (MATH_SRCS ${MATH_SRCS} "Vec3.cpp")
6 6
 
7 7
 # Add library
8 8
 add_library (OpenRaider_math OBJECT ${MATH_SRCS})

+ 8
- 8
src/math/Matrix.cpp Ver arquivo

@@ -177,17 +177,17 @@ Matrix Matrix::operator *(const Matrix& a) {
177 177
     return multiply(a, *this);
178 178
 }
179 179
 
180
-Vector3d Matrix::operator *(Vector3d v) {
181
-    float x = v.mVec[0], y = v.mVec[1], z = v.mVec[2];
180
+Vec3 Matrix::operator *(Vec3 v) {
181
+    float x = v.x, y = v.y, z = v.z;
182 182
 
183 183
 #ifdef COLUMN_ORDER
184
-    return Vector3d(mMatrix[0] * x + mMatrix[4] * y + mMatrix[ 8] * z + mMatrix[12],
185
-                    mMatrix[1] * x + mMatrix[5] * y + mMatrix[ 9] * z + mMatrix[13],
186
-                    mMatrix[2] * x + mMatrix[6] * y + mMatrix[10] * z + mMatrix[14]);
184
+    return Vec3(mMatrix[0] * x + mMatrix[4] * y + mMatrix[ 8] * z + mMatrix[12],
185
+                mMatrix[1] * x + mMatrix[5] * y + mMatrix[ 9] * z + mMatrix[13],
186
+                mMatrix[2] * x + mMatrix[6] * y + mMatrix[10] * z + mMatrix[14]);
187 187
 #else
188
-    return Vector3d(mMatrix[0] * x + mMatrix[1] * y + mMatrix[ 2] * z + mMatrix[ 3],
189
-                    mMatrix[4] * x + mMatrix[5] * y + mMatrix[ 6] * z + mMatrix[ 7],
190
-                    mMatrix[8] * x + mMatrix[9] * y + mMatrix[10] * z + mMatrix[11]);
188
+    return Vec3(mMatrix[0] * x + mMatrix[1] * y + mMatrix[ 2] * z + mMatrix[ 3],
189
+                mMatrix[4] * x + mMatrix[5] * y + mMatrix[ 6] * z + mMatrix[ 7],
190
+                mMatrix[8] * x + mMatrix[9] * y + mMatrix[10] * z + mMatrix[11]);
191 191
 #endif
192 192
 }
193 193
 

+ 118
- 0
src/math/Vec3.cpp Ver arquivo

@@ -0,0 +1,118 @@
1
+/*!
2
+ * \file src/math/Vec3.cpp
3
+ * \brief 3D Math vector
4
+ *
5
+ * \author Mongoose
6
+ */
7
+
8
+#include <math.h>
9
+
10
+#include "global.h"
11
+#include "math/Vec3.h"
12
+
13
+Vec3::Vec3(float _x, float _y, float _z) {
14
+    x = _x;
15
+    y = _y;
16
+    z = _z;
17
+}
18
+
19
+Vec3::Vec3(float v[3]) {
20
+    assert(v != nullptr);
21
+    x = v[0];
22
+    y = v[1];
23
+    z = v[2];
24
+}
25
+
26
+float Vec3::magnitude() {
27
+    return sqrtf(x * x + y * y + z * z);
28
+}
29
+
30
+void Vec3::normalize() {
31
+    float norm = magnitude();
32
+    x /= norm;
33
+    y /= norm;
34
+    z /= norm;
35
+}
36
+
37
+Vec3 Vec3::unit() {
38
+    float norm = magnitude();
39
+    return Vec3(x / norm,
40
+                y / norm,
41
+                z / norm);
42
+}
43
+
44
+Vec3 Vec3::operator +(const Vec3& v) {
45
+    return Vec3(x + v.x,
46
+                y + v.y,
47
+                z + v.z);
48
+}
49
+
50
+Vec3 Vec3::operator -(const Vec3& v) {
51
+    return Vec3(x - v.x,
52
+                y - v.y,
53
+                z - v.z);
54
+}
55
+
56
+Vec3 Vec3::operator -() {
57
+    return Vec3(-x,
58
+                -y,
59
+                -z);
60
+}
61
+
62
+Vec3 Vec3::operator *(float s) {
63
+    return Vec3(s * x,
64
+                s * y,
65
+                s * z);
66
+}
67
+
68
+Vec3 Vec3::operator /(float s) {
69
+    return Vec3(x / s,
70
+                y / s,
71
+                z / s);
72
+}
73
+
74
+float Vec3::operator *(const Vec3& v) {
75
+    return dot(*this, v);
76
+}
77
+
78
+Vec3& Vec3::operator +=(const Vec3& v) {
79
+    x += v.x;
80
+    y += v.y;
81
+    z += v.z;
82
+    return *this;
83
+}
84
+
85
+Vec3& Vec3::operator -=(const Vec3& v) {
86
+    x -= v.x;
87
+    y -= v.y;
88
+    z -= v.z;
89
+    return *this;
90
+}
91
+
92
+Vec3& Vec3::operator *=(float s) {
93
+    x *= s;
94
+    y *= s;
95
+    z *= s;
96
+    return *this;
97
+}
98
+
99
+bool Vec3::operator ==(const Vec3& v) {
100
+    return equalEpsilon(x, v.x)
101
+        && equalEpsilon(y, v.y)
102
+        && equalEpsilon(z, v.z);
103
+}
104
+
105
+bool Vec3::operator !=(const Vec3& v) {
106
+    return !((*this) == v);
107
+}
108
+
109
+float Vec3::dot(const Vec3& u, const Vec3& v) {
110
+    return (u.x * v.x + u.y * v.y + u.z * v.z);
111
+}
112
+
113
+Vec3 Vec3::cross(const Vec3& u, const Vec3& v) {
114
+    return Vec3(u.y * v.z - u.z * v.y,
115
+                u.z * v.x - u.x * v.z,
116
+                u.x * v.y - u.y * v.x);
117
+}
118
+

+ 0
- 136
src/math/Vector3d.cpp Ver arquivo

@@ -1,136 +0,0 @@
1
-/*!
2
- * \file src/math/Vector3d.cpp
3
- * \brief 3D Math vector
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <math.h>
9
-
10
-#include "global.h"
11
-#include "math/Vector3d.h"
12
-
13
-Vector3d::Vector3d() {
14
-    mVec[0] = mVec[1] = mVec[2] = 0.0f;
15
-}
16
-
17
-Vector3d::Vector3d(float v[3]) {
18
-    mVec[0] = v[0];
19
-    mVec[1] = v[1];
20
-    mVec[2] = v[2];
21
-}
22
-
23
-Vector3d::Vector3d(float x, float y, float z) {
24
-    mVec[0] = x;
25
-    mVec[1] = y;
26
-    mVec[2] = z;
27
-}
28
-
29
-Vector3d::Vector3d(const Vector3d& v) {
30
-    mVec[0] = v.mVec[0];
31
-    mVec[1] = v.mVec[1];
32
-    mVec[2] = v.mVec[2];
33
-}
34
-
35
-float Vector3d::dot(const Vector3d& u, const Vector3d& v) {
36
-    return (u.mVec[0] * v.mVec[0] + u.mVec[1] * v.mVec[1] + u.mVec[2] * v.mVec[2]);
37
-}
38
-
39
-Vector3d Vector3d::cross(const Vector3d& u, const Vector3d& v) {
40
-    return Vector3d(u.mVec[1] * v.mVec[2] - u.mVec[2] * v.mVec[1],
41
-                    u.mVec[2] * v.mVec[0] - u.mVec[0] * v.mVec[2],
42
-                    u.mVec[0] * v.mVec[1] - u.mVec[1] * v.mVec[0]);
43
-}
44
-
45
-float Vector3d::magnitude() {
46
-    return sqrtf(mVec[0] * mVec[0] + mVec[1] * mVec[1] + mVec[2] * mVec[2]);
47
-}
48
-
49
-Vector3d Vector3d::unit() {
50
-    float norm = magnitude();
51
-
52
-    return Vector3d(mVec[0] / norm,
53
-                    mVec[1] / norm,
54
-                    mVec[2] / norm);
55
-}
56
-
57
-Vector3d Vector3d::zeroVector() {
58
-    return Vector3d(0, 0, 0);
59
-}
60
-
61
-Vector3d Vector3d::operator +(const Vector3d& v) {
62
-    return Vector3d(mVec[0] + v.mVec[0],
63
-                    mVec[1] + v.mVec[1],
64
-                    mVec[2] + v.mVec[2]);
65
-}
66
-
67
-Vector3d Vector3d::operator -(const Vector3d& v) {
68
-    return Vector3d(mVec[0] - v.mVec[0],
69
-                    mVec[1] - v.mVec[1],
70
-                    mVec[2] - v.mVec[2]);
71
-}
72
-
73
-Vector3d Vector3d::operator -() {
74
-    return Vector3d(-mVec[0],
75
-                    -mVec[1],
76
-                    -mVec[2]);
77
-}
78
-
79
-Vector3d Vector3d::operator *(float s) {
80
-    return Vector3d(s * mVec[0],
81
-                    s * mVec[1],
82
-                    s * mVec[2]);
83
-}
84
-
85
-Vector3d Vector3d::operator /(float s) {
86
-    return Vector3d(mVec[0] / s,
87
-                    mVec[1] / s,
88
-                    mVec[2] / s);
89
-}
90
-
91
-float Vector3d::operator *(const Vector3d& v) {
92
-    return dot(*this, v);
93
-}
94
-
95
-void Vector3d::normalize() {
96
-    float norm = magnitude();
97
-
98
-    mVec[0] /= norm;
99
-    mVec[1] /= norm;
100
-    mVec[2] /= norm;
101
-}
102
-
103
-void Vector3d::zero() {
104
-    mVec[0] = 0;
105
-    mVec[1] = 0;
106
-    mVec[2] = 0;
107
-}
108
-
109
-Vector3d& Vector3d::operator =(const Vector3d& v) {
110
-    mVec[0] = v.mVec[0];
111
-    mVec[1] = v.mVec[1];
112
-    mVec[2] = v.mVec[2];
113
-    return *this;
114
-}
115
-
116
-Vector3d& Vector3d::operator +=(const Vector3d& v) {
117
-    mVec[0] += v.mVec[0];
118
-    mVec[1] += v.mVec[1];
119
-    mVec[2] += v.mVec[2];
120
-    return *this;
121
-}
122
-
123
-Vector3d& Vector3d::operator -=(const Vector3d& v) {
124
-    mVec[0] -= v.mVec[0];
125
-    mVec[1] -= v.mVec[1];
126
-    mVec[2] -= v.mVec[2];
127
-    return *this;
128
-}
129
-
130
-Vector3d& Vector3d::operator *=(float s) {
131
-    mVec[0] *= s;
132
-    mVec[1] *= s;
133
-    mVec[2] *= s;
134
-    return *this;
135
-}
136
-

+ 16
- 16
src/math/math.cpp Ver arquivo

@@ -13,7 +13,7 @@
13 13
 #include <algorithm>
14 14
 
15 15
 #include "global.h"
16
-#include "math/Vector3d.h"
16
+#include "math/Vec3.h"
17 17
 #include "math/Matrix.h"
18 18
 #include "math/math.h"
19 19
 
@@ -29,46 +29,46 @@ int intersectionLinePolygon(float intersect[3],
29 29
     assert(polygon != NULL);
30 30
 
31 31
     // float normal[3], a[3], b[3];
32
-    Vector3d a, b, normal, pA, pB;
32
+    Vec3 a, b, normal, pA, pB;
33 33
     float d, denominator, mu;
34 34
 
35 35
 
36
-    pA = Vector3d(p1);
37
-    pB = Vector3d(p2);
36
+    pA = Vec3(p1);
37
+    pB = Vec3(p2);
38 38
 
39 39
     // Find normal
40
-    a = Vector3d(polygon[1]) - Vector3d(polygon[0]);
41
-    b = Vector3d(polygon[2]) - Vector3d(polygon[0]);
42
-    normal = Vector3d::cross(a, b);
40
+    a = Vec3(polygon[1]) - Vec3(polygon[0]);
41
+    b = Vec3(polygon[2]) - Vec3(polygon[0]);
42
+    normal = Vec3::cross(a, b);
43 43
     normal.normalize();
44 44
 
45 45
     // find D
46
-    d = (normal.mVec[0] * polygon[0][0] -
47
-         normal.mVec[1] * polygon[0][1] -
48
-         normal.mVec[2] * polygon[0][2]);
46
+    d = (normal.x * polygon[0][0] -
47
+         normal.y * polygon[0][1] -
48
+         normal.z * polygon[0][2]);
49 49
 
50 50
     // line segment parallel to plane?
51 51
     a = pB - pA;
52 52
 
53
-    denominator = Vector3d::dot(normal, a);
53
+    denominator = Vec3::dot(normal, a);
54 54
 
55 55
     if (denominator > 0.0)
56 56
         return 0;
57 57
 
58 58
     // Line segment contains intercept point?
59
-    mu = -((d + Vector3d::dot(normal, pA)) / denominator);
59
+    mu = -((d + Vec3::dot(normal, pA)) / denominator);
60 60
 
61 61
     if (mu < 0.0 || mu > 1.0)
62 62
         return 0;
63 63
 
64 64
     b = pA + (a * mu);
65
-    intersect[0] = b.mVec[0];
66
-    intersect[1] = b.mVec[1];
67
-    intersect[2] = b.mVec[2];
65
+    intersect[0] = b.x;
66
+    intersect[1] = b.y;
67
+    intersect[2] = b.z;
68 68
 
69 69
     // See if the intercept is bound by polygon by winding number
70 70
     // assume convex polygons here for sure
71
-    double theta = Vector3d::dot(b - Vector3d(polygon[0]), normal); // b = intersect
71
+    double theta = Vec3::dot(b - Vec3(polygon[0]), normal); // b = intersect
72 72
 
73 73
     if (theta >= 90.0) // Yeah I know
74 74
         return 0;

+ 9
- 0
test/CMakeLists.txt Ver arquivo

@@ -25,6 +25,15 @@ add_executable (tester_loader EXCLUDE_FROM_ALL
25 25
 
26 26
 #################################################################
27 27
 
28
+add_executable (tester_math EXCLUDE_FROM_ALL
29
+    "math.cpp" "../src/math/math.cpp"
30
+    "../src/math/Vec3.cpp"
31
+)
32
+add_dependencies (check tester_math)
33
+add_test (NAME test_math COMMAND tester_math)
34
+
35
+#################################################################
36
+
28 37
 add_executable (tester_script EXCLUDE_FROM_ALL
29 38
     "Script.cpp" "../src/Script.cpp" "../src/main.cpp"
30 39
     "../src/utils/binary.cpp" "../src/Exception.cpp"

+ 34
- 0
test/math.cpp Ver arquivo

@@ -0,0 +1,34 @@
1
+/*!
2
+ * \file test/math.cpp
3
+ * \brief Math Unit Test
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include <iostream>
9
+
10
+#include "global.h"
11
+#include "math/math.h"
12
+#include "math/Vec3.h"
13
+
14
+#define check(x) if (!(x)) { \
15
+    std::cout << "Test failed: " << #x << std::endl; \
16
+    return -1; \
17
+}
18
+
19
+int main() {
20
+    // math.h
21
+    check(equalEpsilon(42.23f, 42.23f));
22
+    check(!equalEpsilon(42.23f, 23.42f));
23
+
24
+    // Vec3.h
25
+    Vec3 a(42.0f, 23.0f, 66.0f);
26
+    Vec3 b(23.0f, 66.0f, 42.0f);
27
+    Vec3 result(-3390.0f, -246.0f, 2243.0f);
28
+    check(Vec3::cross(a, b) == result);
29
+
30
+    check(equalEpsilon(a * b, 5256.0f));
31
+
32
+    return 0;
33
+}
34
+

Carregando…
Cancelar
Salvar