A C89 standard compliant, single header, nostdlib (no C Standard Library) vector linear algebra implementation.
For more information please look at the "vm.h" file or take a look at the "examples" or "tests" folder.
Download or clone vm.h and include it in your project.
#include "vm.h"
int main() {
int width = 800;
int height = 600;
v3 look_at_pos = vm_v3_zero; /* Where should the camera look at */
v3 up = vm_v3(0.0f, 1.0f, 0.0f); /* World/Camera up */
v3 cam_position = vm_v3(0.0f, 0.0f, 13.0f); /* Camera set a little bit back */
float cam_fov = 90.0f;
m4x4 projection = vm_m4x4_perspective(vm_rad(cam_fov), (float)width / (float)height, 0.1f, 1000.0f);
m4x4 view = vm_m4x4_lookAt(cam_position, look_at_pos, up);
m4x4 projection_view = vm_m4x4_mul(projection, view);
/*
Frustum Culling Example
*/
frustum frustum_planes = vm_frustum_extract_planes(projection_view);
v3 cube1_position = vm_v3_zero;
v3 cube1_dimensions = vm_v3_one; /* No Scaling */
v3 cube2_position = vm_v3(100.0f, 0.0f, 0.0f); /* Cube is set far away to the left */
v3 cube2_dimensions = vm_v3_one; /* No Scaling */
/* The cube is rendered inside the camera frustum */
assert(vm_frustum_is_cube_in(frustum_planes, cube1_position, cube1_dimensions, 0.15f));
/* The cube is outside of camer frustum ! */
assert(!vm_frustum_is_cube_in(frustum_planes, cube2_position, cube2_dimensions, 0.15f));
return 0;
}
Note: By default the m4x4 (Matrix 4x4) uses a column major order for storing data (used by OpenGL). If you want to change to a row major order you can use the following define before including the header.
#define VM_M4X4_ROW_MAJOR_ORDER
#include "vm.h"
In this repo you will find the "examples/vm_win32_nostdlib.c" with the corresponding "build.bat" file which creates an executable only linked to "kernel32" and is not using the C standard library and executes the program afterwards.
nostdlib is a lightweight, minimalistic approach to C development that removes dependencies on the standard library. The motivation behind this project is to provide developers with greater control over their code by eliminating unnecessary overhead, reducing binary size, and enabling deployment in resource-constrained environments.
Many modern development environments rely heavily on the standard library, which, while convenient, introduces unnecessary bloat, security risks, and unpredictable dependencies. nostdlib aims to give developers fine-grained control over memory management, execution flow, and system calls by working directly with the underlying platform.
By removing the standard library, nostdlib significantly reduces runtime overhead, allowing for faster execution and smaller binary sizes.
Standard libraries often include unnecessary functions that increase the attack surface of an application. nostdlib mitigates security risks by removing unused and potentially vulnerable components.
Without linking to the standard library, binaries are smaller, making them ideal for embedded systems, bootloaders, and operating systems where storage is limited.
Direct control over system calls and memory management leads to performance gains by eliminating abstraction layers imposed by standard libraries.
By relying only on fundamental system interfaces, nostdlib allows for easier porting across different platforms without worrying about standard library availability.