Przeglądaj źródła

Renamed MatMath and moved into utils

Thomas Buck 10 lat temu
rodzic
commit
31ca2563f6

+ 1
- 1
include/Camera.h Wyświetl plik

@@ -7,7 +7,7 @@
7 7
 #ifndef _CAMERA_H_
8 8
 #define _CAMERA_H_
9 9
 
10
-#include "MatMath.h"
10
+#include "utils/math.h"
11 11
 #include "Matrix.h"
12 12
 #include "Quaternion.h"
13 13
 

+ 1
- 1
include/Matrix.h Wyświetl plik

@@ -8,7 +8,7 @@
8 8
 #ifndef _MATRIX_H_
9 9
 #define _MATRIX_H_
10 10
 
11
-#include "MatMath.h"
11
+#include "utils/math.h"
12 12
 #include "Quaternion.h"
13 13
 #include "Vector3d.h"
14 14
 

+ 8
- 8
include/Mesh.h Wyświetl plik

@@ -10,7 +10,7 @@
10 10
 #ifndef _OPENGLMESH_H_
11 11
 #define _OPENGLMESH_H_
12 12
 
13
-#include "MatMath.h"
13
+#include "utils/math.h"
14 14
 
15 15
 /*!
16 16
  * \brief OpenGL Mesh
@@ -29,7 +29,7 @@ public:
29 29
         fMesh_UseVertexArray = (1 << 0)
30 30
     } MeshFlags;
31 31
 
32
-    typedef struct tris_s {
32
+    typedef struct {
33 33
         int texture;
34 34
 #ifdef MULTITEXTURE
35 35
         int bumpmap;
@@ -53,7 +53,7 @@ public:
53 53
         unsigned int *alpha_triangles; //!< ABCABCABC...
54 54
     } tris_t;
55 55
 
56
-    typedef struct rect_s {
56
+    typedef struct {
57 57
 
58 58
         int texture;
59 59
 #ifdef MULTITEXTURE
@@ -108,8 +108,8 @@ public:
108 108
     void bufferNormalArray(unsigned int normalCount, vec_t *normals);
109 109
 
110 110
     void bufferTriangles(unsigned int count,
111
-                                unsigned int *indices, vec_t *texCoords,
112
-                                int *textures, unsigned int *flags);
111
+                            unsigned int *indices, vec_t *texCoords,
112
+                            int *textures, unsigned int *flags);
113 113
 
114 114
     void bufferVertexArray(unsigned int vertexCount, vec_t *vertices);
115 115
 
@@ -125,11 +125,11 @@ public:
125 125
     void sortFacesByTexture();
126 126
 
127 127
     void addFace(int textureIndex, int textureIndexB, unsigned int flags,
128
-                     unsigned int vertexIndexCount, vec_t *vertexIndices);
128
+                    unsigned int vertexIndexCount, vec_t *vertexIndices);
129 129
 
130 130
     void addTexTiledFace(int textureIndex, int textureIndexB,
131
-                                unsigned int flags, unsigned int indexCount,
132
-                                vec_t *vertexIndices, vec_t *texcoords);
131
+                            unsigned int flags, unsigned int indexCount,
132
+                            vec_t *vertexIndices, vec_t *texcoords);
133 133
 
134 134
     void bufferTexcoords(unsigned int texcoordCount, vec_t *texcoords);
135 135
 

+ 1
- 1
include/Particle.h Wyświetl plik

@@ -8,7 +8,7 @@
8 8
 #ifndef _PARTICLE_H_
9 9
 #define _PARTICLE_H_
10 10
 
11
-#include "MatMath.h"
11
+#include "utils/math.h"
12 12
 
13 13
 /*!
14 14
  * \brief Partcle systems atomic base

+ 1
- 1
include/Quaternion.h Wyświetl plik

@@ -8,7 +8,7 @@
8 8
 #ifndef _QUATERNION_H_
9 9
 #define _QUATERNION_H_
10 10
 
11
-#include "MatMath.h"
11
+#include "utils/math.h"
12 12
 
13 13
 /*!
14 14
  * \brief Quaternion

+ 0
- 1
include/Render.h Wyświetl plik

@@ -17,7 +17,6 @@
17 17
 #include "Texture.h"
18 18
 #include "Camera.h"
19 19
 #include "GLString.h"
20
-#include "templates/List.h"
21 20
 #include "templates/Vector.h"
22 21
 
23 22
 #ifdef USING_EMITTER

+ 1
- 1
include/SkeletalModel.h Wyświetl plik

@@ -12,7 +12,7 @@
12 12
 #ifndef _SKELETALMODEL_H_
13 13
 #define _SKELETALMODEL_H_
14 14
 
15
-#include "MatMath.h"
15
+#include "utils/math.h"
16 16
 #include "templates/Vector.h"
17 17
 
18 18
 typedef struct {

+ 1
- 1
include/Vector3d.h Wyświetl plik

@@ -8,7 +8,7 @@
8 8
 #ifndef _VECTOR3D_H_
9 9
 #define _VECTOR3D_H_
10 10
 
11
-#include "MatMath.h"
11
+#include "utils/math.h"
12 12
 
13 13
 /*!
14 14
  * \brief 3D Math Vector

+ 1
- 1
include/World.h Wyświetl plik

@@ -14,7 +14,7 @@
14 14
 #include "SkeletalModel.h"
15 15
 #endif
16 16
 
17
-#include "MatMath.h"
17
+#include "utils/math.h"
18 18
 #include "templates/List.h"
19 19
 #include "templates/Vector.h"
20 20
 

include/MatMath.h → include/utils/math.h Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 /*!
2 2
  *
3
- * \file include/MatMath.h
3
+ * \file include/utils/math.h
4 4
  * \brief Vector and Matrix math
5 5
  *
6 6
  * \author Mongoose
@@ -27,16 +27,6 @@ typedef float vec4_t[4];    //!< 4D Vector
27 27
 typedef vec_t matrix_t[16]; //!< Used as _Column_major_ in every class now!
28 28
 
29 29
 /*!
30
- * \fixme Add Documentation or remove, as it is unused?
31
- */
32
-vec_t helIntersectionOfAbstractSpheres(vec3_t centerA, vec_t radiusA, vec3_t centerB, vec_t radiusB);
33
-
34
-/*!
35
- * \fixme Add Documentation or remove, as it is unused?
36
- */
37
-int helIntersectionOfAbstractSphereAndLine(vec3_t center, vec_t radius, vec3_t posA, vec3_t posB, vec3_t intersectionA, vec3_t intersectionB);
38
-
39
-/*!
40 30
  * \brief Compare two floats with an Epsilon.
41 31
  * \param a first float
42 32
  * \param b second float

+ 1
- 1
include/utils/strings.h Wyświetl plik

@@ -48,6 +48,6 @@ bool rc_command(const char *symbol, char *command);
48 48
  * \param val is set to boolean interpretation of buffer
49 49
  * \returns -1 for null string, -2 if string is not "true" or "false"
50 50
  */
51
-int rc_get_bool(char *buffer, bool *val);
51
+int rc_get_bool(const char *buffer, bool *val);
52 52
 
53 53
 #endif

+ 5
- 4
include/utils/tga.h Wyświetl plik

@@ -60,7 +60,7 @@ int tga_check(FILE *f);
60 60
  * \returns 0 on success, else error condition
61 61
  */
62 62
 int tga_load(FILE *f, unsigned char **image,
63
-        unsigned int *width, unsigned int *height, char *type);
63
+                unsigned int *width, unsigned int *height, char *type);
64 64
 
65 65
 /*!
66 66
  * \brief Save a pixel buffer into a file on disk
@@ -72,7 +72,7 @@ int tga_load(FILE *f, unsigned char **image,
72 72
  * \returns 0 on success, else error condition
73 73
  */
74 74
 int tga_save(FILE *f, unsigned char *image,
75
-        unsigned int width, unsigned int height, char type);
75
+                unsigned int width, unsigned int height, char type);
76 76
 
77 77
 /*!
78 78
  * \brief Save a pixel buffer into a file on disk
@@ -84,7 +84,8 @@ int tga_save(FILE *f, unsigned char *image,
84 84
  * \returns 0 on success, else error condition
85 85
  */
86 86
 int tga_save_filename(unsigned char *image,
87
-        unsigned int width, unsigned int height,
88
-        char type, char *s, ...) __attribute__((format(printf, 5, 6)));
87
+                        unsigned int width, unsigned int height,
88
+                        char type, char *s, ...)
89
+    __attribute__((format(printf, 5, 6)));
89 90
 
90 91
 #endif

+ 0
- 1
src/CMakeLists.txt Wyświetl plik

@@ -2,7 +2,6 @@
2 2
 set (SRCS ${SRCS} "Camera.cpp")
3 3
 set (SRCS ${SRCS} "Emitter.cpp")
4 4
 set (SRCS ${SRCS} "GLString.cpp")
5
-set (SRCS ${SRCS} "MatMath.cpp")
6 5
 set (SRCS ${SRCS} "Matrix.cpp")
7 6
 set (SRCS ${SRCS} "Mesh.cpp")
8 7
 set (SRCS ${SRCS} "Network.cpp")

+ 1
- 1
src/Camera.cpp Wyświetl plik

@@ -8,7 +8,7 @@
8 8
 #include <stdio.h>
9 9
 #include <math.h>
10 10
 
11
-#include "MatMath.h"
11
+#include "utils/math.h"
12 12
 #include "Camera.h"
13 13
 
14 14
 unsigned int Camera::mCounter = 0;

+ 1
- 1
src/Network.cpp Wyświetl plik

@@ -20,7 +20,7 @@
20 20
 #include <arpa/inet.h>
21 21
 #include <stdlib.h>
22 22
 
23
-#include "MatMath.h" // Random Number
23
+#include "utils/math.h" // Random Number
24 24
 #include "Network.h"
25 25
 
26 26
 //#define LOCAL_BCAST

+ 4
- 4
src/OpenRaider.cpp Wyświetl plik

@@ -1451,8 +1451,8 @@ void OpenRaider::processSprites()
1451 1451
 
1452 1452
 void OpenRaider::processMoveables()
1453 1453
 {
1454
-    List <unsigned int> cache;
1455
-    List <skeletal_model_t *> cache2;
1454
+    List<unsigned int> cache;
1455
+    List<skeletal_model_t *> cache2;
1456 1456
     tr2_mesh_t *mesh = NULL;
1457 1457
     tr2_moveable_t *moveable = NULL;
1458 1458
     tr2_meshtree_t *meshtree = NULL;
@@ -1568,8 +1568,8 @@ void OpenRaider::processMoveables()
1568 1568
 
1569 1569
 
1570 1570
 void OpenRaider::processMoveable(int index, int i, int *ent,
1571
-        List <skeletal_model_t *> &cache2,
1572
-        List <unsigned int> &cache, int object_id)
1571
+        List<skeletal_model_t *> &cache2,
1572
+        List<unsigned int> &cache, int object_id)
1573 1573
 {
1574 1574
     skeletal_model_t *r_model = NULL;
1575 1575
     skeletal_model_t *c_model = NULL;

+ 1
- 1
src/SDLSystem.cpp Wyświetl plik

@@ -12,7 +12,7 @@
12 12
 
13 13
 #include "SDL_opengl.h"
14 14
 
15
-#include "MatMath.h"
15
+#include "utils/math.h"
16 16
 #include "SDLSystem.h"
17 17
 
18 18
 unsigned int *gWidth = 0x0;

+ 1
- 1
src/System.cpp Wyświetl plik

@@ -28,7 +28,7 @@
28 28
 #include <sys/time.h>
29 29
 #endif
30 30
 
31
-#include "MatMath.h"
31
+#include "utils/math.h"
32 32
 #include "System.h"
33 33
 
34 34
 ////////////////////////////////////////////////////////////

+ 1
- 0
src/utils/CMakeLists.txt Wyświetl plik

@@ -1,4 +1,5 @@
1 1
 # Source files
2
+set (UTIL_SRCS ${UTIL_SRCS} "math.cpp")
2 3
 set (UTIL_SRCS ${UTIL_SRCS} "strings.cpp")
3 4
 set (UTIL_SRCS ${UTIL_SRCS} "tga.cpp")
4 5
 

src/MatMath.cpp → src/utils/math.cpp Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 /*!
2 2
  *
3
- * \file src/MatMath.cpp
3
+ * \file src/utils/math.cpp
4 4
  * \brief Vector and Matrix math
5 5
  *
6 6
  * \author Mongoose
@@ -10,9 +10,9 @@
10 10
 #include <math.h>
11 11
 #include <float.h>
12 12
 
13
-#include "MatMath.h"
14 13
 #include "Vector3d.h"
15 14
 #include "Matrix.h"
15
+#include "utils/math.h"
16 16
 
17 17
 bool equalEpsilon(vec_t a, vec_t b) {
18 18
     vec_t epsilon = FLT_EPSILON;
@@ -21,20 +21,6 @@ bool equalEpsilon(vec_t a, vec_t b) {
21 21
     return false;
22 22
 }
23 23
 
24
-vec_t helIntersectionOfAbstractSpheres(vec3_t centerA, vec_t radiusA,
25
-        vec3_t centerB, vec_t radiusB)
26
-{
27
-    Vector3d a = Vector3d(centerA);
28
-    Vector3d b = Vector3d(centerB);
29
-    Vector3d d = a - b;
30
-    vec_t dist, minDist;
31
-
32
-    dist = Vector3d::dot(d, d);
33
-    minDist = radiusA + radiusB;
34
-
35
-    return (dist <= minDist * minDist);
36
-}
37
-
38 24
 
39 25
 inline vec_t square(vec_t a)
40 26
 {
@@ -42,68 +28,6 @@ inline vec_t square(vec_t a)
42 28
 }
43 29
 
44 30
 
45
-// Returns number of intersections and intersection position(s)
46
-// Got algorithm from http://astronomy.swin.edu.au/~pbourke/geometry/
47
-int helIntersectionOfAbstractSphereAndLine(vec3_t center, vec_t radius,
48
-        vec3_t posA, vec3_t posB,
49
-        vec3_t intersectionA,
50
-        vec3_t intersectionB)
51
-{
52
-    // float x , y , z;
53
-    vec_t a, b, c, mu, i ;
54
-
55
-
56
-    a = (square(posB[0] - posA[0]) +
57
-            square(posB[1] - posA[1]) +
58
-            square(posB[2] - posA[2]));
59
-    b = (2 * ((posB[0] - posA[0]) * (posA[0] - center[0]) +
60
-                (posB[1] - posA[1]) * (posA[1] - center[1]) +
61
-                (posB[2] - posA[2]) * (posA[2] - center[2])));
62
-    c = (square(center[0]) + square(center[1]) +
63
-            square(center[2]) + square(posA[0]) +
64
-            square(posA[1]) + square(posA[2]) -
65
-            2 * (center[0]*posA[0] + center[1]*posA[1] + center[2]*posA[2]) -
66
-            square(radius));
67
-
68
-    i = b * b - 4 * a * c;
69
-
70
-
71
-    if (i < 0.0)
72
-    {
73
-        // No intersection
74
-        return 0;
75
-    }
76
-    else if (i == 0.0)
77
-    {
78
-        // One intersection
79
-        mu = -b/(2*a) ;
80
-        intersectionA[0] = posA[0] + mu*(posB[0]-posA[0]);
81
-        intersectionA[1] = posA[1] + mu*(posB[1]-posA[1]);
82
-        intersectionA[2] = posA[2] + mu*(posB[2]-posA[2]);
83
-
84
-        return 1;
85
-    }
86
-    else
87
-    {
88
-        // Two intersections
89
-
90
-        // First intersection
91
-        mu = (-b + sqrtf( square(b) - 4.0f*a*c)) / (2.0f*a);
92
-        intersectionA[0] = posA[0] + mu*(posB[0]-posA[0]);
93
-        intersectionA[1] = posA[1] + mu*(posB[1]-posA[1]);
94
-        intersectionA[2] = posA[2] + mu*(posB[2]-posA[2]);
95
-
96
-        // Second intersection
97
-        mu = (-b - sqrtf(square(b) - 4.0f*a*c)) / (2.0f*a);
98
-        intersectionB[0] = posA[0] + mu*(posB[0]-posA[0]);
99
-        intersectionB[1] = posA[1] + mu*(posB[1]-posA[1]);
100
-        intersectionB[2] = posA[2] + mu*(posB[2]-posA[2]);
101
-
102
-        return 2;
103
-    }
104
-}
105
-
106
-
107 31
 int helIntersectionLineAndPolygon(vec3_t intersect,
108 32
         vec3_t p1, vec3_t p2,
109 33
         vec3_t *polygon)

+ 1
- 1
src/utils/strings.cpp Wyświetl plik

@@ -138,7 +138,7 @@ bool rc_command(const char *symbol, char *command) {
138 138
     return false;
139 139
 }
140 140
 
141
-int rc_get_bool(char *buffer, bool *val) {
141
+int rc_get_bool(const char *buffer, bool *val) {
142 142
     if (!buffer || !buffer[0])
143 143
         return -1;
144 144
 

+ 3
- 3
test/CMakeLists.txt Wyświetl plik

@@ -52,7 +52,7 @@ set (THREADLIBS ${THREADLIBS} ${CMAKE_THREAD_LIBS_INIT})
52 52
 
53 53
 # Network Test
54 54
 set (NETWORKSRCS "${PROJECT_SOURCE_DIR}/test/Network.cpp" "${PROJECT_SOURCE_DIR}/src/Network.cpp")
55
-set (NETWORKSRCS ${NETWORKSRCS} "${PROJECT_SOURCE_DIR}/src/MatMath.cpp" "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp")
55
+set (NETWORKSRCS ${NETWORKSRCS} "${PROJECT_SOURCE_DIR}/src/utils/math.cpp" "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp")
56 56
 add_executable (NetworkTest EXCLUDE_FROM_ALL ${NETWORKSRCS})
57 57
 set_target_properties (NetworkTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
58 58
 target_link_libraries (NetworkTest m ${THREADLIBS})
@@ -60,7 +60,7 @@ target_link_libraries (NetworkTest m ${THREADLIBS})
60 60
 #################################################################
61 61
 
62 62
 # Math Test
63
-set (MATHSRCS "${PROJECT_SOURCE_DIR}/test/MatMath.cpp" "${PROJECT_SOURCE_DIR}/src/MatMath.cpp" "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp")
63
+set (MATHSRCS "${PROJECT_SOURCE_DIR}/test/math.cpp" "${PROJECT_SOURCE_DIR}/src/utils/math.cpp" "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp")
64 64
 add_executable (MathTest EXCLUDE_FROM_ALL ${MATHSRCS})
65 65
 set_target_properties (MathTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
66 66
 
@@ -68,7 +68,7 @@ set_target_properties (MathTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS}
68 68
 
69 69
 # Matrix Test
70 70
 set (MATRIXSRCS "${PROJECT_SOURCE_DIR}/test/Matrix.cpp" "${PROJECT_SOURCE_DIR}/src/Matrix.cpp")
71
-set (MATRIXSRCS ${MATRIXSRCS} "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp" "${PROJECT_SOURCE_DIR}/src/MatMath.cpp")
71
+set (MATRIXSRCS ${MATRIXSRCS} "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp" "${PROJECT_SOURCE_DIR}/src/utils/math.cpp")
72 72
 set (MATRIXSRCS ${MATRIXSRCS} "${PROJECT_SOURCE_DIR}/src/Quaternion.cpp")
73 73
 add_executable (MatrixTest EXCLUDE_FROM_ALL ${MATRIXSRCS})
74 74
 set_target_properties (MatrixTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})

test/MatMath.cpp → test/math.cpp Wyświetl plik


Ładowanie…
Anuluj
Zapisz