summaryrefslogtreecommitdiff
path: root/src/player.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c69
1 files changed, 50 insertions, 19 deletions
diff --git a/src/player.c b/src/player.c
index 91c4520..c06dfa4 100644
--- a/src/player.c
+++ b/src/player.c
@@ -3,7 +3,7 @@
#include "player.h"
-void move_player(Player *player, GLFWwindow* window) {
+void move_player(Player *player, GLFWwindow* window, double* mouse_x, double* mouse_y, double width, double height) {
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
player->pos_x += player->dir_x * player->move_speed;
player->pos_y += player->dir_y * player->move_speed;
@@ -12,23 +12,54 @@ void move_player(Player *player, GLFWwindow* window) {
player->pos_x -= player->dir_x * player->move_speed;
player->pos_y -= player->dir_y * player->move_speed;
}
- if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
- // this changes where we're casting our rays
- double old_dir_x = player->dir_x;
- player->dir_x = player->dir_x * cos(-player->rot_speed) - player->dir_y * sin(-player->rot_speed);
- player->dir_y = old_dir_x * sin(-player->rot_speed) + player->dir_y * cos(-player->rot_speed);
- // this updates perspective
- double old_plane_x = player->plane_x;
- player->plane_x = player->plane_x * cos(-player->rot_speed) - player->plane_y * sin(-player->rot_speed);
- player->plane_y = old_plane_x * sin(-player->rot_speed) + player->plane_y * cos(-player->rot_speed);
- }
- if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
- double old_dir_x = player->dir_x;
- player->dir_x = player->dir_x * cos(player->rot_speed) - player->dir_y * sin(player->rot_speed);
- player->dir_y = old_dir_x * sin(player->rot_speed) + player->dir_y * cos(player->rot_speed);
- double old_plane_x = player->plane_x;
- player->plane_x = player->plane_x * cos(player->rot_speed) - player->plane_y * sin(player->rot_speed);
- player->plane_y = old_plane_x * sin(player->rot_speed) + player->plane_y * cos(player->rot_speed);
- }
+
+ // old implementation
+ // if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
+ // // this changes where we're casting our rays
+ // double old_dir_x = player->dir_x;
+ // player->dir_x = player->dir_x * cos(-player->sensitivity) - player->dir_y * sin(-player->sensitivity);
+ // player->dir_y = old_dir_x * sin(-player->sensitivity) + player->dir_y * cos(-player->sensitivity);
+ // // this updates perspective
+ // double old_plane_x = player->plane_x;
+ // player->plane_x = player->plane_x * cos(-player->sensitivity) - player->plane_y * sin(-player->sensitivity);
+ // player->plane_y = old_plane_x * sin(-player->sensitivity) + player->plane_y * cos(-player->sensitivity);
+ // }
+ // if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
+ // double old_dir_x = player->dir_x;
+ // player->dir_x = player->dir_x * cos(player->sensitivity) - player->dir_y * sin(player->sensitivity);
+ // player->dir_y = old_dir_x * sin(player->sensitivity) + player->dir_y * cos(player->sensitivity);
+ // double old_plane_x = player->plane_x;
+ // player->plane_x = player->plane_x * cos(player->sensitivity) - player->plane_y * sin(player->sensitivity);
+ // player->plane_y = old_plane_x * sin(player->sensitivity) + player->plane_y * cos(player->sensitivity);
+ // }
+
+ // issues
+ //double new_mouse_x = 0, new_mouse_y = 0;
+ //glfwGetCursorPos(window, &new_mouse_x, &new_mouse_y);
+ //new_mouse_x -= width / 2;
+ //new_mouse_y -= height / 2;
+ //double dx = new_mouse_x - *mouse_x;
+ //double dy = new_mouse_y - *mouse_y;
+ //*mouse_x = new_mouse_x;
+ //*mouse_y = new_mouse_y;
+ //player->dir += dx * player->sensitivity;
+ //player->dir_x = cos(player->dir);
+ //player->dir_y = sin(player->dir);
+
+
+ double mouse_dx, mouse_dy;
+ double old_mouse_x, old_mouse_y;
+ old_mouse_x = *mouse_x;
+ old_mouse_y = *mouse_y;
+ glfwGetCursorPos(window, mouse_x, mouse_y);
+ mouse_dx = *mouse_x - old_mouse_x;
+ mouse_dy = *mouse_y - old_mouse_y;
+ double rot_speed = mouse_dx * player->sensitivity;
+ double old_dir_x = player->dir_x;
+ player->dir_x = player->dir_x * cos(rot_speed) - player->dir_y * sin(rot_speed);
+ player->dir_y = old_dir_x * sin(rot_speed) + player->dir_y * cos(rot_speed);
+ double old_plane_x = player->plane_x;
+ player->plane_x = player->plane_x * cos(rot_speed) - player->plane_y * sin(rot_speed);
+ player->plane_y = old_plane_x * sin(rot_speed) + player->plane_y * cos(rot_speed);
}