srp
software rendering pipeline
Loading...
Searching...
No Matches

Vector & Matrix API, only included if you define SRP_INCLUDE_VECTOR or SRP_INCLUDE_MAT More...

Collaboration diagram for Math:

Files

file  mat.h
 
file  vec.h
 

Classes

struct  mat4
 
struct  vec2
 
typedef struct mat4 mat4
 
vec4 mat4MultiplyVec4 (const mat4 *restrict a, vec4 b)
 
mat4 mat4MultiplyMat4 (const mat4 *restrict a, const mat4 *restrict b)
 
mat4 mat4ConstructIdentity ()
 
mat4 mat4ConstructScale (float x, float y, float z)
 
mat4 mat4ConstructTranslate (float x, float y, float z)
 
mat4 mat4ConstructRotate (float x, float y, float z)
 
mat4 mat4ConstructTRS (float transX, float transY, float transZ, float rotataionX, float rotataionY, float rotataionZ, float scaleX, float scaleY, float scaleZ)
 
mat4 mat4ConstructView (float cameraX, float cameraY, float cameraZ, float rotationX, float rotationY, float rotationZ, float scaleX, float scaleY, float scaleZ)
 
mat4 mat4ConstructOrthogonalProjection (float x_min, float x_max, float y_min, float y_max, float z_min, float z_max)
 
mat4 mat4ConstructPerspectiveProjection (float x_min_near, float x_max_near, float y_min_near, float y_max_near, float z_near, float z_far)
 
typedef struct vec2 vec2
 

Detailed Description

Vector & Matrix API, only included if you define SRP_INCLUDE_VECTOR or SRP_INCLUDE_MAT

Typedef Documentation

◆ mat4

typedef struct mat4 mat4

Represents a 4x4 matrix of floats, stores data in row-major order

◆ vec2

typedef struct vec2 vec2

Represents a 2D vector of floats

Function Documentation

◆ mat4ConstructIdentity()

mat4 mat4ConstructIdentity ( )

Construct a 4x4 identity matrix

Returns
4x4 identity matrix

◆ mat4ConstructOrthogonalProjection()

mat4 mat4ConstructOrthogonalProjection ( float  x_min,
float  x_max,
float  y_min,
float  y_max,
float  z_min,
float  z_max 
)

Construct a 4x4 orthogonal projection matrix. The orthogonal projection matrix transforms arbitrary rectangular parallelepiped (defined by 2 points: "min" and "max" ones) into an NDC cube, so it can be drawn in screen space

Parameters
x_min,y_min,z_minCoordinates of the "min" point defining a rectangular parallelepiped
x_max,y_max,z_maxCoordinates of the "max" point defining a rectangular parallelepiped
Returns
Orthogonal projection matrix

◆ mat4ConstructPerspectiveProjection()

mat4 mat4ConstructPerspectiveProjection ( float  x_min_near,
float  x_max_near,
float  y_min_near,
float  y_max_near,
float  z_near,
float  z_far 
)

Construct a 4x4 perspective projection matrix. The perspective projection matrix transforms the perspective frustum (defined by the distance to near and far planes and by "min" and "max" points on the near plane) to a unit cube, so it can be drawn in screen space

Parameters
x_min_near,x_max_nearMinimum and maximum X values on the near plane
y_min_near,y_max_nearMinimum and maximum Y on the near plane
z_near,z_farDistance to the near and far planes
Returns
Perspective projection matrix
Todo:
Avoid matmul here?

◆ mat4ConstructRotate()

mat4 mat4ConstructRotate ( float  x,
float  y,
float  z 
)

Construct a 4x4 matrix that rotates the points

Parameters
x,y,zAngle (in radians) by which the points are rotated around X, Y, Z axis respectively
Returns
Rotation matrix

◆ mat4ConstructScale()

mat4 mat4ConstructScale ( float  x,
float  y,
float  z 
)

Construct a 4x4 matrix that scales the X, Y and Z dimensions

Parameters
x,y,zScaling coefficients for X, Y, Z dimensions respectively
Returns
Scale matrix

◆ mat4ConstructTranslate()

mat4 mat4ConstructTranslate ( float  x,
float  y,
float  z 
)

Construct a 4x4 matrix that translates the points

Parameters
x,y,zTranslating coefficient for X, Y, Z dimensions respectively
Returns
Translation matrix

◆ mat4ConstructTRS()

mat4 mat4ConstructTRS ( float  transX,
float  transY,
float  transZ,
float  rotataionX,
float  rotataionY,
float  rotataionZ,
float  scaleX,
float  scaleY,
float  scaleZ 
)

Construct a 4x4 matrix that translates, rotates the points and scales the X, Y, and Z dimenstions

See also
mat4ConstructScale() mat4ConstructTranslate() mat4ConstructRotate()
Returns
TRS matrix

◆ mat4ConstructView()

mat4 mat4ConstructView ( float  cameraX,
float  cameraY,
float  cameraZ,
float  rotationX,
float  rotationY,
float  rotationZ,
float  scaleX,
float  scaleY,
float  scaleZ 
)

Construct a 4x4 view matrix

Parameters
cameraX,cameraY,cameraZCamera position
rotationX,rotationY,rotationZCamera rotation along each dimension
scaleX,scaleY,scaleZCamera "zoom" along each dimension
Returns
View matrix

◆ mat4MultiplyMat4()

mat4 mat4MultiplyMat4 ( const mat4 *restrict  a,
const mat4 *restrict  b 
)

Multiply two 4x4 matrices

Parameters
aPointer to a matrix A
bPointer to a matrix B
Returns
The product A*B

◆ mat4MultiplyVec4()

vec4 mat4MultiplyVec4 ( const mat4 *restrict  a,
vec4  b 
)

Multiply mat4 by vec4

Parameters
aPointer to a matrix A
bVector B
Returns
The product A*B