Let's add some keyboard controls so that we can interact with the sphere. We will set it so that, when we press the up key on the keyboard, the sphere jumps. We will add the jump feature by applying an impulse to the sphere. To do so, follow these steps:
- First, we'll use GLFW, which has a keyboard callback function so that we can add interaction with the keyboard for the game. Before we begin with the main() function, we will set this keyboard callback function:
void updateKeyboard(GLFWwindow* window, int key, int scancode, int action, int mods){ if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { glfwSetWindowShouldClose(window, true); } if (key == GLFW_KEY_UP && action == GLFW_PRESS) { if (grounded == true) { grounded = false;
sphere->...