|
@@ -1,109 +1,81 @@
|
1
|
|
-/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
|
2
|
|
-/*================================================================
|
|
1
|
+/*!
|
3
|
2
|
*
|
4
|
|
- * Project : Freyja
|
5
|
|
- * Author : Terry 'Mongoose' Hendrix II
|
6
|
|
- * Website : http://www.westga.edu/~stu7440/
|
7
|
|
- * Email : stu7440@westga.edu
|
8
|
|
- * Object :
|
9
|
|
- * License : No use w/o permission (C) 2002 Mongoose
|
10
|
|
- * Comments:
|
|
3
|
+ * \file include/MatMath.h
|
|
4
|
+ * \brief Vector and Matrix math
|
11
|
5
|
*
|
12
|
|
- *
|
13
|
|
- * This file was generated using Mongoose's C++
|
14
|
|
- * template generator script. <stu7440@westga.edu>
|
15
|
|
- *
|
16
|
|
- *-- History ------------------------------------------------
|
17
|
|
- *
|
18
|
|
- * 2002.05.11:
|
19
|
|
- * Mongoose - Created
|
20
|
|
- ================================================================*/
|
21
|
|
-
|
|
6
|
+ * \author Mongoose
|
|
7
|
+ */
|
22
|
8
|
|
23
|
9
|
#ifndef _MATMATH_H
|
24
|
10
|
#define _MATMATH_H
|
25
|
11
|
|
26
|
|
-#define HEL_PI 3.14159265358979323846 /* pi */
|
27
|
|
-#define HEL_PI_OVER_2 1.57079632679489661923 /* pi/2 */
|
28
|
|
-#define HEL_2_PI 6.28318530717958647692 /* pi*2 */
|
29
|
|
-#define HEL_PI_OVER_4 0.78539816339744830962 /* pi/4 */
|
30
|
|
-#define HEL_PI_OVER_180 0.017453292519943295 /* pi/180 */
|
31
|
|
-#define HEL_180_OVER_PI 57.295779513082323 /* 180/pi */
|
32
|
|
-
|
33
|
|
-#define HEL_RAD_TO_DEG(x) ((x) * HEL_180_OVER_PI)
|
34
|
|
-#define HEL_DEG_TO_RAD(x) ((x) * HEL_PI_OVER_180)
|
|
12
|
+#define HEL_PI 3.14159265358979323846 //!< pi
|
|
13
|
+#define HEL_PI_OVER_2 1.57079632679489661923 //!< pi/2
|
|
14
|
+#define HEL_2_PI 6.28318530717958647692 //!< pi*2
|
|
15
|
+#define HEL_PI_OVER_4 0.78539816339744830962 //!< pi/4
|
|
16
|
+#define HEL_PI_OVER_180 0.017453292519943295 //!< pi/180
|
|
17
|
+#define HEL_180_OVER_PI 57.295779513082323 //!< 180/pi
|
35
|
18
|
|
36
|
|
-typedef float vec_t;
|
37
|
|
-typedef float vec2_t[2];
|
38
|
|
-typedef float vec3_t[3];
|
39
|
|
-typedef float vec4_t[4];
|
40
|
|
-typedef vec_t matrix_t[16]; /* Used as _Column_major_ in every class now! */
|
|
19
|
+#define HEL_RAD_TO_DEG(x) ((x) * HEL_180_OVER_PI) //!< Convert radians to degrees
|
|
20
|
+#define HEL_DEG_TO_RAD(x) ((x) * HEL_PI_OVER_180) //!< Convert degrees to radians
|
41
|
21
|
|
|
22
|
+typedef float vec_t; //!< 1D Vector, aka float
|
|
23
|
+typedef float vec2_t[2]; //!< 2D Vector
|
|
24
|
+typedef float vec3_t[3]; //!< 3D Vector
|
|
25
|
+typedef float vec4_t[4]; //!< 4D Vector
|
|
26
|
+typedef vec_t matrix_t[16]; //!< Used as _Column_major_ in every class now!
|
42
|
27
|
|
43
|
|
-int helIntersectionLineAndPolygon(vec3_t intersect,
|
44
|
|
- vec3_t p1, vec3_t p2,
|
45
|
|
- unsigned int vertexCount, vec3_t *ploygon);
|
46
|
|
-/*------------------------------------------------------
|
47
|
|
- * Pre : Given P1 and P2 of line segment and
|
48
|
|
- * Vertex count and ploygon with count vertices
|
49
|
|
- *
|
50
|
|
- * Only supports triangles and coplanar quads
|
51
|
|
- *
|
52
|
|
- * Post : Returns intersect point or 0 if none
|
53
|
|
- *
|
54
|
|
- *-- History ------------------------------------------
|
55
|
|
- *
|
56
|
|
- * 2003.05.30:
|
57
|
|
- * Mongoose - Created
|
58
|
|
- ------------------------------------------------------*/
|
|
28
|
+/*!
|
|
29
|
+ * \brief Calculate Intersection of a line and a polygon
|
|
30
|
+ * \param intersect Where the intersection is stored, if it exists
|
|
31
|
+ * \param p1 First point of line segment
|
|
32
|
+ * \param p2 Second point of line segment
|
|
33
|
+ * \param vertexCount number of vertices in polygon
|
|
34
|
+ * \param polygon polygon vertex array
|
|
35
|
+ * \returns 0 if there is no intersection
|
|
36
|
+ */
|
|
37
|
+int helIntersectionLineAndPolygon(vec3_t intersect, vec3_t p1, vec3_t p2, unsigned int vertexCount, vec3_t *polygon);
|
59
|
38
|
|
|
39
|
+/*!
|
|
40
|
+ * \brief Calculate the distance from a sphere to a plane
|
|
41
|
+ * \param center Center of sphere
|
|
42
|
+ * \param radius Radius of sphere
|
|
43
|
+ * \param plane Plane
|
|
44
|
+ * \returns distance
|
|
45
|
+ */
|
60
|
46
|
vec_t helDistToSphereFromPlane3v(vec3_t center, vec_t radius, vec4_t plane);
|
61
|
|
-/*------------------------------------------------------
|
62
|
|
- * Pre : Given center and radius of sphere and a plane
|
63
|
|
- * Post : Returns distance from sphere to plane
|
64
|
|
- *
|
65
|
|
- *-- History ------------------------------------------
|
66
|
|
- *
|
67
|
|
- * 1999.06.14:
|
68
|
|
- * Mongoose - Created, from mtk3d
|
69
|
|
- ------------------------------------------------------*/
|
70
|
47
|
|
|
48
|
+/*!
|
|
49
|
+ * \brief Calculate the distance from a box to a plane
|
|
50
|
+ * \param min Minimum Point of a bounding box
|
|
51
|
+ * \param max Maximum Point of a bounding box
|
|
52
|
+ * \param plane Plane
|
|
53
|
+ * \returns distance
|
|
54
|
+ */
|
71
|
55
|
vec_t helDistToBboxFromPlane3v(vec3_t min, vec3_t max, vec4_t plane);
|
72
|
|
-/*------------------------------------------------------
|
73
|
|
- * Pre : Given min and max points of a bounding box
|
74
|
|
- * and a plane
|
75
|
|
- *
|
76
|
|
- * Post : Returns distance from box to plane
|
77
|
|
- *
|
78
|
|
- *-- History ------------------------------------------
|
79
|
|
- *
|
80
|
|
- * 1999.06.14:
|
81
|
|
- * Mongoose - Created, from mtk3d
|
82
|
|
- ------------------------------------------------------*/
|
83
|
56
|
|
|
57
|
+/*!
|
|
58
|
+ * \brief Calculate the length of a line segment / the distance between two points
|
|
59
|
+ * \param a First point
|
|
60
|
+ * \param b Second point
|
|
61
|
+ * \returns distance/length
|
|
62
|
+ */
|
84
|
63
|
vec_t helDist3v(vec3_t a, vec3_t b);
|
85
|
|
-/*------------------------------------------------------
|
86
|
|
- * Pre : Given point A and B
|
87
|
|
- * Post : Returns length of line segment
|
88
|
|
- *
|
89
|
|
- *-- History ------------------------------------------
|
90
|
|
- *
|
91
|
|
- * 1999.06.14:
|
92
|
|
- * Mongoose - Created, from mtk3d
|
93
|
|
- ------------------------------------------------------*/
|
94
|
64
|
|
|
65
|
+/*!
|
|
66
|
+ * \brief Calculates the midpoint between two points / of a line segment
|
|
67
|
+ * \param a First point
|
|
68
|
+ * \param b Second point
|
|
69
|
+ * \param mid Midpoint will be stored here
|
|
70
|
+ */
|
95
|
71
|
void helMidpoint3v(vec3_t a, vec3_t b, vec3_t mid);
|
96
|
|
-/*------------------------------------------------------
|
97
|
|
- * Pre : Given point A and B
|
98
|
|
- * Post : Returns midpoint of line segment
|
99
|
|
- *
|
100
|
|
- *-- History ------------------------------------------
|
101
|
|
- *
|
102
|
|
- * 1999.06.14:
|
103
|
|
- * Mongoose - Created, from mtk3d
|
104
|
|
- ------------------------------------------------------*/
|
105
|
|
-
|
106
|
72
|
|
|
73
|
+/*!
|
|
74
|
+ * \brief Calculates a pseudo-random number
|
|
75
|
+ * \param from Lower bound of resulting number
|
|
76
|
+ * \param to Upper bound
|
|
77
|
+ * \returns random number
|
|
78
|
+ */
|
107
|
79
|
vec_t helRandomNum(vec_t from, vec_t to);
|
108
|
80
|
|
109
|
81
|
#endif
|