aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-03-07 20:30:07 +0100
committerRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-03-07 20:30:07 +0100
commitced2be0469537a5d21043325c9bc54762197ec30 (patch)
tree0147b95e157bec2b301e82badc1532d40335201b /src
parentThe sky is nice (diff)
download42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.tar.gz
42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.tar.bz2
42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.tar.xz
42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.tar.zst
42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.zip
qwe
Diffstat (limited to 'src')
-rw-r--r--src/ft_darken_rgb.c33
-rw-r--r--src/ft_draw_scene.c19
-rw-r--r--src/ft_draw_verline.c6
-rw-r--r--src/ft_rgb_to_hex.c6
4 files changed, 41 insertions, 23 deletions
diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c
index 3587d72..fe69fa2 100644
--- a/src/ft_darken_rgb.c
+++ b/src/ft_darken_rgb.c
@@ -15,20 +15,33 @@
#include <stdio.h>
uint32_t
- ft_darken_rgb(t_rgb rgb, t_cub *cl)
+ ft_darken_ceil(t_rgb rgb, t_cub *cl)
{
t_rgb darker;
- float dist;
float calc;
- if ((dist = cl->rlist.wall_dist) <= 0)
- dist = 0.0001;
- calc = (dist * 0.2);
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
darker = rgb;
- darker.r /= calc;
- darker.g /= calc;
- darker.b /= calc;
+ calc = ((float)(cl->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));
+}
+
+uint32_t
+ ft_darken_floor(t_rgb rgb, t_cub *cl)
+{
+ t_rgb darker;
+ float calc;
+
+ calc = ((float)(cl->y + (75000.0 / cl->wlist.y_size))
+ / (cl->wlist.y_size / 2)) - 1.0;
+ calc = (calc < 0) ? (0) : (calc);
+ darker = rgb;
+ darker.r *= calc;
+ darker.g *= calc;
+ darker.b *= calc;
return (ft_rgb_to_hex(darker));
}
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c
index f96eae6..e7895f5 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -21,20 +21,18 @@ static int8_t
const uint32_t x = 15;
const uint32_t y = clist->wlist.y_size
- (clist->mlist.map_h * clist->mlist.scale) - 20;
- const uint8_t len = 6 + ft_uintlen(clist->currlvl);
+ uint8_t len;
char *str;
+ len = 6 + ft_uintlen(clist->currlvl);
if (!(str = (char*)malloc((len + 1) * sizeof(char))))
return (-1);
ft_sprintf(str, "Stage %hd", clist->currlvl);
- if (clist->mlist.isnlvl)
- {
- mlx_string_put(clist->wlist.wlx,
- clist->wlist.winptr,
- x, y,
- 0x00ff0000,
- str);
- }
+ mlx_string_put(clist->wlist.wlx,
+ clist->wlist.winptr,
+ x, y,
+ 0x00ff0000,
+ str);
ft_memdel((void**)&str);
return (0);
}
@@ -50,11 +48,10 @@ void
if (clist->ishud)
{
ft_draw_hud(clist);
- ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist);
}
mlx_put_image_to_window(clist->wlist.wlx,
clist->wlist.winptr, clist->img.img, 0, 0);
- if (clist->ishud)
+ if (clist->ishud && clist->mlist.isnlvl)
{
if (ft_put_stage(clist) < 0)
{
diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c
index 3198357..8621668 100644
--- a/src/ft_draw_verline.c
+++ b/src/ft_draw_verline.c
@@ -18,9 +18,10 @@ static void
{
while ((uint32_t)y < cl->wlist.y_size)
{
+ cl->y = y;
*(int*)(cl->img.ptr +
(x * 4 + (y * cl->img.sizeline)))
- = ft_rgb_to_hex(cl->f_rgb);
+ = ft_darken_floor(cl->f_rgb, cl);
y++;
}
}
@@ -33,9 +34,10 @@ static void
i = 0;
while (i <= y)
{
+ cl->y = i;
*(int*)(cl->img.ptr +
(x * 4 + (i * cl->img.sizeline)))
- = ft_darken_rgb(cl->c_rgb, cl);
+ = ft_darken_ceil(cl->c_rgb, cl);
i++;
}
}
diff --git a/src/ft_rgb_to_hex.c b/src/ft_rgb_to_hex.c
index a25d3e0..e101dcf 100644
--- a/src/ft_rgb_to_hex.c
+++ b/src/ft_rgb_to_hex.c
@@ -18,6 +18,12 @@ uint32_t
{
uint32_t res;
+ rgb.r = (rgb.r > 255) ? (255) : (rgb.r);
+ rgb.g = (rgb.g > 255) ? (255) : (rgb.g);
+ rgb.b = (rgb.b > 255) ? (255) : (rgb.b);
+ rgb.r = (rgb.r < 0) ? (0) : (rgb.r);
+ 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);
return (res);