Parcourir la source

Renamed MatMath and moved into utils

Thomas Buck il y a 10 ans
Parent
révision
31ca2563f6

+ 1
- 1
include/Camera.h Voir le fichier

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

+ 1
- 1
include/Matrix.h Voir le fichier

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

+ 8
- 8
include/Mesh.h Voir le fichier

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

+ 1
- 1
include/Particle.h Voir le fichier

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

+ 1
- 1
include/Quaternion.h Voir le fichier

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

+ 0
- 1
include/Render.h Voir le fichier

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

+ 1
- 1
include/SkeletalModel.h Voir le fichier

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

+ 1
- 1
include/Vector3d.h Voir le fichier

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

+ 1
- 1
include/World.h Voir le fichier

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

include/MatMath.h → include/utils/math.h Voir le fichier

1
 /*!
1
 /*!
2
  *
2
  *
3
- * \file include/MatMath.h
3
+ * \file include/utils/math.h
4
  * \brief Vector and Matrix math
4
  * \brief Vector and Matrix math
5
  *
5
  *
6
  * \author Mongoose
6
  * \author Mongoose
27
 typedef vec_t matrix_t[16]; //!< Used as _Column_major_ in every class now!
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
  * \brief Compare two floats with an Epsilon.
30
  * \brief Compare two floats with an Epsilon.
41
  * \param a first float
31
  * \param a first float
42
  * \param b second float
32
  * \param b second float

+ 1
- 1
include/utils/strings.h Voir le fichier

48
  * \param val is set to boolean interpretation of buffer
48
  * \param val is set to boolean interpretation of buffer
49
  * \returns -1 for null string, -2 if string is not "true" or "false"
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
 #endif
53
 #endif

+ 5
- 4
include/utils/tga.h Voir le fichier

60
  * \returns 0 on success, else error condition
60
  * \returns 0 on success, else error condition
61
  */
61
  */
62
 int tga_load(FILE *f, unsigned char **image,
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
  * \brief Save a pixel buffer into a file on disk
66
  * \brief Save a pixel buffer into a file on disk
72
  * \returns 0 on success, else error condition
72
  * \returns 0 on success, else error condition
73
  */
73
  */
74
 int tga_save(FILE *f, unsigned char *image,
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
  * \brief Save a pixel buffer into a file on disk
78
  * \brief Save a pixel buffer into a file on disk
84
  * \returns 0 on success, else error condition
84
  * \returns 0 on success, else error condition
85
  */
85
  */
86
 int tga_save_filename(unsigned char *image,
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
 #endif
91
 #endif

+ 0
- 1
src/CMakeLists.txt Voir le fichier

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

+ 1
- 1
src/Camera.cpp Voir le fichier

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

+ 1
- 1
src/Network.cpp Voir le fichier

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

+ 4
- 4
src/OpenRaider.cpp Voir le fichier

1451
 
1451
 
1452
 void OpenRaider::processMoveables()
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
     tr2_mesh_t *mesh = NULL;
1456
     tr2_mesh_t *mesh = NULL;
1457
     tr2_moveable_t *moveable = NULL;
1457
     tr2_moveable_t *moveable = NULL;
1458
     tr2_meshtree_t *meshtree = NULL;
1458
     tr2_meshtree_t *meshtree = NULL;
1568
 
1568
 
1569
 
1569
 
1570
 void OpenRaider::processMoveable(int index, int i, int *ent,
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
     skeletal_model_t *r_model = NULL;
1574
     skeletal_model_t *r_model = NULL;
1575
     skeletal_model_t *c_model = NULL;
1575
     skeletal_model_t *c_model = NULL;

+ 1
- 1
src/SDLSystem.cpp Voir le fichier

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

+ 1
- 1
src/System.cpp Voir le fichier

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

+ 1
- 0
src/utils/CMakeLists.txt Voir le fichier

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

src/MatMath.cpp → src/utils/math.cpp Voir le fichier

1
 /*!
1
 /*!
2
  *
2
  *
3
- * \file src/MatMath.cpp
3
+ * \file src/utils/math.cpp
4
  * \brief Vector and Matrix math
4
  * \brief Vector and Matrix math
5
  *
5
  *
6
  * \author Mongoose
6
  * \author Mongoose
10
 #include <math.h>
10
 #include <math.h>
11
 #include <float.h>
11
 #include <float.h>
12
 
12
 
13
-#include "MatMath.h"
14
 #include "Vector3d.h"
13
 #include "Vector3d.h"
15
 #include "Matrix.h"
14
 #include "Matrix.h"
15
+#include "utils/math.h"
16
 
16
 
17
 bool equalEpsilon(vec_t a, vec_t b) {
17
 bool equalEpsilon(vec_t a, vec_t b) {
18
     vec_t epsilon = FLT_EPSILON;
18
     vec_t epsilon = FLT_EPSILON;
21
     return false;
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
 inline vec_t square(vec_t a)
25
 inline vec_t square(vec_t a)
40
 {
26
 {
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
 int helIntersectionLineAndPolygon(vec3_t intersect,
31
 int helIntersectionLineAndPolygon(vec3_t intersect,
108
         vec3_t p1, vec3_t p2,
32
         vec3_t p1, vec3_t p2,
109
         vec3_t *polygon)
33
         vec3_t *polygon)

+ 1
- 1
src/utils/strings.cpp Voir le fichier

138
     return false;
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
     if (!buffer || !buffer[0])
142
     if (!buffer || !buffer[0])
143
         return -1;
143
         return -1;
144
 
144
 

+ 3
- 3
test/CMakeLists.txt Voir le fichier

52
 
52
 
53
 # Network Test
53
 # Network Test
54
 set (NETWORKSRCS "${PROJECT_SOURCE_DIR}/test/Network.cpp" "${PROJECT_SOURCE_DIR}/src/Network.cpp")
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
 add_executable (NetworkTest EXCLUDE_FROM_ALL ${NETWORKSRCS})
56
 add_executable (NetworkTest EXCLUDE_FROM_ALL ${NETWORKSRCS})
57
 set_target_properties (NetworkTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
57
 set_target_properties (NetworkTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
58
 target_link_libraries (NetworkTest m ${THREADLIBS})
58
 target_link_libraries (NetworkTest m ${THREADLIBS})
60
 #################################################################
60
 #################################################################
61
 
61
 
62
 # Math Test
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
 add_executable (MathTest EXCLUDE_FROM_ALL ${MATHSRCS})
64
 add_executable (MathTest EXCLUDE_FROM_ALL ${MATHSRCS})
65
 set_target_properties (MathTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
65
 set_target_properties (MathTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
66
 
66
 
68
 
68
 
69
 # Matrix Test
69
 # Matrix Test
70
 set (MATRIXSRCS "${PROJECT_SOURCE_DIR}/test/Matrix.cpp" "${PROJECT_SOURCE_DIR}/src/Matrix.cpp")
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
 set (MATRIXSRCS ${MATRIXSRCS} "${PROJECT_SOURCE_DIR}/src/Quaternion.cpp")
72
 set (MATRIXSRCS ${MATRIXSRCS} "${PROJECT_SOURCE_DIR}/src/Quaternion.cpp")
73
 add_executable (MatrixTest EXCLUDE_FROM_ALL ${MATRIXSRCS})
73
 add_executable (MatrixTest EXCLUDE_FROM_ALL ${MATRIXSRCS})
74
 set_target_properties (MatrixTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
74
 set_target_properties (MatrixTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})

test/MatMath.cpp → test/math.cpp Voir le fichier


Chargement…
Annuler
Enregistrer