From 53b151b3fd6d4c2b953d8ed93261125577f1c123 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 13 Mar 2023 12:29:35 -0500 Subject: cycle through all meshes --- honey/window.lua | 4 ++++ main.lua | 31 +++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/honey/window.lua b/honey/window.lua index 35e04ac..471d51e 100644 --- a/honey/window.lua +++ b/honey/window.lua @@ -147,6 +147,10 @@ function Window.setContentScaleCallback(self, cb) return glfw.SetContentScaleCallback(self.win, cb) end +function Window.setKeyCallback(self, cb) + return glfw.SetKeyCallback(self.win, cb) +end + function Window.swapBuffers(self) glfw.SwapBuffers(self.win) diff --git a/main.lua b/main.lua index 95068eb..0ff081c 100644 --- a/main.lua +++ b/main.lua @@ -84,16 +84,27 @@ gl.DeleteShader(vertexShader) gl.DeleteShader(fragmentShader) -local mesh = honey.mesh.loadFile("assets/tetrahedron.obj")[1] ---local mesh = honey.mesh.Mesh( --- { --- 0, 0, 0, 0, 0, 1, 0, 0, --- 1, 0, 0, 0, 0, 1, 1, 0, --- 0, 1, 0, 0, 0, 1, 0, 1, --- }, --- { 0, 2, 1 } ---) - +local tetra = honey.mesh.loadFile("assets/tetrahedron.obj")[1] +local cube = honey.mesh.loadFile("assets/cube.obj")[1] +local octa = honey.mesh.loadFile("assets/octahedron.obj")[1] +local dodeca = honey.mesh.loadFile("assets/dodecahedron.obj")[1] +local icosa = honey.mesh.loadFile("assets/icosahedron.obj")[1] + +local meshes = { tetra, cube, octa, dodeca, icosa } +local meshIndex = 1 +local mesh = meshes[1] + +window:setKeyCallback(function(_, key, scancode, action, mods) + if action ~= glfw.PRESS then return end + + if key == glfw.KEY_SPACE then + meshIndex = meshIndex + 1 + if meshIndex > #meshes then meshIndex = 1 end + mesh = meshes[meshIndex] + elseif key == glfw.KEY_ESCAPE then + window:setShouldClose(true) + end +end) while not window:shouldClose() do -- cgit v1.2.1