aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-08 00:56:36 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-08 00:56:36 +0100
commitd248cde2309e9aa3f14a10ce2db0019afdf9f0f1 (patch)
tree3b754dacd2e858c547f9cb95a303a797f39382c8
parentI gotta figure out (diff)
download42-cub3d-d248cde2309e9aa3f14a10ce2db0019afdf9f0f1.tar.gz
42-cub3d-d248cde2309e9aa3f14a10ce2db0019afdf9f0f1.tar.bz2
42-cub3d-d248cde2309e9aa3f14a10ce2db0019afdf9f0f1.tar.xz
42-cub3d-d248cde2309e9aa3f14a10ce2db0019afdf9f0f1.tar.zst
42-cub3d-d248cde2309e9aa3f14a10ce2db0019afdf9f0f1.zip
Collision fixed, still galering
-rw-r--r--inc/cub3d.h2
-rw-r--r--inc/cub3d_defines.h1
-rw-r--r--inc/cub3d_structs.h13
-rw-r--r--src/ft_darken_rgb.c26
-rw-r--r--src/ft_draw_verline.c20
-rw-r--r--src/ft_floor_cast.c37
-rw-r--r--src/ft_key_loop.c3
-rw-r--r--src/ft_raycasting.c1
8 files changed, 44 insertions, 59 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 4151daa..3875adc 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -120,7 +120,7 @@ uint8_t ft_use_args(int argc, const char *argv[],
*/
void ft_castray(t_cub *cl);
-void ft_floor_cast(t_cub *cl);
+void ft_floor_cast(uint16_t y, t_cub *cl);
void ft_detect(t_cub *cl);
/*
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index 66105fd..aee4e39 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -118,6 +118,7 @@ enum
# define FT_CHRST_MAP_ENTRY "012NSEWLD "
# define FT_CHRST_SPAWN "NSEW"
# define FT_CHRST_MAP_NON_WALL "02NESWLD"
+# define FT_CHRST_COLLISION "12 "
/*
** ====== BMP ======
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index ecbbaf3..d59c25e 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -122,22 +122,23 @@ typedef struct s_ray
{
uint16_t line_h;
float wall_dist;
+ float row_dist;
float x_ray_pos;
float y_ray_pos;
float x_ray_dir;
float y_ray_dir;
- float x_ray_dir_bis;
- float y_ray_dir_bis;
+ float x_ray_dir_f;
+ float y_ray_dir_f;
+ float x_ray_dir_f_bis;
+ float y_ray_dir_f_bis;
float x_side_dist;
float y_side_dist;
float x_delta_dist;
float y_delta_dist;
float floor_x;
float floor_y;
- int16_t ceil_x;
- int16_t ceil_y;
- float row_dist;
- float ceil_dist;
+ int16_t cell_x;
+ int16_t cell_y;
int16_t wall_t;
int16_t wall_b;
uint8_t side;
diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c
index 7f5e12a..5edfd89 100644
--- a/src/ft_darken_rgb.c
+++ b/src/ft_darken_rgb.c
@@ -12,23 +12,21 @@
#include <cub3d.h>
#include <stdint.h>
+#include <stdio.h>
uint32_t
ft_darken_ceil(t_rgb rgb, int32_t y, t_cub *cl)
{
t_rgb darker;
- float dist;
float calc;
darker = rgb;
- (void)y;
- dist = (cl->rlist.ceil_dist > 0) ? (cl->rlist.ceil_dist) : (0.0001);
- calc = dist * 0.4;
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
- darker.r /= calc;
- darker.g /= calc;
- darker.b /= calc;
+ calc = ((float)(y - (75000.0 / cl->wlist.y_size))
+ / (cl->wlist.y_size / 2));
+ calc = (calc < 0) ? (0) : (calc);
+ darker.r *= 1 - calc;
+ darker.g *= 1 - calc;
+ darker.b *= 1 - calc;
return (ft_rgb_to_hex(darker));
}
@@ -38,9 +36,13 @@ uint32_t
t_rgb darker;
float calc;
- calc = ((float)(y + (75000.0 / cl->wlist.y_size))
- / (cl->wlist.y_size / 2)) - 1.0;
- calc = (calc < 0) ? (0) : (calc);
+ /* calc = ((float)(y + (75000.0 / cl->wlist.y_size)) */
+ /* / (cl->wlist.y_size / 2)) - 1.0; */
+ /* calc = (calc < 0) ? (0) : (calc); */
+ (void)y;
+ calc = (cl->rlist.row_dist * 0.4);
+ calc = (calc >= 255) ? (255) : (calc);
+ calc = (calc < 1) ? (1) : (calc);
darker = rgb;
darker.r *= calc;
darker.g *= calc;
diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c
index 6fa0d1e..d32ac38 100644
--- a/src/ft_draw_verline.c
+++ b/src/ft_draw_verline.c
@@ -33,6 +33,7 @@ static void
i = 0;
while (i <= y)
{
+ ft_floor_cast(i, cl);
*(int*)(cl->img.ptr +
(x * 4 + (i * cl->img.sizeline)))
= ft_darken_ceil(cl->c_rgb, i, cl);
@@ -40,18 +41,14 @@ static void
}
}
-#include <stdio.h>
-static void
- ft_calc_ceil_dist(int32_t y, t_ray *rl, t_cub *cl)
-{
- int16_t p;
+/* #include <stdio.h> */
+/* static void */
+/* ft_calc_ceil_dist(int32_t y, t_ray *rl, t_cub *cl) */
+/* { */
+/* int16_t p; */
- p = y - cl->wlist.y_size / 2;
- cl->plist.pos_z = 0.5 * cl->wlist.y_size;
- rl->ceil_dist = cl->plist.pos_z / p;
- rl->ceil_dist = (rl->ceil_dist > 0) ? (rl->ceil_dist) : (-rl->ceil_dist);
- printf("%f\n", rl->ceil_dist);
-}
+/* printf("%f\n", rl->ceil_dist); */
+/* } */
int8_t
ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2)
@@ -61,7 +58,6 @@ int8_t
(y < 0) ? (y = 0) : 0;
(y2 < 0) ? (y2 = 0) : 0;
- ft_calc_ceil_dist(y, &cl->rlist, cl);
ft_draw_ceil(cl, y, x);
(cl->rlist.line_h <= 0) ? (cl->rlist.line_h = 1) : 0;
while (y < y2)
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c
index c82163a..482ee8a 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -18,38 +18,23 @@ static void
{
int16_t p;
- rl->x_ray_dir = pl->dir_x - pl->plane_x;
- rl->y_ray_dir = pl->dir_y - pl->plane_y;
- rl->x_ray_dir_bis = pl->dir_x + pl->plane_x;
- rl->y_ray_dir_bis = pl->dir_y + pl->plane_y;
+ rl->x_ray_dir_f = pl->dir_x - pl->plane_x;
+ rl->y_ray_dir_f = pl->dir_y - pl->plane_y;
+ rl->x_ray_dir_f_bis = pl->dir_x + pl->plane_x;
+ rl->y_ray_dir_f_bis = pl->dir_y + pl->plane_y;
p = y - cl->wlist.y_size / 2;
- pl->pos_z = 0.5 * cl->wlist.y_size;
rl->row_dist = pl->pos_z / p;
cl->mlist.x_floor_step = rl->row_dist *
- (rl->x_ray_dir_bis - rl->x_ray_dir) / cl->wlist.x_size;
+ (rl->x_ray_dir_f_bis - rl->x_ray_dir_f) / cl->wlist.x_size;
cl->mlist.y_floor_step = rl->row_dist *
- (rl->y_ray_dir_bis - rl->y_ray_dir) / cl->wlist.x_size;
- rl->floor_x = pl->pos_x + rl->row_dist * rl->x_ray_dir;
- rl->floor_y = pl->pos_y + rl->row_dist * rl->y_ray_dir;
+ (rl->y_ray_dir_f_bis - rl->y_ray_dir_f) / cl->wlist.x_size;
+ rl->floor_x = pl->pos_x + rl->row_dist * rl->x_ray_dir_f;
+ rl->floor_y = pl->pos_y + rl->row_dist * rl->y_ray_dir_f;
}
void
- ft_floor_cast(t_cub *cl)
+ ft_floor_cast(uint16_t y, t_cub *cl)
{
- uint16_t y;
- uint16_t x;
-
- y = 0;
- while (y < cl->wlist.y_size)
- {
- ft_initray(y, &cl->rlist, &cl->plist, cl);
- x = 1;
- while (x < cl->wlist.x_size)
- {
- cl->rlist.ceil_x = (int16_t)cl->rlist.floor_x;
- cl->rlist.ceil_y = (int16_t)cl->rlist.floor_y;
- x++;
- }
- y++;
- }
+ cl->plist.pos_z = 0.5 * cl->wlist.y_size;
+ ft_initray(y, &cl->rlist, &cl->plist, cl);
}
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index e2e2b5c..1d463bc 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -53,7 +53,8 @@ static void
pl = &cl->plist;
x = ft_find_x(key, pl);
y = ft_find_y(key, pl);
- if (cl->mlist.map[y][x] == '1' || cl->mlist.map[y][x] == '2')
+ if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[y][x]) ||
+ cl->mlist.map[y][x] == '\0')
{
pl->pos_y = old_y;
pl->pos_x = old_x;
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 5bb3649..50bdbf9 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -112,7 +112,6 @@ void
i = 0;
wl = &cl->wlist;
- /* ft_floor_cast(cl); */
while (i < wl->x_size)
{
ft_initray(cl, i);