adjust camera speed for framerate
This commit is contained in:
parent
3f6c99cf21
commit
d9b1acde84
14
u06-2/main.c
14
u06-2/main.c
|
@ -36,21 +36,21 @@ int framesSinceUpdate = 0;
|
||||||
GLfloat step = 0.0f;
|
GLfloat step = 0.0f;
|
||||||
const GLfloat pi = 3.14159f;
|
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
|
// input handler for camera movement
|
||||||
void handleInputs(void) {
|
void handleInputs(double deltaTime) {
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
|
||||||
cameraPosition.z += 0.02f;
|
cameraPosition.z += deltaTime * 10;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
|
||||||
cameraPosition.z -= 0.02f;
|
cameraPosition.z -= deltaTime * 10;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
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) {
|
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
|
// camera movement
|
||||||
handleInputs();
|
handleInputs(deltaTime);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
|
|
Loading…
Reference in New Issue