naev 0.11.5
mat4.c File Reference

Handles OpenGL matrix stuff. More...

#include <stdio.h>
#include "mat4.h"

Go to the source code of this file.

Functions

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_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_translate (mat4 *m, double x, double y, double z)
 Translates a homogenous transformation 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.
 
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.)
 
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.
 

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 53 of file mat4.c.

◆ mat4_identity()

mat4 mat4_identity ( void )

Creates an identity matrix.

Returns
A new identity matrix.

Definition at line 195 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 239 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 35 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 209 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 288 of file mat4.c.

◆ mat4_print()

void mat4_print ( const mat4 * m)

Definition at line 17 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 159 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 111 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 135 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 82 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 99 of file mat4.c.