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

Internals of the Vector & Matrix API. More...

Collaboration diagram for Math:

Files

file  mat.c
 
file  utils.h
 
file  vec.c
 
SRP_FORCEINLINE vec4 mat4MultiplyVec4 (const mat4 *restrict m, vec4 v)
 
SRP_FORCEINLINE mat4 mat4MultiplyMat4 (const mat4 *restrict a, const mat4 *restrict b)
 
SRP_FORCEINLINE mat4 mat4ConstructIdentity ()
 
SRP_FORCEINLINE mat4 mat4ConstructScale (float x, float y, float z)
 
SRP_FORCEINLINE mat4 mat4ConstructTranslate (float x, float y, float z)
 
SRP_FORCEINLINE mat4 mat4ConstructRotate (float x, float y, float z)
 
SRP_FORCEINLINE mat4 mat4ConstructTRS (float transX, float transY, float transZ, float rotataionX, float rotataionY, float rotataionZ, float scaleX, float scaleY, float scaleZ)
 
SRP_FORCEINLINE mat4 mat4ConstructView (float cameraX, float cameraY, float cameraZ, float rotataionX, float rotataionY, float rotataionZ, float scaleX, float scaleY, float scaleZ)
 
SRP_FORCEINLINE mat4 mat4ConstructOrthogonalProjection (float x_min, float x_max, float y_min, float y_max, float z_min, float z_max)
 
SRP_FORCEINLINE mat4 mat4ConstructPerspectiveProjection (float x_min_near, float x_max_near, float y_min_near, float y_max_near, float z_near, float z_far)
 
SRP_FORCEINLINE vec2 vec2Add (vec2 a, vec2 b)
 
SRP_FORCEINLINE vec2 vec2Subtract (vec2 a, vec2 b)
 
SRP_FORCEINLINE float vec2DotProduct (vec2 a, vec2 b)
 
SRP_FORCEINLINE vec2 vec2MultiplyScalar (vec2 a, float b)
 
SRP_FORCEINLINE vec3 vec3Add (vec3 a, vec3 b)
 
SRP_FORCEINLINE vec3 vec3Subtract (vec3 a, vec3 b)
 
SRP_FORCEINLINE float vec3DotProduct (vec3 a, vec3 b)
 
SRP_FORCEINLINE vec3 vec3MultiplyScalar (vec3 a, float b)
 
SRP_FORCEINLINE vec4 vec4Add (vec4 a, vec4 b)
 
SRP_FORCEINLINE vec4 vec4Subtract (vec4 a, vec4 b)
 
SRP_FORCEINLINE float vec4DotProduct (vec4 a, vec4 b)
 
SRP_FORCEINLINE vec4 vec4MultiplyScalar (vec4 a, float b)
 
#define _USE_MATH_DEFINES
 
#define M_PI   3.14159265358979323846
 
#define MIN(a, b)   ( (a) > (b) ? (b) : (a) )
 
#define MAX(a, b)   ( (a) > (b) ? (a) : (b) )
 
#define CLAMP(min, max, value)
 
#define FRACTIONAL(x)   ( (x) - floor(x) )
 
#define EPSILON   1e-9
 
#define ROUGHLY_EQUAL(a, b)   (fabs((a) - (b)) <= EPSILON)
 
#define ROUGHLY_ZERO(x)   (fabs(x) <= EPSILON)
 
#define ROUGHLY_LESS_OR_EQUAL(a, b)   ((a) <= (b) + EPSILON)
 
#define ROUGHLY_GREATER_OR_EQUAL(a, b)   ((a) >= (b) - EPSILON)
 

Detailed Description

Internals of the Vector & Matrix API.

Macro Definition Documentation

◆ CLAMP

#define CLAMP (   min,
  max,
  value 
)
Value:
( \
(value < min) ? \
(min) : \
(value > max) ? \
(max) : \
(value) \
)

Clamp the value between min and max

Returns
min, if value < min; max, if value > max; value otherwise

◆ FRACTIONAL

#define FRACTIONAL (   x)    ( (x) - floor(x) )

Get the fractional part of float or double

◆ MAX

#define MAX (   a,
 
)    ( (a) > (b) ? (a) : (b) )

Get the maximum of two values

◆ MIN

#define MIN (   a,
 
)    ( (a) > (b) ? (b) : (a) )

Get the minimum of two values

◆ ROUGHLY_EQUAL

#define ROUGHLY_EQUAL (   a,
 
)    (fabs((a) - (b)) <= EPSILON)

Determine if two values are roughly equal

◆ ROUGHLY_GREATER_OR_EQUAL

#define ROUGHLY_GREATER_OR_EQUAL (   a,
 
)    ((a) >= (b) - EPSILON)

Determine if the first value is roughly greater or equal than the second one

◆ ROUGHLY_LESS_OR_EQUAL

#define ROUGHLY_LESS_OR_EQUAL (   a,
 
)    ((a) <= (b) + EPSILON)

Determine if the first value is roughly less or equal than the second one

◆ ROUGHLY_ZERO

#define ROUGHLY_ZERO (   x)    (fabs(x) <= EPSILON)

Determine if a value is roughly zero

Function Documentation

◆ mat4ConstructIdentity()

SRP_FORCEINLINE mat4 mat4ConstructIdentity ( )

Construct a 4x4 identity matrix

Returns
4x4 identity matrix

◆ mat4ConstructOrthogonalProjection()

SRP_FORCEINLINE 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()

SRP_FORCEINLINE mat4 mat4ConstructPerspectiveProjection ( float  x_min_near,
float  x_max_near,
float  y_min_near,
float  y_max_near,
float  z_near,
float  z_far 
)
Todo:
Avoid matmul here?

◆ mat4ConstructRotate()

SRP_FORCEINLINE 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()

SRP_FORCEINLINE 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()

SRP_FORCEINLINE 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()

SRP_FORCEINLINE 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()

SRP_FORCEINLINE 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()

SRP_FORCEINLINE 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()

SRP_FORCEINLINE 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

◆ vec2Add()

SRP_FORCEINLINE vec2 vec2Add ( vec2  a,
vec2  b 
)

Add two vectors

◆ vec2DotProduct()

SRP_FORCEINLINE float vec2DotProduct ( vec2  a,
vec2  b 
)

Calculate the dot product of two vectors

◆ vec2MultiplyScalar()

SRP_FORCEINLINE vec2 vec2MultiplyScalar ( vec2  a,
float  b 
)

Multiply a vector with a scalar value

◆ vec2Subtract()

SRP_FORCEINLINE vec2 vec2Subtract ( vec2  a,
vec2  b 
)

Subtract two vectors

◆ vec3Add()

SRP_FORCEINLINE vec3 vec3Add ( vec3  a,
vec3  b 
)

Add two vectors

◆ vec3DotProduct()

SRP_FORCEINLINE float vec3DotProduct ( vec3  a,
vec3  b 
)

Calculate the dot product of two vectors

◆ vec3MultiplyScalar()

SRP_FORCEINLINE vec3 vec3MultiplyScalar ( vec3  a,
float  b 
)

Multiply a vector with a scalar value

◆ vec3Subtract()

SRP_FORCEINLINE vec3 vec3Subtract ( vec3  a,
vec3  b 
)

Subtract two vectors

◆ vec4Add()

SRP_FORCEINLINE vec4 vec4Add ( vec4  a,
vec4  b 
)

Add two vectors

◆ vec4DotProduct()

SRP_FORCEINLINE float vec4DotProduct ( vec4  a,
vec4  b 
)

Calculate the dot product of two vectors

◆ vec4MultiplyScalar()

SRP_FORCEINLINE vec4 vec4MultiplyScalar ( vec4  a,
float  b 
)

Multiply a vector with a scalar value

◆ vec4Subtract()

SRP_FORCEINLINE vec4 vec4Subtract ( vec4  a,
vec4  b 
)

Subtract two vectors