Skip to content

Instantly share code, notes, and snippets.

@jakubtomsu
jakubtomsu / poly_obb.odin
Created August 2, 2025 13:54
A demo app showing how to compute tightest possible oriented bounding box of a 2D polygon
// A demo app showing how to compute tightest possible oriented bounding box/rectangle of a convex polygon.
// The order of edges matters, so the points should be in order. In case of convex polygons you can just radially sort them.
//
// By Jakub Tomšů
package poly_obb_demo
import "core:fmt"
import "core:math/linalg"
import rl "vendor:raylib"
package fp_exceptions
import "core:log"
when ODIN_OS == .Windows {
foreign import libcmt "system:libcmt.lib"
}
@(default_calling_convention = "system")
foreign libcmt {
// Failed experiment for a hotreload system. Instead of passing a big global struct pointer, try copying DLL global data sections.
copy_dll_data_sections :: proc(
dst: windows.HMODULE,
src: windows.HMODULE,
) -> bool {
dst_header := get_dll_nt_header(dst) or_return
src_header := get_dll_nt_header(src) or_return
dst_sections := cast([^]windows_IMAGE_SECTION_HEADER)windows_image_first_section(dst_header)
@jakubtomsu
jakubtomsu / obj.odin
Created October 6, 2024 09:34
Simple .obj 3d model parser, doesn't support 100% features like curves and whatnot but it's good enough for most regular models.
package obj
import "core:fmt"
import "core:math/linalg"
import "core:os"
import "core:strconv"
import "core:strings"
// https://en.wikipedia.org/wiki/Wavefront_.obj_file
@jakubtomsu
jakubtomsu / qmap.odin
Created October 6, 2024 09:33
Very simple parser for quake .map readable level data format (Valve version). I didn't fully test it.
package qmap
import "core:fmt"
import "core:os"
import "core:strconv"
import "core:strings"
// https://developer.valvesoftware.com/wiki/MAP_(file_format)
File :: struct {
@jakubtomsu
jakubtomsu / curves.odin
Created September 14, 2024 17:00
Curves based on Freya's video
package curves
Curve_Kind :: enum u8 {
Linear,
Bezier,
Hermite,
Catmull_Rom,
B_Spline,
}
@jakubtomsu
jakubtomsu / points_along_curve.odin
Created September 14, 2024 16:11
Simple example of nicely animating moving points along a curve
package curve_test
import "core:math/linalg"
import rl "vendor:raylib"
main :: proc() {
rl.SetConfigFlags({.MSAA_4X_HINT, .VSYNC_HINT})
rl.InitWindow(900, 600, "Curves")
defer rl.CloseWindow()
@jakubtomsu
jakubtomsu / fontstash_sokol_gfx.odin
Last active July 28, 2025 05:34
Example font renderer using fontstash and sokol_gfx in Odin
// This is an example usage of vendor:fontstash with sokol_gfx.
// By Jakub Tomšů
//
// https://gist.github.com/jakubtomsu/5ee4fdfee23df893f6f61b4692dcf895
//
// This won't compile on it's own, but it contains all of the interesting parts.
// It should be pretty obvious how to modify it to your needs, if not let me know.
//
// The genral per-frame work is this:
// - renderer_draw_text appends quads to a cpu-side buffer
@jakubtomsu
jakubtomsu / realtime_collision_detection.odin
Last active July 21, 2025 09:58
Port of some functions from 'Real Time Collision Detection' book by Christer Ericson to Odin
// Port of some collision functions to Odin by Jakub Tomšů.
//
// from Real-Time Collision Detection by Christer Ericson, published by Morgan Kaufmann Publishers, © 2005 Elsevier Inc
//
// This should serve as an reference implementation for common collision queries for games.
// The goal is good numerical robustness, handling edge cases and optimized math equations.
// The code isn't necessarily very optimized.
//
// There are a few cases you don't want to use the procedures below directly, but instead manually inline the math and adapt it to your needs.
// In my experience this method is clearer when writing complex level queries where I need to handle edge cases differently etc.
@jakubtomsu
jakubtomsu / vlsm.odin
Created May 14, 2024 10:17
Simple Variable Length Subnet Mask solver
package vlsm
import "core:fmt"
import "core:intrinsics"
import "core:net"
import "core:slice"
Subnet :: struct {
prefix: u8,
num_hosts: u32,