Skip to content

Instantly share code, notes, and snippets.

View karl-zylinski's full-sized avatar

Karl Zylinski karl-zylinski

View GitHub Profile
// Odin + Box2D + Raylib example with stacking boxes and a shape attached to the cursor that can smack the shapes.
// Made (mostly) during this stream: https://www.youtube.com/watch?v=LYW7jdwEnaI
// I have updated this to use the `vendor:box2d` bindings instead of the ones I used on the stream.
package game
import b2 "vendor:box2d"
import rl "vendor:raylib"
@karl-zylinski
karl-zylinski / load_ttf_from_memory_premultiply_alpha.odin
Created April 15, 2024 11:28
Loading a TTF in Odin and multiply alpha into the gray component of the gray+alpha atlas
load_ttf_from_memory :: proc(file_data: []byte, font_size: int) -> rl.Font {
font := rl.Font {
baseSize = i32(font_size),
glyphCount = 95,
}
font.glyphs = rl.LoadFontData(&file_data[0], i32(len(file_data)), font.baseSize, {}, font.glyphCount, .DEFAULT)
if font.glyphs != nil {
font.glyphPadding = 4
@karl-zylinski
karl-zylinski / tracking_alloc_example.odin
Created March 3, 2024 20:26
Example of how to setup tracking allocator
// from https://odin-lang.org/docs/overview/#when-statements, see end of that section
package main
import "core:fmt"
import "core:mem"
main :: proc() {
when ODIN_DEBUG {
track: mem.Tracking_Allocator
package assets_builder
import "core:fmt"
import "core:os"
import "core:strings"
import "core:path/slashpath"
import "core:hash"
dir_path_to_file_infos :: proc(path: string) -> []os.File_Info {
d, derr := os.open(path, os.O_RDONLY)
{
"selector": "source.odin",
"file_regex": "^(.+)\\(([0-9]+):([0-9]+)\\) (.+)$",
"file_patterns": ["*.odin"],
"cmd": ["build.bat"],
"working_dir": "c:/repos/cat-game",
"variants": [
{
"name": "run",
"cmd": "build.bat && start run.bat",
// Handle-based array. Used like this:
//
// Entity_Handle :: distinct Handle
// entities: Handle_Array(Entity, Entity_Handle)
//
// It expects the type used (in this case
// Entity) to contains a field called
// `handle`, of type `Entity_Handle`.
//
// You can then fetch entities using
[EditorTool("Tile Placer Tool", typeof(TileData))]
class TilePlacerTool : EditorTool
{
private GUIContent m_iconContent;
void OnEnable()
{
var icon = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/Textures/Editor/TileEditorIcon.png");
// Icon for tools toolbar
@karl-zylinski
karl-zylinski / d3d12_triangle.odin
Last active January 11, 2025 17:25
D3D12 triangle in Odin
// D3D12 single-function triangle sample.
//
// Usage:
// - copy SDL2.dll from Odin/vendor/sdl2 to your project directory
// - odin run .
//
// Contributors:
// - Karl Zylinski <[email protected]> (version 1, version 3)
// - Jakub Tomšů (version 2)
//
# Linearly propagates the error of a velocity given in celestial coordinates to cartesian via the
# formulas identical to the ones in function cartesian_velocity_from_celestial.
def celestial_coords_to_cartesian_error(
ra, dec, r,
ra_error, dec_error, r_error,
pmra, pmdec, rv,
pmra_error, pmdec_error, rv_error):
dvx_dra = -cos(dec)*sin(ra)*rv + r*cos(dec)*cos(ra)*pmra - r*sin(dec)*sin(ra)*pmdec
dvx_ddec = -sin(dec)*cos(ra)*rv - r*sin(dec)*sin(ra)*pmra + r*cos(dec)*cos(ra)*pmdec
dvx_dr = cos(dec)*sin(ra)*pmra + sin(dec)*cos(ra)*pmdec
# propagates error of |v2 - v1| where v2 and v1 are vectors and parameters are in celestial coordinates
def celestial_magnitude_of_velocity_difference_error(
ra1_deg, dec1_deg, r1,
ra1_error_deg, dec1_error_deg, r1_error,
pmra1_deg_per_s, pmdec1_deg_per_s, rv1,
pmra1_error_deg_per_s, pmdec1_error_deg_per_s, rv1_error,
ra2_deg, dec2_deg, r2,
ra2_error_deg, dec2_error_deg, r2_error,
pmra2_deg_per_s, pmdec2_deg_per_s, rv2,
pmra2_error_deg_per_s, pmdec2_error_deg_per_s, rv2_error):