17void mat4_print(
const mat4 *m )
19 for (
int i=0; i<4; i++) {
20 for (
int j=0; j<4; j++)
21 printf(
"%6.1f ", m->m[j][i]);
37 for (
int i=0; i<4; i++) {
38 for (
int j=0; j<4; j++) {
40 for (
int k=0; k<4; k++)
41 v += m1->m[i][k] * m2->m[k][j];
56 for (
int i=0; i<4; i++) {
57 float l0 = lhs->m[i][0];
58 float l1 = lhs->m[i][1];
59 float l2 = lhs->m[i][2];
61 float r0 = l0 * rhs->m[0][0] + l1 * rhs->m[1][0] + l2 * rhs->m[2][0];
62 float r1 = l0 * rhs->m[0][1] + l1 * rhs->m[1][1] + l2 * rhs->m[2][1];
63 float r2 = l0 * rhs->m[0][2] + l1 * rhs->m[1][2] + l2 * rhs->m[2][2];
69 lhs->m[3][0] += rhs->m[3][0];
70 lhs->m[3][1] += rhs->m[3][1];
71 lhs->m[3][2] += rhs->m[3][2];
84 for (
int i=0; i<4; i++) {
101 for (
int i=0; i<4; i++)
102 m->m[3][i] += m->m[0][i] * x + m->m[1][i] * y + m->m[2][i] * z;
119 m->m[0][0] =
c*x + s*y;
120 m->m[1][0] = -s*x +
c*y;
124 m->m[0][1] =
c*x + s*y;
125 m->m[1][1] = -s*x +
c*y;
141 m->m[0][0] =
c*x + s*y;
142 m->m[1][0] = -s*x +
c*y;
146 m->m[0][1] =
c*x + s*y;
147 m->m[1][1] = -s*x +
c*y;
170 R.m[0][0] = x*x*(1.-
c) +
c;
171 R.m[0][1] = y*x*(1.-
c) + z*s;
172 R.m[0][2] = x*z*(1.-
c) - y*s;
174 R.m[1][0] = x*y*(1.-
c) - z*s;
175 R.m[1][1] = y*y*(1.-
c) +
c;
176 R.m[1][2] = y*z*(1.-
c) + x*s;
178 R.m[2][0] = x*z*(1.-
c) + y*s;
179 R.m[2][1] = y*z*(1.-
c) - x*s;
180 R.m[2][2] = z*z*(1.-
c) +
c;
197 const mat4 m = { .m = {
210 double bottom,
double top,
double nearVal,
double farVal )
212 mat4 mat = {{{{0}}}};
216 tx = -(right + left) / (right - left);
217 ty = -(top + bottom) / (top - bottom);
218 tz = -(farVal + nearVal) / (farVal - nearVal);
220 mat.m[0][0] = 2. / (right - left);
221 mat.m[1][1] = 2. / (top - bottom);
222 mat.m[2][2] = -2. / (farVal - nearVal);
241 vec3 forward, side, upc;
244 vec3_sub( &forward, center, eye );
245 vec3_normalize( &forward );
248 vec3_cross( &side, &forward, up );
249 vec3_normalize( &side );
252 vec3_cross( &upc, &side, &forward );
256 H.m[0][0] = side.v[0];
257 H.m[0][1] = side.v[1];
258 H.m[0][2] = side.v[2];
261 H.m[1][0] = upc.v[0];
262 H.m[1][1] = upc.v[1];
263 H.m[1][2] = upc.v[2];
266 H.m[2][0] = -forward.v[0];
267 H.m[2][1] = -forward.v[1];
268 H.m[2][2] = -forward.v[2];
271 H.m[3][0] = -eye->v[0];
272 H.m[3][1] = -eye->v[1];
273 H.m[3][2] = -eye->v[2];
291 double c = 1. / tan( fov * 0.5 );
292 double d = far - near;
295 H.m[0][0] =
c / aspect;
307 H.m[2][2] = -(far+near) /
d;
312 H.m[3][2] = -2.*far*near /
d;
void mat4_translate(mat4 *m, double x, double y, double z)
Translates a homogenous transformation matrix.
void mat4_apply(mat4 *lhs, const mat4 *rhs)
Applies a transformation to another, storing the result in the left hand side.
mat4 mat4_lookat(const vec3 *eye, const vec3 *center, const vec3 *up)
Creates a matrix with a transformation to look at a center point from an eye with an up vector.
mat4 mat4_identity(void)
Creates an identity matrix.
mat4 mat4_perspective(double fov, double aspect, double near, double far)
Creates a matrix with a perspective transformation.
void mat4_rotate(mat4 *m, double angle, double x, double y, double z)
Multiplies the given matrix by a rotation. (Follows the right-hand rule.)
void mat4_scale(mat4 *m, double x, double y, double z)
Scales a homogeneous transformation matrix.
void mat4_mul(mat4 *out, const mat4 *m1, const mat4 *m2)
Multiplies two matrices (out = m1 * m2).
mat4 mat4_ortho(double left, double right, double bottom, double top, double nearVal, double farVal)
Creates an orthographic projection matrix.
void mat4_rotate2d(mat4 *m, double angle)
Rotates an angle, in radians, around the z axis.
void mat4_rotate2dv(mat4 *m, double c, double s)
Rotates the +x axis to the given vector.
Header file with generic functions and naev-specifics.