wip: receive key input

This commit is contained in:
ktyl 2024-03-03 23:52:34 +00:00
parent 441a0748d1
commit 0b4e84323c
1 changed files with 19 additions and 2 deletions

View File

@ -38,6 +38,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <astro/stateVectorIndices.hpp> #include <astro/stateVectorIndices.hpp>
#include <iostream>
#include "gfx.hpp" #include "gfx.hpp"
#include "icosphere.hpp" #include "icosphere.hpp"
@ -45,6 +46,14 @@
#include "orbiter.hpp" #include "orbiter.hpp"
#include "widget.hpp" #include "widget.hpp"
void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_C && action == GLFW_PRESS)
{
std::cout << "lol!" << std::endl;
}
}
int main() int main()
{ {
GLFWwindow* window = nullptr; GLFWwindow* window = nullptr;
@ -54,9 +63,9 @@ int main()
GLuint litProgram = compileShaderProgram("./frag_lit.glsl"); GLuint litProgram = compileShaderProgram("./frag_lit.glsl");
GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl"); GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl");
// set up scene
Icosphere planet(0.2, 3, litProgram); Icosphere planet(0.2, 3, litProgram);
std::vector<float> keplerianElements(6); std::vector<float> keplerianElements(6);
keplerianElements[astro::semiMajorAxisIndex] = .75; keplerianElements[astro::semiMajorAxisIndex] = .75;
keplerianElements[astro::eccentricityIndex] = .5; keplerianElements[astro::eccentricityIndex] = .5;
@ -68,9 +77,18 @@ int main()
Icosphere orbiterSphere(0.07, 2, litProgram); Icosphere orbiterSphere(0.07, 2, litProgram);
Orbiter orbiter(orbiterSphere, orbit, unlitProgram); Orbiter orbiter(orbiterSphere, orbit, unlitProgram);
// register input
// TODO: init objects with a reference to the window so that they can register
// their own key inputs
glfwSetKeyCallback(window, keyCallback);
// Main loop // Main loop
while (!glfwWindowShouldClose(window)) while (!glfwWindowShouldClose(window))
{ {
// TODO: receive input from GLFW
glfwPollEvents();
// rendering
glClearColor(0.2, 0.3, 0.3, 1.0); glClearColor(0.2, 0.3, 0.3, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -79,7 +97,6 @@ int main()
orbiter.render(time); orbiter.render(time);
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents();
} }
glfwTerminate(); glfwTerminate();