From: Brendan Hansen Date: Fri, 17 Dec 2021 04:41:48 +0000 (-0600) Subject: fully mobile around a cube X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=61dc73d315688e74fa685f7f4d41e5879f82ea87;p=voxel-shooter.git fully mobile around a cube --- diff --git a/src/main.onyx b/src/main.onyx index 463dce4..29c658e 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -215,8 +215,9 @@ Vector3 :: struct { } } -#operator + macro (v1, v2: Vector3) => Vector3.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z }; -#operator - macro (v1, v2: Vector3) => Vector3.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z }; +#operator + macro (v1, v2: Vector3) => Vector3.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z }; +#operator - macro (v1, v2: Vector3) => Vector3.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z }; +#operator * macro (v: Vector3, s: f32) => Vector3.{ v.x * s, v.y * s, v.z * s }; update_world_matrix :: (position: Vector3, facing: Vector3, up: Vector3) { forward := Vector3.norm(facing); //center - position); @@ -239,6 +240,7 @@ update_world_matrix :: (position: Vector3, facing: Vector3, up: Vector3) { theta := 0.0f; // y-axis phi := 0.0f; // x-axis +pos := Vector3.{ 5, 5, 5 }; update :: (dt: f32) { #persist t := 0.0f; @@ -261,7 +263,22 @@ update :: (dt: f32) { math.cos(theta) * math.cos(phi) }; - update_world_matrix(.{ 5, 5, 5 }, facing, .{ 0, 1, 0 }); + up := Vector3.{0,1,0}; + + if glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS { + pos += Vector3.norm(facing) * 3 * dt; + } + if glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS { + pos -= Vector3.norm(facing) * 3 * dt; + } + if glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS { + pos += Vector3.norm(Vector3.cross(facing, up)) * 3 * dt; + } + if glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS { + pos -= Vector3.norm(Vector3.cross(facing, up)) * 3 * dt; + } + + update_world_matrix(pos, facing, up); } draw :: () {