lol everyone re-invents a vector lib

This commit is contained in:
Tenari
2026-06-19 07:16:21 -05:00
parent 6e0ef08f1f
commit c81f8fb942
2 changed files with 30 additions and 0 deletions
+27
View File
@@ -72,3 +72,30 @@ fn void u32ReverseArray(u32 arr[], u32 size) {
}
}
fn Vec2f32 vec2Add(Vec2 a, Vec2 b) {
Vec2f32 result = a;
result.x += b.x;
result.y += b.y;
return result;
}
fn Vec2f32 vec2Subtract(Vec2 a, Vec2 b) {
Vec2f32 result = a;
result.x -= b.x;
result.y -= b.y;
return result;
}
fn Vec2f32 vec2FromHexCube(Vec2 map_center, XYZ cube, f32 size, f32 border_thickness) {
f32 hex_height = SQRT_3 * size;
f32 hex_width = 2.0 * size;
f32 horiz_spacing = 0.75 * (hex_width - border_thickness);
f32 vert_spacing = (hex_height - border_thickness);
bool parity = cube.x & 1;
i32 use_y = cube.y * -1;
return (Vec2) {
.x = map_center.x + (cube.x * horiz_spacing),
.y = map_center.y + ((use_y + (f32)(cube.x + parity) / 2.0) * vert_spacing) - (parity ? 0.5*vert_spacing : 0),
};
}