aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_verline.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_draw_verline.c53
1 files changed, 40 insertions, 13 deletions
diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c
index d32ac38..b7084cc 100644
--- a/src/ft_draw_verline.c
+++ b/src/ft_draw_verline.c
@@ -14,13 +14,50 @@
#include <stdint.h>
static void
+ ft_draw_floor_tex(t_cub *cl, int32_t y, int32_t x, int32_t tex_y)
+{
+ 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 * tex_y];
+ 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 * tex_y + 1];
+ 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 * tex_y + 2];
+ cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (int8_t)0;
+}
+
+#include <libft.h>
+static void
ft_draw_floor(t_cub *cl, int32_t y, int32_t x)
{
+ float dist_player;
+ float curr_dist;
+ float weight;
+ float curr_floor_x;
+ float curr_floor_y;
+
+ dist_player = 0.0;
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);
+ curr_dist = cl->wlist.y_size / (2.0 * y - cl->wlist.y_size);
+ weight = (curr_dist - dist_player)
+ / (cl->rlist.wall_dist - dist_player);
+ curr_floor_x = weight * cl->rlist.floor_x_wall
+ + (1.0 - weight) * cl->plist.pos_x;
+ curr_floor_y = weight * cl->rlist.floor_y_wall
+ + (1.0 - weight) * cl->plist.pos_y;
+ cl->tlist[6].tex_x = (int32_t)(curr_floor_x
+ * cl->tlist[6].img_w) % cl->tlist[6].img_w;
+ cl->tlist[6].tex_y = (int32_t)(curr_floor_y
+ * cl->tlist[6].img_h) % cl->tlist[6].img_h;
+ cl->tlist[6].tex_x = (cl->tlist[6].tex_x > 0) ? (cl->tlist[6].tex_x) : (-cl->tlist[6].tex_x);
+ cl->tlist[6].tex_y = (cl->tlist[6].tex_y > 0) ? (cl->tlist[6].tex_y) : (-cl->tlist[6].tex_y);
+ ft_draw_floor_tex(cl, y, x, cl->tlist[6].tex_y);
+ /* *(int*)(cl->img.ptr + */
+ /* (x * 4 + (y * cl->img.sizeline))) */
+ /* = ft_darken_floor(cl->f_rgb, weight, cl); */
y++;
}
}
@@ -33,7 +70,6 @@ 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);
@@ -41,15 +77,6 @@ static void
}
}
-/* #include <stdio.h> */
-/* static void */
-/* ft_calc_ceil_dist(int32_t y, t_ray *rl, t_cub *cl) */
-/* { */
-/* int16_t p; */
-
-/* printf("%f\n", rl->ceil_dist); */
-/* } */
-
int8_t
ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2)
{