summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorSchark <jordan@schark.online>2023-05-12 01:31:13 -0700
committerSchark <jordan@schark.online>2023-05-12 01:31:13 -0700
commit4b23f2fcc44fc636d8d4dbe94881cf937c54199b (patch)
treede316f938ce661052de23b089760aba7c1268402 /src/main.c
parentdc8ad2d7f67e47b00ed0ecb77fae976275fc7a16 (diff)
downloadgamedev-4b23f2fcc44fc636d8d4dbe94881cf937c54199b.tar.gz
gamedev-4b23f2fcc44fc636d8d4dbe94881cf937c54199b.zip
Mouse inputs working
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 0ea84d4..34a4d0e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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();