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