GrooveStomp's 3D Software Renderer  0.1.0
Classes | Macros | Functions
math.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  vec2
 Homogenous 2D coordinates. More...
 
struct  vec3
 Homogenous 3D coordinates. More...
 
struct  triangle
 Triangular mesh face. More...
 
struct  mesh
 A collection of triangles representing some kind of 3D model. More...
 
struct  mat4x4
 A 3D matrix using homogenous coordinates. More...
 

Macros

#define MATH_VERSION   "0.1.0"
 include guard
 

Functions

void Vec3Debug (struct vec3 vec3, char *name)
 Prints debug information about the homogenous 3D vector.
 
struct vec3 Vec3Init (float x, float y, float z)
 
float Vec3DotProduct (struct vec3 left, struct vec3 right)
 
struct vec3 Vec3CrossProduct (struct vec3 left, struct vec3 right)
 
struct vec3 Vec3Normalize (struct vec3 vec3)
 
struct vec3 Vec3Add (struct vec3 left, struct vec3 right)
 
struct vec3 Vec3Subtract (struct vec3 minuend, struct vec3 subtrahend)
 
struct vec3 Vec3Multiply (struct vec3 vec3, float f)
 
struct vec3 Vec3Divide (struct vec3 vec3, float f)
 
struct vec3 Vec3IntersectPlane (struct vec3 plane, struct vec3 normal, struct vec3 lineStart, struct vec3 lineEnd, float *t)
 Return the 3d point where a line intersects a plane. More...
 
struct triangle TriangleInit (float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3)
 Create a new triangle with the given params.
 
int TriangleClipAgainstPlane (struct vec3 plane, struct vec3 normal, struct triangle in, struct triangle *out1, struct triangle *out2)
 Clip a triangle against a plane. More...
 
void TriangleDebug (struct triangle triangle, char *name)
 Prints debug information about the triangle face.
 
struct meshMeshInit (int numTris)
 Initialize a new mesh object. More...
 
struct meshMeshInitFromObj (char *objFile)
 Initialize a new mesh object from an obj file. More...
 
void MeshDeinit (struct mesh *mesh)
 De-initializes the mesh object. More...
 
struct vec3 Mat4x4MultiplyVec3 (struct mat4x4 mat, struct vec3 vec)
 
struct mat4x4 Mat4x4Identity ()
 
struct mat4x4 Mat4x4RotateX (float rad)
 
struct mat4x4 Mat4x4RotateY (float rad)
 
struct mat4x4 Mat4x4RotateZ (float rad)
 
struct mat4x4 Mat4x4Translate (float x, float y, float z)
 
struct mat4x4 Mat4x4Project (float fovDegrees, float aspect, float near, float far)
 
struct mat4x4 Mat4x4Multiply (struct mat4x4 left, struct mat4x4 right)
 
struct mat4x4 Mat4x4InvertFast (struct mat4x4 matrix)
 Fast matrix inverse. Doesn't work if matrix does scaling.
 
struct mat4x4 Mat4x4PointAt (struct vec3 pos, struct vec3 target, struct vec3 up)
 
void Mat4x4Debug (struct mat4x4 mat, char *name)
 Prints debug information about the 4x4 matrix.
 

Detailed Description

A collection of vector and matrix types and associated functions.

Function Documentation

◆ MeshDeinit()

void MeshDeinit ( struct mesh mesh)

De-initializes the mesh object.

Frees any memory allocated by the object and frees the pointer to the object itself.

Parameters
[in,out]meshThe mesh to be de-initialized

◆ MeshInit()

struct mesh* MeshInit ( int  numTris)

Initialize a new mesh object.

This function is useful if a mesh needs to be explicitly, manually defined. Initialization here only refers to setting a valid "zero" state.

Parameters
[in]numTristhe number of triangular faces the mesh will hold.
Returns
a properly "zeroed" mesh object that can support numTris faces.

◆ MeshInitFromObj()

struct mesh* MeshInitFromObj ( char *  objFile)

Initialize a new mesh object from an obj file.

Loads the specified obj file and constructs a new mesh object representation of it.

Note: This doesn't read material definitions properly, instead explicitly loading a predefined texture out-of-band and applying it if there are texture coordinates in the obj file.

Parameters
[in]objFilepath to the obj file to read
Returns
a mesh object representing the data in the obj file
See also
Features

◆ TriangleClipAgainstPlane()

int TriangleClipAgainstPlane ( struct vec3  plane,
struct vec3  normal,
struct triangle  in,
struct triangle out1,
struct triangle out2 
)

Clip a triangle against a plane.

Given a triangle and a plane, if some of the points lie on one side of the plane and some on the other, then split the triangle into 1 or 2 smaller triangles that do not pass through the plane.

Parameters
[in]planepoint on the plane to clip against
[in]normalnormal of the plane to clip against
[in]inthe triangle to clip
[out]out1one of the smaller triangles resulting from the clipping, if necessary
[out]out2one of the smaller triangles resulting from the clipping, if necessary
Returns
0 if all points are outside the plane, 1 if the triangle is not clipped, otherwise the number of smaller triangles resulting from clipping.

◆ Vec3IntersectPlane()

struct vec3 Vec3IntersectPlane ( struct vec3  plane,
struct vec3  normal,
struct vec3  lineStart,
struct vec3  lineEnd,
float *  t 
)

Return the 3d point where a line intersects a plane.

Parameters
[in]plane3d point on the plane to intersect against
[in]normalnormal of the plane to intersect against
[in]lineStart
[in]lineEnd
[out]twhere on the line the intersection occurs.