diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-23 18:04:38 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-23 18:04:38 +0100 |
commit | 50759fcc4f3b939ad35254ce220c206056f3f31e (patch) | |
tree | fd28f91d64ccefe142927eeaf9dc85e5719c3666 | |
parent | Good tweak (diff) | |
download | 42-cub3d-50759fcc4f3b939ad35254ce220c206056f3f31e.tar.gz 42-cub3d-50759fcc4f3b939ad35254ce220c206056f3f31e.tar.bz2 42-cub3d-50759fcc4f3b939ad35254ce220c206056f3f31e.tar.xz 42-cub3d-50759fcc4f3b939ad35254ce220c206056f3f31e.tar.zst 42-cub3d-50759fcc4f3b939ad35254ce220c206056f3f31e.zip |
Fixed
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/cub3d.h | 2 | ||||
-rw-r--r-- | map/lvl_three.cub | 2 | ||||
-rw-r--r-- | src/ft_darken_rgb.c | 33 | ||||
-rw-r--r-- | src/ft_draw_heals.c | 25 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 26 | ||||
-rw-r--r-- | src/ft_draw_textures.c | 19 | ||||
-rw-r--r-- | src/ft_draw_traps.c | 26 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 1 | ||||
-rw-r--r-- | src/ft_draw_weapons.c | 26 | ||||
-rw-r--r-- | src/ft_floor_cast.c | 5 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 1 | ||||
-rw-r--r-- | src/ft_raycasting.c | 1 | ||||
-rw-r--r-- | src/ft_rgb_to_hex.c | 9 | ||||
-rw-r--r-- | src/ft_suffer_animation.c | 2 |
15 files changed, 69 insertions, 110 deletions
@@ -63,7 +63,6 @@ SRCS_NAME += ft_extra_keys.c SRCS_NAME += ft_draw_verline.c SRCS_NAME += ft_rgb_to_hex.c SRCS_NAME += ft_hex_to_rgb.c -SRCS_NAME += ft_darken_rgb.c SRCS_NAME += ft_raycasting.c SRCS_NAME += ft_init_s_ray.c SRCS_NAME += ft_init_map.c diff --git a/inc/cub3d.h b/inc/cub3d.h index 0d8fede..faf990b 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -218,7 +218,7 @@ void ft_music_fork(char **mcmd_words, char *const envp[]); int8_t ft_save_to_bmp(t_cub *cl); int ft_error(uint8_t retval, const char *errmsg, t_cub *clist); int8_t ft_warp_level(char *path, t_cub *cl); -uint32_t ft_rgb_to_hex(t_rgb rgb); +uint32_t ft_rgb_to_hex(float dist, t_rgb rgb, t_cub *cl); t_bmp_rgb ft_hex_to_rgb(uint32_t color); uint32_t ft_darken(t_rgb rgb, t_cub *cl); void ft_death_screen(t_cub *cl); diff --git a/map/lvl_three.cub b/map/lvl_three.cub index e4ea8c7..3044f7f 100644 --- a/map/lvl_three.cub +++ b/map/lvl_three.cub @@ -27,5 +27,5 @@ MU ./media/sound/BITURE-ET-MELANCOLIE.wav 10011111011111111111101 1001 101 101 10011111011111111111101 -1200000000000T000!00001 +1200000000000T!00000001 11111111111111111111111 diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c deleted file mode 100644 index 223a540..0000000 --- a/src/ft_darken_rgb.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_darken_rgb.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/03/05 16:04:28 by rbousset #+# #+# */ -/* Updated: 2020/03/05 16:04:29 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#include <cub3d.h> -#include <stdint.h> - -uint32_t - ft_darken(t_rgb rgb, t_cub *cl) -{ - t_rgb darker; - float calc; - float dist; - - if ((dist = cl->rlist.row_dist) <= 0) - dist = 0.0001; - calc = (dist * 0.1 * cl->mlist.darklvl); - calc = (calc >= 255) ? (255) : (calc); - calc = (calc < 1) ? (1) : (calc); - darker = rgb; - darker.r /= calc; - darker.g /= calc; - darker.b /= calc; - return (ft_rgb_to_hex(darker)); -} diff --git a/src/ft_draw_heals.c b/src/ft_draw_heals.c index bc1e1b2..0ef9590 100644 --- a/src/ft_draw_heals.c +++ b/src/ft_draw_heals.c @@ -61,22 +61,19 @@ static void ft_put_heal(t_sprite *sprite, t_cub *cl) { float dist; - float calc; + t_rgb rgb; - if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0) + if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) + + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) dist = 0.0001; - calc = (dist * 0.1 * cl->mlist.darklvl); - calc = (calc >= 255) ? (255) : (calc); - calc = (calc < 1) ? (1) : (calc); - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = - (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[17].img_h * sprite->tex_y] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = - (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[17].img_h * sprite->tex_y + 1] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = - (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[17].img_h * sprite->tex_y + 2] / calc; + rgb.r = (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y + 2]; + rgb.g = (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y + 1]; + rgb.b = (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y]; + *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + + (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } void diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 5fc28d3..b381957 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -13,7 +13,6 @@ #include <libft.h> #include <cub3d.h> #include <stdint.h> -#include <stdio.h> #include <stdlib.h> #include <math.h> @@ -69,22 +68,19 @@ static void ft_put_sprite(t_sprite *sprite, t_cub *cl) { float dist; - float calc; + t_rgb rgb; - if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0) + if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) + + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) dist = 0.0001; - calc = (dist * 0.1 * cl->mlist.darklvl); - calc = (calc >= 255) ? (255) : (calc); - calc = (calc < 1) ? (1) : (calc); - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = - (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = - (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = - (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2] / calc; + rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x + * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2]; + rgb.g = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x + * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1]; + rgb.b = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x + * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y]; + *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + + (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } void diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index 126d0af..4bc0b78 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -26,22 +26,21 @@ void ft_draw_texture(t_cub *cl, int x, int y, int tex_y) { float dist; - float calc; + t_rgb rgb; if ((dist = cl->rlist.wall_dist) <= 0) dist = 0.0001; - calc = (dist * 0.1 * cl->mlist.darklvl); - calc = (calc >= 255) ? (255) : (calc); - calc = (calc < 1) ? (1) : (calc); - cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = + rgb.b = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y] / calc; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = + cl->tlist[cl->w_side].img_h * tex_y]; + rgb.g = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y + 1] / calc; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = + cl->tlist[cl->w_side].img_h * tex_y + 1]; + rgb.r = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y + 2] / calc; + cl->tlist[cl->w_side].img_h * tex_y + 2]; + *(int*)(cl->img.ptr + ((uint16_t)x * 4 + + (y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } void diff --git a/src/ft_draw_traps.c b/src/ft_draw_traps.c index 05e8446..ed53dc0 100644 --- a/src/ft_draw_traps.c +++ b/src/ft_draw_traps.c @@ -12,6 +12,7 @@ #include <cub3d.h> #include <stdint.h> +#include <math.h> static void ft_sort_traps_norme(float *dist_tab, int32_t it, t_cub *cl) @@ -58,22 +59,19 @@ static void ft_put_trap(t_sprite *sprite, t_cub *cl) { float dist; - float calc; + t_rgb rgb; - if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0) + if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) + + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) dist = 0.0001; - calc = (dist * 0.1 * cl->mlist.darklvl); - calc = (calc >= 255) ? (255) : (calc); - calc = (calc < 1) ? (1) : (calc); - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = - (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[15].img_h * sprite->tex_y] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = - (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[15].img_h * sprite->tex_y + 1] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = - (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[15].img_h * sprite->tex_y + 2] / calc; + rgb.r = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y + 2]; + rgb.g = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y + 1]; + rgb.b = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y]; + *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + + (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } void diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 16dc63c..7bfba8d 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include <stdio.h> #include <cub3d.h> #include <stdint.h> diff --git a/src/ft_draw_weapons.c b/src/ft_draw_weapons.c index 2e1ec13..c527987 100644 --- a/src/ft_draw_weapons.c +++ b/src/ft_draw_weapons.c @@ -12,6 +12,7 @@ #include <cub3d.h> #include <stdint.h> +#include <math.h> static void ft_sort_weapons_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) @@ -65,22 +66,19 @@ static void ft_put_weapon(t_sprite *sprite, t_cub *cl) { float dist; - float calc; + t_rgb rgb; - if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0) + if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) + + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) dist = 0.0001; - calc = (dist * 0.1 * cl->mlist.darklvl); - calc = (calc >= 255) ? (255) : (calc); - calc = (calc < 1) ? (1) : (calc); - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = - (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = - (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = - (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2] / calc; + rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x + * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2]; + rgb.g = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x + * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1]; + rgb.b = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x + * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y]; + *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + + (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } void diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 160a2c1..9166147 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -16,8 +16,11 @@ static void ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) { + float dist; + + dist = (cl->rlist.row_dist > 0) ? (cl->rlist.row_dist) : (0.0001); *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl); + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } static void diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 5a5ecd0..05b13b2 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -13,7 +13,6 @@ #include <libft.h> #include <cub3d.h> #include <stdint.h> -#include <stdio.h> static int8_t ft_get_sprite_id(char *word) diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 7baac29..e6c87ff 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -13,7 +13,6 @@ #include <libft.h> #include <cub3d.h> #include <stdint.h> -#include <stdio.h> #include <stdlib.h> #include <math.h> diff --git a/src/ft_rgb_to_hex.c b/src/ft_rgb_to_hex.c index e101dcf..2b72287 100644 --- a/src/ft_rgb_to_hex.c +++ b/src/ft_rgb_to_hex.c @@ -14,10 +14,14 @@ #include <stdint.h> uint32_t - ft_rgb_to_hex(t_rgb rgb) + ft_rgb_to_hex(float dist, t_rgb rgb, t_cub *cl) { uint32_t res; + float calc; + calc = (dist * 0.1 * cl->mlist.darklvl); + calc = (calc >= 255) ? (255) : (calc); + calc = (calc < 1) ? (1) : (calc); rgb.r = (rgb.r > 255) ? (255) : (rgb.r); rgb.g = (rgb.g > 255) ? (255) : (rgb.g); rgb.b = (rgb.b > 255) ? (255) : (rgb.b); @@ -25,6 +29,7 @@ uint32_t rgb.g = (rgb.g < 0) ? (0) : (rgb.g); rgb.b = (rgb.b < 0) ? (0) : (rgb.b); res = 0; - res += ((rgb.r << 16) + (rgb.g << 8) + rgb.b); + res += (((uint8_t)(rgb.r / calc) << 16) + ((uint8_t)(rgb.g / calc) << 8) + + (uint8_t)(rgb.b / calc)); return (res); } diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index 51de24a..1b48e47 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -75,7 +75,7 @@ void rgb.g += 20; rgb.b += 20; *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(0, rgb, cl); } } ft_get_damaged(cl); |