]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - matrixlib.h
moved state update from R_Mesh_Render to R_Mesh_Draw_GetBuffer
[xonotic/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
77 // ease of use functions
78 // immediately applies a Translate to the matrix
79 void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z);
80 // immediately applies a Rotate to the matrix
81 void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z);
82 // immediately applies a Scale to the matrix
83 void Matrix4x4_ConcatScale (matrix4x4_t *out, float x);
84 // immediately applies a Scale3 to the matrix
85 void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z);
86
87
88
89 // functions for manipulating 3x4 matrices
90
91 // copy a matrix3x4
92 void Matrix3x4_Copy (matrix3x4_t *out, const matrix3x4_t *in);
93 // copy only the rotation portion of a matrix3x4
94 void Matrix3x4_CopyRotateOnly (matrix3x4_t *out, const matrix3x4_t *in);
95 // copy only the translate portion of a matrix3x4
96 void Matrix3x4_CopyTranslateOnly (matrix3x4_t *out, const matrix3x4_t *in);
97 // make a matrix3x4 from a matrix4x4
98 void Matrix3x4_FromMatrix4x4 (matrix3x4_t *out, const matrix4x4_t *in);
99 // multiply two matrix3x4 together, combining their transformations
100 // (warning: order matters - Concat(a, b, c) != Concat(a, c, b))
101 void Matrix3x4_Concat (matrix3x4_t *out, const matrix3x4_t *in1, const matrix3x4_t *in2);
102 // swaps the rows and columns of the rotation matrix
103 // (inverting the rotation, but leaving everything else the same)
104 void Matrix3x4_Transpose3x3 (matrix3x4_t *out, const matrix3x4_t *in1);
105 // creates a matrix that does the opposite of the matrix provided
106 // only supports translate, rotate, scale (not scale3) matrices
107 void Matrix3x4_Invert_Simple (matrix3x4_t *out, const matrix3x4_t *in1);
108
109 // creates an identity matrix
110 // (a matrix which does nothing)
111 void Matrix3x4_CreateIdentity (matrix3x4_t *out);
112 // creates a translate matrix
113 // (moves vectors)
114 void Matrix3x4_CreateTranslate (matrix3x4_t *out, float x, float y, float z);
115 // creates a rotate matrix
116 // (rotates vectors)
117 void Matrix3x4_CreateRotate (matrix3x4_t *out, float angle, float x, float y, float z);
118 // creates a scaling matrix
119 // (expands or contracts vectors)
120 // (warning: do not apply this kind of matrix to direction vectors)
121 void Matrix3x4_CreateScale (matrix3x4_t *out, float x);
122 // creates a squishing matrix
123 // (expands or contracts vectors differently in different axis)
124 // (warning: this is not reversed by Invert_Simple)
125 // (warning: do not apply this kind of matrix to direction vectors)
126 void Matrix3x4_CreateScale3 (matrix3x4_t *out, float x, float y, float z);
127 // creates a matrix for a quake entity
128 void Matrix3x4_CreateFromQuakeEntity(matrix3x4_t *out, float x, float y, float z, float pitch, float yaw, float roll, float scale);
129
130 // converts a matrix3x4 to a set of 3D vectors for the 3 axial directions, and the translate
131 void Matrix3x4_ToVectors(const matrix3x4_t *in, float vx[3], float vy[3], float vz[3], float t[3]);
132 // creates a matrix3x4 from a set of 3D vectors for axial directions, and translate
133 void Matrix3x4_FromVectors(matrix3x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3]);
134
135 // transforms a 3D vector through a matrix3x4
136 void Matrix3x4_Transform (const matrix3x4_t *in, const float v[3], float out[3]);
137 // reverse transforms a 3D vector through a matrix3x4, at least for *simple*
138 // cases (rotation and translation *ONLY*), this attempts to undo the results
139 // of Transform
140 void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float out[3]);
141
142 // ease of use functions
143 // immediately applies a Translate to the matrix
144 void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z);
145 // immediately applies a Rotate to the matrix
146 void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z);
147 // immediately applies a Scale to the matrix
148 void Matrix3x4_ConcatScale (matrix3x4_t *out, float x);
149 // immediately applies a Scale3 to the matrix
150 void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z);
151
152 #endif