aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-09 01:52:21 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-09 01:52:21 +0100
commitc51419a68e38ed3a2eb28e740f72eaa436fbd106 (patch)
tree4cafa4ee075be34b32132c54fdda87c7ec996695 /src
parentNigga my gun go off (diff)
download42-cub3d-c51419a68e38ed3a2eb28e740f72eaa436fbd106.tar.gz
42-cub3d-c51419a68e38ed3a2eb28e740f72eaa436fbd106.tar.bz2
42-cub3d-c51419a68e38ed3a2eb28e740f72eaa436fbd106.tar.xz
42-cub3d-c51419a68e38ed3a2eb28e740f72eaa436fbd106.tar.zst
42-cub3d-c51419a68e38ed3a2eb28e740f72eaa436fbd106.zip
Boy
Diffstat (limited to 'src')
-rw-r--r--src/ft_darken_rgb.c33
-rw-r--r--src/ft_draw_verline.c29
-rw-r--r--src/ft_floor_cast.c39
-rw-r--r--src/ft_tex_init.c10
4 files changed, 51 insertions, 60 deletions
diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c
index 656aac7..4c571cf 100644
--- a/src/ft_darken_rgb.c
+++ b/src/ft_darken_rgb.c
@@ -14,33 +14,20 @@
#include <stdint.h>
uint32_t
- ft_darken_ceil(t_rgb rgb, int32_t y, t_cub *cl)
+ 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.4);
+ calc = (calc >= 255) ? (255) : (calc);
+ calc = (calc < 1) ? (1) : (calc);
darker = rgb;
- 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;
+ darker.r /= calc;
+ darker.g /= calc;
+ darker.b /= calc;
return (ft_rgb_to_hex(darker));
}
-
-/* uint32_t */
-/* ft_darken_floor(t_rgb rgb, int32_t y, t_cub *cl) */
-/* { */
-/* 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); */
-/* darker = rgb; */
-/* darker.r *= calc; */
-/* darker.g *= calc; */
-/* darker.b *= calc; */
-/* return (ft_rgb_to_hex(darker)); */
-/* } */
diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c
index b6729de..7bfba8d 100644
--- a/src/ft_draw_verline.c
+++ b/src/ft_draw_verline.c
@@ -13,33 +13,6 @@
#include <cub3d.h>
#include <stdint.h>
-/* static void */
-/* ft_draw_floor(t_cub *cl, int32_t y, int32_t x) */
-/* { */
-/* while ((uint32_t)y < cl->wlist.y_size) */
-/* { */
-/* *(int*)(cl->img.ptr + */
-/* (x * 4 + (y * cl->img.sizeline))) */
-/* = ft_darken_floor(cl->f_rgb, y, cl); */
-/* y++; */
-/* } */
-/* } */
-
-static void
- ft_draw_ceil(t_cub *cl, int32_t y, int32_t x)
-{
- int16_t i;
-
- i = 0;
- while (i <= y)
- {
- *(int*)(cl->img.ptr +
- (x * 4 + (i * cl->img.sizeline)))
- = ft_darken_ceil(cl->c_rgb, i, cl);
- i++;
- }
-}
-
int8_t
ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2)
{
@@ -48,7 +21,6 @@ int8_t
(y < 0) ? (y = 0) : 0;
(y2 < 0) ? (y2 = 0) : 0;
- ft_draw_ceil(cl, y, x);
(cl->rlist.line_h <= 0) ? (cl->rlist.line_h = 1) : 0;
while (y < y2)
{
@@ -59,6 +31,5 @@ int8_t
ft_draw_texture(cl, x, y, tex_y);
y++;
}
- /* ft_draw_floor(cl, y, x); */
return (0);
}
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c
index 6947403..1b22a71 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -13,18 +13,34 @@
#include <cub3d.h>
#include <stdint.h>
+/* static void */
+/* ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) */
+/* { */
+/* *(int*)(cl->img.ptr + */
+/* (x * 4 + (y * cl->img.sizeline))) */
+/* = ft_darken(rgb, cl); */
+/* } */
+
static void
- ft_put_floor_tex(uint16_t y, uint16_t x, t_cub *cl)
+ ft_draw_extra_tex(uint8_t tid, uint16_t y, uint16_t x, t_cub *cl)
{
+ float dist;
+ float calc;
+
+ if ((dist = cl->rlist.row_dist) <= 0)
+ dist = 0.0001;
+ calc = (dist * 0.4);
+ calc = (calc >= 255) ? (255) : (calc);
+ calc = (calc < 1) ? (1) : (calc);
cl->img.ptr[x * 4 + (cl->img.sizeline * y)] =
- (uint8_t)cl->tlist[6].ptr[cl->tlist[6].tex_x * 4 + 4 *
- cl->tlist[6].img_h * cl->tlist[6].tex_y];
+ (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+ cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc;
cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] =
- (uint8_t)cl->tlist[6].ptr[cl->tlist[6].tex_x * 4 + 4 *
- cl->tlist[6].img_h * cl->tlist[6].tex_y + 1];
+ (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+ cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1] / calc;
cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =
- (uint8_t)cl->tlist[6].ptr[cl->tlist[6].tex_x * 4 + 4 *
- cl->tlist[6].img_h * cl->tlist[6].tex_y + 2];
+ (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+ cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 2] / calc;
cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0;
}
@@ -37,9 +53,16 @@ static void
* (rl->x_floor - rl->x_cell)) % (cl->tlist[6].img_w);
cl->tlist[6].tex_x = (int32_t)(cl->tlist[6].img_h
* (rl->y_floor - rl->y_cell)) % (cl->tlist[6].img_h);
+ cl->tlist[7].tex_y = (int32_t)(cl->tlist[7].img_w
+ * (rl->x_floor - rl->x_cell)) % (cl->tlist[7].img_w);
+ cl->tlist[7].tex_x = (int32_t)(cl->tlist[7].img_h
+ * (rl->y_floor - rl->y_cell)) % (cl->tlist[7].img_h);
rl->x_floor += cl->mlist.x_floor_step;
rl->y_floor += cl->mlist.y_floor_step;
- ft_put_floor_tex(y, x, cl);
+ ft_draw_extra_tex(6, y, x, cl);
+ ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl);
+ /* ft_draw_plain_horizontal(cl->f_rgb, cl, y, x); */
+ /* ft_draw_plain_horizontal(cl->c_rgb, cl, cl->wlist.y_size - y - 1, x); */
}
void
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 116f537..599e902 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -42,6 +42,15 @@ static void
&cl->tlist[6].bpp, &cl->tlist[6].sizeline, &cl->tlist[6].endian);
}
+static void
+ ft_get_ceil_tex(t_cub *cl)
+{
+ cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ cl->mlist.no_tex_path, &cl->tlist[7].img_w, &cl->tlist[7].img_h);
+ cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img,
+ &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian);
+}
+
void
ft_wall_tex_init(t_cub *cl)
{
@@ -68,5 +77,6 @@ void
if (cl->mlist.isnlvl)
ft_get_nlvl_img(cl);
ft_get_floor_tex(cl);
+ ft_get_ceil_tex(cl);
cl->walltexgood = 1;
}