Skip to content

Instantly share code, notes, and snippets.

@jakubtomsu
jakubtomsu / collision_3d.odin
Last active May 19, 2025 08:31
Simple raylib example of 3d FPS player movement with triangle collision
package main
import "core:fmt"
import "core:math"
import "core:math/linalg"
import rl "vendor:raylib"
main :: proc() {
rl.SetConfigFlags({.VSYNC_HINT, .WINDOW_RESIZABLE, .MSAA_4X_HINT})
rl.InitWindow(800, 600, "collision")
// 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 / realtime_collision_detection.odin
Last active March 25, 2025 05:21
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 / 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 / fontstash_sokol_gfx.odin
Last active February 28, 2025 13:12
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 / ease.odin
Last active February 7, 2025 23:13
Easings library ported to Odin
package ease
// Adapted from functions here: https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c
// For previews go here: https://easings.net/
import "core:math"
Mode :: enum {
linear = 0,
quad_in,
@jakubtomsu
jakubtomsu / octviz.odin
Last active February 7, 2025 20:08
Odin program for visualizing spherical/hemispherical octahedral mapping with Raylib
// Octahedral mapping visualization in Odin and Raylib
// by Jakub Tomšů (@jakubtomsu_)
//
// Build and run with 'odin run octsphere.odin -file'.
// No additional dependencies required.
//
// Sources:
// https://gpuopen.com/learn/fetching-from-cubes-and-octahedrons/
// https://knarkowicz.wordpress.com/2014/04/16/octahedron-normal-vector-encoding/
@jakubtomsu
jakubtomsu / d3d12_triangle.odin
Last active January 6, 2025 09:15
Simple d3d12 triangle example in Odin
// D3D12 single-function triangle sample.
//
// Usage:
// - copy SDL2.dll from Odin/vendor/sdl2 to your project directory
// - odin run .
//
// Contributors:
// - Jakub Tomšů (updated to newest Odin version)
// - Karl Zylinski <karl@zylinski.se> (Initial port)
//
@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
Renderer_Frustum :: struct {
planes: [6]Vec4,
}
renderer_frustum_from_projection_mat4 :: proc(m: Mat4) -> (result: Renderer_Frustum) {
// https://iquilezles.org/articles/frustum/
result.planes = {
{m[0, 3] - m[0, 0], m[1, 3] - m[1, 0], m[2, 3] - m[2, 0], m[3, 3] - m[3, 0]},
{m[0, 3] + m[0, 0], m[1, 3] + m[1, 0], m[2, 3] + m[2, 0], m[3, 3] + m[3, 0]},
{m[0, 3] + m[0, 1], m[1, 3] + m[1, 1], m[2, 3] + m[2, 1], m[3, 3] + m[3, 1]},