aboutsummaryrefslogtreecommitdiff
path: root/src/helper.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-30 15:52:16 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-30 15:52:16 +0100
commit57867bbbdc24b734d85f8d3569c7ad27dcd9504d (patch)
tree1727dd02444038341746894268ecea62b84aaea1 /src/helper.c
parent3a164bce55e173d5204c4aaa66dd4eb5bc1762f9 (diff)
downloadcub3d-57867bbbdc24b734d85f8d3569c7ad27dcd9504d.tar.gz
cub3d-57867bbbdc24b734d85f8d3569c7ad27dcd9504d.tar.bz2
cub3d-57867bbbdc24b734d85f8d3569c7ad27dcd9504d.zip
files restructuration
Diffstat (limited to 'src/helper.c')
-rw-r--r--src/helper.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/helper.c b/src/helper.c
new file mode 100644
index 0000000..9940848
--- /dev/null
+++ b/src/helper.c
@@ -0,0 +1,60 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* helper.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/11 07:32:20 by cacharle #+# #+# */
+/* Updated: 2020/01/16 08:57:01 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "cub3d.h"
+
+t_bool helper_is_player_cell(t_cell cell)
+{
+ return (cell == CELL_LOOK_NORTH || cell == CELL_LOOK_SOUTH ||
+ cell == CELL_LOOK_WEST || cell == CELL_LOOK_EAST);
+}
+
+void helper_free_splited(char **splited)
+{
+ int i;
+
+ if (splited == NULL)
+ return ;
+ i = -1;
+ while (splited[++i] != NULL)
+ free(splited[i]);
+ free(splited);
+}
+
+void helper_rotate_player(t_state *state, double rotation)
+{
+ state->dir = vector_rotate(state->dir, rotation);
+ state->plane = vector_rotate(state->plane, rotation);
+}
+
+/*
+** Initial player direction vector
+** Since the map [0 0] is in the top left corner the north/south direction are slipped.
+** The camera plane has to stay perpendicular to the direction and
+** create a camera with a 66 degree angle (which is a recommended angle for fps)
+*/
+
+void helper_init_dir_plane(t_state *state, int y, int x)
+{
+ if (state->map[y][x] == CELL_LOOK_NORTH)
+ state->dir.y = -1.0;
+ else if (state->map[y][x] == CELL_LOOK_SOUTH)
+ state->dir.y = 1.0;
+ else if (state->map[y][x] == CELL_LOOK_WEST)
+ state->dir.x = -1.0;
+ else if (state->map[y][x] == CELL_LOOK_EAST)
+ state->dir.x = 1.0;
+ state->plane = vector_rotate(state->dir, M_PI_2);
+ state->plane = vector_scale(state->plane, 1.0 / vector_norm(state->plane));
+ state->plane = vector_scale(state->plane, 0.66);
+ state->plane = vector_apply(state->plane, &fabs);
+}