aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_detect.c
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z3r8p1.le-101.fr>2020-02-13 18:30:37 +0100
committerRudy Bousset <rbousset@z3r8p1.le-101.fr>2020-02-13 18:30:37 +0100
commitd91a3ef90ba3975b7c3bd47b69ce7febda2a77a7 (patch)
treedc63c1a193330cabf201fd4afab0c4b02a2d5f65 /src/ft_detect.c
parentDivided minimap scale by 4, Makefile update (diff)
download42-cub3d-d91a3ef90ba3975b7c3bd47b69ce7febda2a77a7.tar.gz
42-cub3d-d91a3ef90ba3975b7c3bd47b69ce7febda2a77a7.tar.bz2
42-cub3d-d91a3ef90ba3975b7c3bd47b69ce7febda2a77a7.tar.xz
42-cub3d-d91a3ef90ba3975b7c3bd47b69ce7febda2a77a7.tar.zst
42-cub3d-d91a3ef90ba3975b7c3bd47b69ce7febda2a77a7.zip
Smooth
Diffstat (limited to 'src/ft_detect.c')
-rw-r--r--src/ft_detect.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/ft_detect.c b/src/ft_detect.c
new file mode 100644
index 0000000..b83c9f1
--- /dev/null
+++ b/src/ft_detect.c
@@ -0,0 +1,67 @@
+#include <cub3d.h>
+#include <math.h>
+
+static void
+ft_detection_init_y(t_cub *cl)
+{
+ cl->rlist.y_delta_dist = sqrt(1 + (cl->rlist.x_ray_dir *
+ cl->rlist.x_ray_dir) / (cl->rlist.y_ray_dir *
+ cl->rlist.y_ray_dir));
+ if (cl->rlist.y_ray_dir < 0)
+ {
+ cl->y_step = -1;
+ cl->rlist.y_side_dist = (cl->rlist.y_ray_pos -
+ cl->rlist.sqy) * cl->rlist.y_delta_dist;
+ }
+ else
+ {
+ cl->y_step = 1;
+ cl->rlist.y_side_dist = (cl->rlist.sqy + 1.0 -
+ cl->rlist.y_ray_pos) * cl->rlist.y_delta_dist;
+ }
+}
+
+static void
+ft_detection_init_x(t_cub *cl)
+{
+ cl->rlist.x_delta_dist = sqrt(1 + (cl->rlist.y_ray_dir *
+ cl->rlist.y_ray_dir) / (cl->rlist.x_ray_dir *
+ cl->rlist.x_ray_dir));
+ if (cl->rlist.x_ray_dir < 0)
+ {
+ cl->x_step = -1;
+ cl->rlist.x_side_dist = (cl->rlist.x_ray_pos -
+ cl->rlist.sqx) * cl->rlist.x_delta_dist;
+ }
+ else
+ {
+ cl->x_step = 1;
+ cl->rlist.x_side_dist = (cl->rlist.sqx + 1.0 -
+ cl->rlist.x_ray_pos) * cl->rlist.x_delta_dist;
+ }
+ ft_detection_init_y(cl);
+}
+
+void
+ft_detect(t_cub *cl)
+{
+ ft_detection_init_x(cl);
+ cl->rlist.hit = 0;
+ while (cl->rlist.hit == 0)
+ {
+ if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
+ {
+ cl->rlist.x_side_dist += cl->rlist.x_delta_dist;
+ cl->rlist.sqx += cl->x_step;
+ cl->rlist.side = 0;
+ }
+ else
+ {
+ cl->rlist.y_side_dist += cl->rlist.y_delta_dist;
+ cl->rlist.sqy += cl->y_step;
+ cl->rlist.side = 1;
+ }
+ if (cl->map[cl->rlist.sqx][cl->rlist.sqy] == '1')
+ cl->rlist.hit = 1;
+ }
+}