]> icculus.org git repositories - divverent/darkplaces.git/blob - matrixlib.h
make view kicks (both angle and origin) occur before gun is oriented, so it follows...
[divverent/darkplaces.git] / matrixlib.h
1
2 #ifndef MATRIXLIB_H
3 #define MATRIXLIB_H
4
5 typedef struct matrix4x4_s
6 {
7         float m[4][4];
8 }
9 matrix4x4_t;
10
11 typedef struct matrix3x4_s
12 {
13         float m[3][4];
14 }
15 matrix3x4_t;
16
17 // functions for manipulating 4x4 matrices
18
19 // copy a matrix4x4
20 void Matrix4x4_Copy (matrix4x4_t *out, const matrix4x4_t *in);
21 // copy only the rotation portion of a matrix4x4
22 void Matrix4x4_CopyRotateOnly (matrix4x4_t *out, const matrix4x4_t *in);
23 // copy only the translate portion of a matrix4x4
24 void Matrix4x4_CopyTranslateOnly (matrix4x4_t *out, const matrix4x4_t *in);
25 // make a matrix4x4 from a matrix3x4
26 void Matrix4x4_FromMatrix3x4 (matrix4x4_t *out, const matrix3x4_t *in);
27 // multiply two matrix4x4 together, combining their transformations
28 // (warning: order matters - Concat(a, b, c) != Concat(a, c, b))
29 void Matrix4x4_Concat (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2);
30 // swaps the rows and columns of the matrix
31 // (is this useful for anything?)
32 void Matrix4x4_Transpose (matrix4x4_t *out, const matrix4x4_t *in1);
33 // swaps the rows and columns of the rotation matrix
34 // (inverting the rotation, but leaving everything else the same)
35 void Matrix4x4_Transpose3x3 (matrix4x4_t *out, const matrix4x4_t *in1);
36 // creates a matrix that does the opposite of the matrix provided
37 // only supports translate, rotate, scale (not scale3) matrices
38 void Matrix4x4_Invert_Simple (matrix4x4_t *out, const matrix4x4_t *in1);
39
40 // creates an identity matrix
41 // (a matrix which does nothing)
42 void Matrix4x4_CreateIdentity (matrix4x4_t *out);
43 // creates a translate matrix
44 // (moves vectors)
45 void Matrix4x4_CreateTranslate (matrix4x4_t *out, float x, float y, float z);
46 // creates a rotate matrix
47 // (rotates vectors)
48 void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, float z);
49 // creates a scaling matrix
50 // (expands or contracts vectors)
51 // (warning: do not apply this kind of matrix to direction vectors)
52 void Matrix4x4_CreateScale (matrix4x4_t *out, float x);
53 // creates a squishing matrix
54 // (expands or contracts vectors differently in different axis)
55 // (warning: this is not reversed by Invert_Simple)
56 // (warning: do not apply this kind of matrix to direction vectors)
57 void Matrix4x4_CreateScale3 (matrix4x4_t *out, float x, float y, float z);
58 // creates a matrix for a quake entity
59 void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, float x, float y, float z, float pitch, float yaw, float roll, float scale);
60
61 // converts a matrix4x4 to a set of 3D vectors for the 3 axial directions, and the translate
62 void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3]);
63 // creates a matrix4x4 from a set of 3D vectors for axial directions, and translate
64 void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3]);
65
66 // transforms a 3D vector through a matrix4x4
67 void Matrix4x4_Transform (const matrix4x4_t *in, const float v[3], float out[3]);
68 // transforms a 4D vector through a matrix4x4
69 // (warning: if you don't know why you would need this, you don't need it)
70 // (warning: the 4th component of the vector should be 1.0)
71 void Matrix4x4_Transform4 (const matrix4x4_t *in, const float v[4], float out[4]);
72 // reverse transforms a 3D vector through a matrix4x4, at least for *simple*
73 // cases (rotation and translation *ONLY*), this attempts to undo the results
74 // of Transform
75 //void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3]);
76 // transforms a direction vector through the rotation part of a matrix
77 void Matrix4x4_Transform3x3 (const matrix4x4_t *in, const float v[3], float out[3]);
78
79 // ease of use functions
80 // immediately applies a Translate to the matrix
81 void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z);
82 // immediately applies a Rotate to the matrix
83 void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z);
84 // immediately applies a Scale to the matrix
85 void Matrix4x4_ConcatScale (matrix4x4_t *out, float x);
86 // immediately applies a Scale3 to the matrix
87 void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z);
88
89 // print a matrix to the console
90 void Matrix4x4_Print(const matrix4x4_t *in);
91
92
93 // functions for manipulating 3x4 matrices
94
95 // copy a matrix3x4
96 void Matrix3x4_Copy (matrix3x4_t *out, const matrix3x4_t *in);
97 // copy only the rotation portion of a matrix3x4
98 void Matrix3x4_CopyRotateOnly (matrix3x4_t *out, const matrix3x4_t *in);
99 // copy only the translate portion of a matrix3x4
100 void Matrix3x4_CopyTranslateOnly (matrix3x4_t *out, const matrix3x4_t *in);
101 // make a matrix3x4 from a matrix4x4
102 void Matrix3x4_FromMatrix4x4 (matrix3x4_t *out, const matrix4x4_t *in);
103 // multiply two matrix3x4 together, combining their transformations
104 // (warning: order matters - Concat(a, b, c) != Concat(a, c, b))
105 void Matrix3x4_Concat (matrix3x4_t *out, const matrix3x4_t *in1, const matrix3x4_t *in2);
106 // swaps the rows and columns of the rotation matrix
107 // (inverting the rotation, but leaving everything else the same)
108 void Matrix3x4_Transpose3x3 (matrix3x4_t *out, const matrix3x4_t *in1);
109 // creates a matrix that does the opposite of the matrix provided
110 // only supports translate, rotate, scale (not scale3) matrices
111 void Matrix3x4_Invert_Simple (matrix3x4_t *out, const matrix3x4_t *in1);
112
113 // creates an identity matrix
114 // (a matrix which does nothing)
115 void Matrix3x4_CreateIdentity (matrix3x4_t *out);
116 // creates a translate matrix
117 // (moves vectors)
118 void Matrix3x4_CreateTranslate (matrix3x4_t *out, float x, float y, float z);
119 // creates a rotate matrix
120 // (rotates vectors)
121 void Matrix3x4_CreateRotate (matrix3x4_t *out, float angle, float x, float y, float z);
122 // creates a scaling matrix
123 // (expands or contracts vectors)
124 // (warning: do not apply this kind of matrix to direction vectors)
125 void Matrix3x4_CreateScale (matrix3x4_t *out, float x);
126 // creates a squishing matrix
127 // (expands or contracts vectors differently in different axis)
128 // (warning: this is not reversed by Invert_Simple)
129 // (warning: do not apply this kind of matrix to direction vectors)
130 void Matrix3x4_CreateScale3 (matrix3x4_t *out, float x, float y, float z);
131 // creates a matrix for a quake entity
132 void Matrix3x4_CreateFromQuakeEntity(matrix3x4_t *out, float x, float y, float z, float pitch, float yaw, float roll, float scale);
133
134 // converts a matrix3x4 to a set of 3D vectors for the 3 axial directions, and the translate
135 void Matrix3x4_ToVectors(const matrix3x4_t *in, float vx[3], float vy[3], float vz[3], float t[3]);
136 // creates a matrix3x4 from a set of 3D vectors for axial directions, and translate
137 void Matrix3x4_FromVectors(matrix3x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3]);
138
139 // transforms a 3D vector through a matrix3x4
140 void Matrix3x4_Transform (const matrix3x4_t *in, const float v[3], float out[3]);
141 // reverse transforms a 3D vector through a matrix3x4, at least for *simple*
142 // cases (rotation and translation *ONLY*), this attempts to undo the results
143 // of Transform
144 //void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float out[3]);
145 // transforms a direction vector through the rotation part of a matrix
146 void Matrix3x4_Transform3x3 (const matrix3x4_t *in, const float v[3], float out[3]);
147
148 // ease of use functions
149 // immediately applies a Translate to the matrix
150 void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z);
151 // immediately applies a Rotate to the matrix
152 void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z);
153 // immediately applies a Scale to the matrix
154 void Matrix3x4_ConcatScale (matrix3x4_t *out, float x);
155 // immediately applies a Scale3 to the matrix
156 void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z);
157
158 // print a matrix to the console
159 void Matrix3x4_Print(const matrix3x4_t *in);
160
161 #endif