![]() |
LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
|
Go to the source code of this file.
Data Structures | |
struct | vec3_t |
union | mat4_t |
Functions | |
mat4_t | m4_rotation (float angle_in_rad, vec3_t axis) |
mat4_t | m4_ortho_RH (float left, float right, float bottom, float top, float back, float front) |
mat4_t | m4_perspective_RH (float vertical_field_of_view_in_deg, float aspect_ratio, float near_view_distance, float far_view_distance) |
mat4_t | m4_look_at_RH (vec3_t from, vec3_t to, vec3_t up) |
mat4_t | m4_frustum (float left, float right, float bottom, float top, float near, float far) |
mat4_t | m4_invert_affine (mat4_t matrix) |
vec3_t | m4_mul_pos (mat4_t matrix, vec3_t position) |
vec3_t | m4_mul_dir (mat4_t matrix, vec3_t direction) |
void | m4_print (mat4_t matrix) |
void | m4_printp (mat4_t matrix, int width, int precision) |
void | m4_fprint (FILE *stream, mat4_t matrix) |
void | m4_fprintp (FILE *stream, mat4_t matrix, int width, int precision) |
void | m4_print2 (mat4_t matrix, const char *line_start) |
void | m4_printp2 (mat4_t matrix, int width, int precision, const char *line_start) |
void | m4_fprint2 (FILE *stream, mat4_t matrix, const char *line_start) |
void | m4_fprintp2 (FILE *stream, mat4_t matrix, int width, int precision, const char *line_start) |
Math 3D v1.0 - by Stephan Soller steph and Tobias Malmsheimer an.s oller @hel ionwe b.de
Licensed under the MIT license
See: https://github.com/arkanis/single-header-file-c-libs/blob/master/math_3d.h
A few (mainly cosmetic) changes by Emmanuel Thomas-Maurin manu@ etms oftwa re.n et
Last change on 2025-02-22
Math 3D v1.0 By Stephan Soller steph and Tobias Malmsheimer Licensed under the MIT license an.s oller @hel ionwe b.de
Math 3D is a compact C99 library meant to be used with OpenGL. It provides basic 3D vector and 4x4 matrix operations as well as functions to create transformation and projection matrices. The OpenGL binary layout is used so you can just upload vectors and matrices into shaders and work with them without any conversions.
It's an stb style single header file library. Define MATH_3D_IMPLEMENTATION before you include this file in one C file to create the implementation.
QUICK NOTES
m4_mul_pos()
and m4_mul_dir()
functions do a correct perspective divide (division by w) when necessary. This is a bit slower but ensures that the functions will properly work with projection matrices. If profiling shows this is a bottleneck special functions without perspective division can be added. But the normal multiplications should avoid any surprises.glOrtho()
broke that rule and m4_ortho()
has be slightly modified so you can always think of right-handed cubes that are projected into OpenGLs normalized device coordinates.FURTHER IDEAS
These are ideas for future work on the library. They're implemented as soon as there is a proper use case and we can find good names for them.
epsilon
.default_length
if the length of v
is smaller than epsilon
. Otherwise same as v3_length()
.default_vector
if the length of v
is smaller than epsilon
. Otherwise the same as v3_norm()
.m4_invert_affine()
can already invert translation, rotation, scaling, mirroring, reflection and shearing matrices. So a general inversion might only be useful to invert projection matrices for picking. But with orthographic and perspective projection it's probably simpler to calculate the ray into the scene directly based on the screen coordinates.VERSION HISTORY
v1.0 2016-02-15 Initial release