naev 0.12.5
mat4.c File Reference

Handles OpenGL matrix stuff. More...

#include <stdio.h>
#include "mat4.h"
#include "nstring.h"
Include dependency graph for mat4.c:

Go to the source code of this file.

Functions

void mat4_tostr (const mat4 *m, char *buf, size_t len)
void mat4_print (const mat4 *m)
void mat4_mul (mat4 *out, const mat4 *m1, const mat4 *m2)
 Multiplies two matrices (out = m1 * m2).
void mat4_mul_vec (vec3 *out, const mat4 *m, const vec3 *v)
 Multiplies a matrix with a vector (out = m * v);.
void mat4_apply (mat4 *lhs, const mat4 *rhs)
 Applies a transformation to another, storing the result in the left hand side.
void mat4_scale (mat4 *m, double x, double y, double z)
 Scales a homogeneous transformation matrix.
void mat4_scale_xy (mat4 *m, double x, double y)
void mat4_translate (mat4 *m, double x, double y, double z)
 Translates a homogenous transformation matrix.
void mat4_translate_x (mat4 *m, double x)
void mat4_translate_xy (mat4 *m, double x, double y)
void mat4_translate_scale_xy (mat4 *m, double x, double y, double w, double h)
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.
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_rotate_quaternion (mat4 *m, const quat *q)
 Applies a quaternion transformation.
void mat4_trs (mat4 *m, const vec3 *t, const quat *r, const vec3 *s)
 Creates a homogeneous transform matrix from a translation, rotation, and scaling. Uses T*R*S order.
mat4 mat4_identity (void)
 Creates an identity matrix.
mat4 mat4_ortho (double left, double right, double bottom, double top, double nearVal, double farVal)
 Creates an orthographic projection matrix.
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_perspective (double fov, double aspect, double near, double far)
 Creates a matrix with a perspective transformation.
void quat_normalize (quat *q)
void quat_slerp (GLfloat qm[4], const GLfloat qa[4], const GLfloat qb[4], GLfloat t)

Detailed Description

Handles OpenGL matrix stuff.

Definition in file mat4.c.

Function Documentation

◆ mat4_apply()

void mat4_apply ( mat4 * lhs,
const mat4 * rhs )

Applies a transformation to another, storing the result in the left hand side.

Parameters
[in,out]lhsLeft hand side matrix.
[in]rhsRight hand side matrix.

Definition at line 84 of file mat4.c.

◆ mat4_identity()

mat4 mat4_identity ( void )

Creates an identity matrix.

Returns
A new identity matrix.

Definition at line 335 of file mat4.c.

◆ mat4_lookat()

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.

Parameters
[in]eyeVector representing the eye position that is looking at something.
[in]centerVector representing the position that is being looked at.
[in]upVector representing the "upward" direction. Has to be a unitary vector.
Returns
The newly created matrix.

Definition at line 382 of file mat4.c.

◆ mat4_mul()

void mat4_mul ( mat4 * out,
const mat4 * m1,
const mat4 * m2 )

Multiplies two matrices (out = m1 * m2).

Note that out should not be neither m1 nor m2.

Parameters
[out]outOutput matrix.
m1First matrix to mulitply.
m2Second matrix to multiply.

Definition at line 46 of file mat4.c.

◆ mat4_mul_vec()

void mat4_mul_vec ( vec3 * out,
const mat4 * m,
const vec3 * v )

Multiplies a matrix with a vector (out = m * v);.

Note that out should not be v.

Parameters
[out]outOutput vector.
mMatrix to mulitply.
vVector to multiply.

Definition at line 67 of file mat4.c.

◆ mat4_ortho()

mat4 mat4_ortho ( double left,
double right,
double bottom,
double top,
double nearVal,
double farVal )

Creates an orthographic projection matrix.

Definition at line 347 of file mat4.c.

◆ mat4_perspective()

mat4 mat4_perspective ( double fov,
double aspect,
double near,
double far )

Creates a matrix with a perspective transformation.

Parameters
fovField of view.
aspectAspect ratio.
nearNear plane.
farFar plane.
Returns
The newly created matrix.

Definition at line 433 of file mat4.c.

◆ mat4_print()

void mat4_print ( const mat4 * m)

Definition at line 28 of file mat4.c.

◆ mat4_rotate()

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.)

Parameters
[in,out]mMatrix to multiply with.
angleAngle in radians.
xX component of the axis of rotation.
yY component of the axis of rotation.
zZ component of the axis of rotation.

Definition at line 216 of file mat4.c.

◆ mat4_rotate2d()

void mat4_rotate2d ( mat4 * m,
double angle )

Rotates an angle, in radians, around the z axis.

Parameters
[in,out]mMatrix to multiply with.
angleAngle in radians.

Definition at line 167 of file mat4.c.

◆ mat4_rotate2dv()

void mat4_rotate2dv ( mat4 * m,
double c,
double s )

Rotates the +x axis to the given vector.

Parameters
[in,out]mMatrix to multiply with.
cAngle cosine (or x coordinate of the vector).
sAngle sine (or y coordinate of the vector).

Definition at line 191 of file mat4.c.

◆ mat4_rotate_quaternion()

void mat4_rotate_quaternion ( mat4 * m,
const quat * q )

Applies a quaternion transformation.

Parameters
[in,out]mMatrix to multiply with.
qQuaternion to use for rotation.

Definition at line 253 of file mat4.c.

◆ mat4_scale()

void mat4_scale ( mat4 * m,
double x,
double y,
double z )

Scales a homogeneous transformation matrix.

Parameters
[in,out]mMatrix to apply scaling to.
xScaling on X axis.
yScaling on Y axis.
zScaling on Z axis.

Definition at line 113 of file mat4.c.

◆ mat4_scale_xy()

void mat4_scale_xy ( mat4 * m,
double x,
double y )

Definition at line 121 of file mat4.c.

◆ mat4_tostr()

void mat4_tostr ( const mat4 * m,
char * buf,
size_t len )

Definition at line 18 of file mat4.c.

◆ mat4_translate()

void mat4_translate ( mat4 * m,
double x,
double y,
double z )

Translates a homogenous transformation matrix.

Parameters
[in,out]mMatrix to apply scaling to.
xTranslation on X axis.
yTranslation on Y axis.
zTranslation on Z axis.

Definition at line 137 of file mat4.c.

◆ mat4_translate_scale_xy()

void mat4_translate_scale_xy ( mat4 * m,
double x,
double y,
double w,
double h )

Definition at line 152 of file mat4.c.

◆ mat4_translate_x()

void mat4_translate_x ( mat4 * m,
double x )

Definition at line 142 of file mat4.c.

◆ mat4_translate_xy()

void mat4_translate_xy ( mat4 * m,
double x,
double y )

Definition at line 147 of file mat4.c.

◆ mat4_trs()

void mat4_trs ( mat4 * m,
const vec3 * t,
const quat * r,
const vec3 * s )

Creates a homogeneous transform matrix from a translation, rotation, and scaling. Uses T*R*S order.

Definition at line 290 of file mat4.c.

◆ quat_normalize()

void quat_normalize ( quat * q)

Definition at line 463 of file mat4.c.

◆ quat_slerp()

void quat_slerp ( GLfloat qm[4],
const GLfloat qa[4],
const GLfloat qb[4],
GLfloat t )

Definition at line 471 of file mat4.c.