adjust camera speed for framerate

This commit is contained in:
Luca Conte 2024-04-25 19:10:33 +02:00
parent 3f6c99cf21
commit d9b1acde84
1 changed files with 7 additions and 7 deletions

View File

@ -36,21 +36,21 @@ int framesSinceUpdate = 0;
GLfloat step = 0.0f;
const GLfloat pi = 3.14159f;
vec3 cameraPosition = {4.0f, 2.0f, 0.0f};
vec3 cameraPosition = {0.0f, 2.0f, 4.0f};
// input handler for camera movement
void handleInputs(void) {
void handleInputs(double deltaTime) {
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
cameraPosition.z += 0.02f;
cameraPosition.z += deltaTime * 10;
}
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
cameraPosition.z -= 0.02f;
cameraPosition.z -= deltaTime * 10;
}
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
cameraPosition.y += 0.02f;
cameraPosition.y += deltaTime * 10;
}
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
cameraPosition.y -= 0.02f;
cameraPosition.y -= deltaTime * 10;
}
}
@ -204,7 +204,7 @@ void draw(void) {
}
// camera movement
handleInputs();
handleInputs(deltaTime);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(program);