PowerBlocks SDK
 
Loading...
Searching...
No Matches
matrix4.c File Reference

4x4 Matrices More...

#include "matrix4.h"
#include <math.h>

Functions

void matrix4_perspective (matrix4 mtx, float fov, float aspect, float near, float far)
 Generate a perspective projection matrix.
 
void matrix4_orthographic (matrix4 mtx, float left, float right, float bottom, float top, float near, float far)
 Generate a orthographic projection matrix.
 

Detailed Description

4x4 Matrices

Your standard column major 4x4 matrix you all know and love.

Author
Samuel Fitzsimons (rainbain)
Date
2025 @license MIT (see LICENSE file)

Function Documentation

◆ matrix4_orthographic()

void matrix4_orthographic ( matrix4 mtx,
float left,
float right,
float bottom,
float top,
float near,
float far )

Generate a orthographic projection matrix.

Transforms points to screen space with no perspective adjustment. So objects remain the same size no matter the Z. Z is treated like 2D layers.

Each feild shows the corners of the 2D space that the points take place in, and will then be projected to the screen.

Points outside are clipped.

Parameters
mtxMatrix to save output into
leftLeft most boundary.
rightRight most boundary.
bottomBottom most boundary.
toptop most boundary.
nearNear Z of the view area. Things outside of it will be clipped.
farFar Z of the view area. Things outside of it will be clipped.

◆ matrix4_perspective()

void matrix4_perspective ( matrix4 mtx,
float fov,
float aspect,
float near,
float far )

Generate a perspective projection matrix.

Used to setup a perspective projection matrix to transform points into screen space such that they appear farther as they go into (-Z) of the screen.

Parameters
mtxMatrix to save output into
fovFeild of view in radians.
aspectAspect ration of the screen. Width / Height
nearNear Z of the view area. Things outside of it will be clipped.
farFar Z of the view area. Things outside of it will be clipped.