From 748528a31fd6266c961528b2f9ec05cca724ddcd Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 27 Aug 2026 14:41:36 -0400 Subject: [PATCH] Quick little way to spawn in some popcorns. Hit M. --- 17-refactor-bug-fix/src/main.cpp | 14 +++++++++----- 17-refactor-bug-fix/src/scene.cpp | 7 +++++++ 17-refactor-bug-fix/src/scene.hpp | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/17-refactor-bug-fix/src/main.cpp b/17-refactor-bug-fix/src/main.cpp index 01b88ad..cf5ee51 100644 --- a/17-refactor-bug-fix/src/main.cpp +++ b/17-refactor-bug-fix/src/main.cpp @@ -16,13 +16,13 @@ void framebuffer_size_callback(GLFWwindow *, int width, int height) { } void mouse_callback(GLFWwindow *window, double xpos, double ypos) { - Camera* camera = static_cast(glfwGetWindowUserPointer(window)); - camera->mouse_move(xpos, ypos); + Scene* scene = static_cast(glfwGetWindowUserPointer(window)); + scene->camera.mouse_move(xpos, ypos); } void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) { - Camera* camera = static_cast(glfwGetWindowUserPointer(window)); - camera->mouse_scroll(xoffset, yoffset); + Scene* scene = static_cast(glfwGetWindowUserPointer(window)); + scene->camera.mouse_scroll(xoffset, yoffset); } GLFWwindow* create_window() { @@ -65,6 +65,10 @@ void process_input(GLFWwindow *window, Scene& scene) { scene.camera.right(); } + if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) { + scene.spawn("popcorn", scene.camera.position); + } + if(glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) { for(auto& light : scene.light.directional) { light.adjust(-0.01f); @@ -109,7 +113,7 @@ int main() { auto window = create_window(); auto scene = setup(); - glfwSetWindowUserPointer(window, &scene.camera); + glfwSetWindowUserPointer(window, &scene); while(!glfwWindowShouldClose(window)) { update(window, scene); diff --git a/17-refactor-bug-fix/src/scene.cpp b/17-refactor-bug-fix/src/scene.cpp index 5836d5d..d39db47 100644 --- a/17-refactor-bug-fix/src/scene.cpp +++ b/17-refactor-bug-fix/src/scene.cpp @@ -57,3 +57,10 @@ void Scene::render(GLFWwindow* window) { void Scene::cleanup() { shader.cleanup(); } + +void Scene::spawn(const std::string& name, components::Position& position) { + things.emplace_back( + models.at(name), + position, + materials.at(name)); +} diff --git a/17-refactor-bug-fix/src/scene.hpp b/17-refactor-bug-fix/src/scene.hpp index b5dd673..601c8c4 100644 --- a/17-refactor-bug-fix/src/scene.hpp +++ b/17-refactor-bug-fix/src/scene.hpp @@ -60,4 +60,5 @@ struct Scene { void draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position); void render(GLFWwindow* window); void cleanup(); + void spawn(const std::string& name, components::Position& position); };