summaryrefslogtreecommitdiff
path: root/position.ha
diff options
context:
space:
mode:
authorLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:11:21 +0200
committerLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:51:35 +0200
commitae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch)
tree5f462459ae4b47d22114eed717d1382d08cf4dfe /position.ha
Initial commit (import old repo)HEADmain
Diffstat (limited to 'position.ha')
-rw-r--r--position.ha49
1 files changed, 49 insertions, 0 deletions
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);
+};