12 static void cursor_pos_callback(__attribute__((unused)) GLFWwindow* window, double current_x, double current_y)
14 static double last_x, last_y = 0.0;
16 double delta_x = current_x - last_x;
17 double delta_y = current_y - last_y;
21 input.client->yaw += (float) delta_x * M_PI / 180.0f / 8.0f;
22 input.client->pitch -= (float) delta_y * M_PI / 180.0f / 8.0f;
24 input.client->pitch = fmax(fmin(input.client->pitch, 89.0f), -89.0f);
26 set_camera_angle(input.client->yaw, input.client->pitch);
29 static bool move(int forward, int backward, vec3 speed)
33 if (glfwGetKey(input.window, forward) == GLFW_PRESS)
35 else if (glfwGetKey(input.window, backward) == GLFW_PRESS)
40 input.client->pos.x += speed[0] * sign;
41 input.client->pos.y += speed[1] * sign;
42 input.client->pos.z += speed[2] * sign;
49 bool moved_forward = move(GLFW_KEY_W, GLFW_KEY_S, movement_dirs.front);
50 bool moved_up = move(GLFW_KEY_SPACE, GLFW_KEY_LEFT_SHIFT, movement_dirs.up);
51 bool moved_right = move(GLFW_KEY_D, GLFW_KEY_A, movement_dirs.right);
53 if (moved_forward || moved_up || moved_right) {
54 set_camera_position(input.client->pos);
56 pthread_mutex_lock(&input.client->mtx);
57 (void) (write_u32(input.client->fd, SC_POS) && write_v3f32(input.client->fd, input.client->pos));
58 pthread_mutex_unlock(&input.client->mtx);
62 void init_input(Client *client, GLFWwindow *window)
64 input.client = client;
65 input.window = window;
67 glfwSetCursorPosCallback(input.window, &cursor_pos_callback);