From ae44478b30d890fe0fb04022f44d474dcdcc3f9d Mon Sep 17 00:00:00 2001 From: Lassi Pulkkinen Date: Thu, 31 Oct 2024 03:11:21 +0200 Subject: Initial commit (import old repo) --- position.ha | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 position.ha (limited to 'position.ha') diff --git a/position.ha b/position.ha new file mode 100644 index 0000000..aa0e36d --- /dev/null +++ b/position.ha @@ -0,0 +1,49 @@ +use glm; + +type ChunkPos = struct { + x: i32, + z: i32, +}; + +type SectionPos = union { + chunk: ChunkPos, + struct { + ChunkPos, + y: i8, + }, +}; + +type BlockPos = struct { + x: i32, + y: i16, + z: i32, +}; + +type Dir = enum u8 { + WEST, + EAST, + DOWN, + UP, + NORTH, + SOUTH, +}; + +fn block_section(pos: BlockPos) SectionPos = { + return SectionPos { + x = pos.x >> 4, + y = (pos.y >> 4): i8, + z = pos.z >> 4, + }; +}; + +fn section_origin(pos: SectionPos) glm::v3 = { + return glm::v3_new( + pos.x: f32 * 16.0, + pos.y: f32 * 16.0, + pos.z: f32 * 16.0, + ); +}; + +fn block_origin(pos: BlockPos) glm::v3 = { + return glm::v3_new(pos.x: f32, pos.y: f32, pos.z: f32); +}; -- cgit v1.2.3