diff options
author | Schark <jordan@schark.online> | 2023-05-12 01:31:13 -0700 |
---|---|---|
committer | Schark <jordan@schark.online> | 2023-05-12 01:31:13 -0700 |
commit | 4b23f2fcc44fc636d8d4dbe94881cf937c54199b (patch) | |
tree | de316f938ce661052de23b089760aba7c1268402 /src/main.c | |
parent | dc8ad2d7f67e47b00ed0ecb77fae976275fc7a16 (diff) | |
download | gamedev-4b23f2fcc44fc636d8d4dbe94881cf937c54199b.tar.gz gamedev-4b23f2fcc44fc636d8d4dbe94881cf937c54199b.zip |
Mouse inputs working
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -154,6 +154,8 @@ void raycast(Player *player, int width, int height) { int main(int argc, char *argv[]) { GLFWwindow* window; + double mouse_x; + double mouse_y; // init player Player player; @@ -163,8 +165,8 @@ int main(int argc, char *argv[]) { player.dir_y = 0.0f; // facing right player.plane_x = 0.0f; // FOV related player.plane_y = 0.66f; // FOV related - player.move_speed = 0.05f; - player.rot_speed = 0.1f; + player.move_speed = 0.02f; + player.sensitivity = 0.001f; // initiate glfw library if (!glfwInit()){ @@ -185,6 +187,12 @@ int main(int argc, char *argv[]) { // make window current glfwMakeContextCurrent(window); + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); + + // update mouse position + // glfwGetCursorPos(window, &mouse_x, &mouse_y); + mouse_x -= mode->width / 2; + mouse_y -= mode->height / 2; // setup orthographic projection camera glMatrixMode(GL_PROJECTION); @@ -200,6 +208,11 @@ int main(int argc, char *argv[]) { while (!glfwWindowShouldClose(window)) { + // Stop loop if window isn't focused + if(!glfwGetWindowAttrib(window, GLFW_FOCUSED)){ + continue; + } + // timing section double current_time = glfwGetTime(); nb_frames++; @@ -208,15 +221,18 @@ int main(int argc, char *argv[]) { glfwSetWindowTitle(window, title); nb_frames = 0; last_time += 1.0; + } else if (current_time - last_time >= 0.7) { + //glfwSetCursorPos(window, mode->width / 2, mode->height / 2); } // clear window glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); + // main raycast function + move_player(&player, window, &mouse_x, &mouse_y, mode->width, mode->height); raycast(&player, mode->width, mode->height); - move_player(&player, window); glfwSwapBuffers(window); glfwPollEvents(); |