aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--map/map_one.cub6
-rw-r--r--src/ft_draw_scene.c2
-rw-r--r--src/ft_draw_sprite.c22
3 files changed, 22 insertions, 8 deletions
diff --git a/map/map_one.cub b/map/map_one.cub
index 857127f..9142d01 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -10,9 +10,9 @@ C 50,100,200
F 50,190,124
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
-1 0 0 2 0 0 0 0 0 0 1 1 0 0 0 0 0 1
-1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
-1 N 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1
+1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1
+1 0 0 1 0 2 0 0 0 0 0 0 0 0 0 0 0 1
+1 N 1 1 0 2 0 0 0 1 1 1 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1
1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1
1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c
index f974d42..a1a4a20 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -25,7 +25,7 @@ void
ft_castray(clist);
if (clist->ishud)
ft_draw_hud(clist);
- ft_calc_sprite(clist);
+ ft_calc_sprite(clist);
mlx_put_image_to_window(clist->wlist->wlx,
clist->wlist->winptr, clist->img.img, 0, 0);
mlx_destroy_image(clist->wlist->wlx, clist->img.img);
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c
index 8c1b848..e412998 100644
--- a/src/ft_draw_sprite.c
+++ b/src/ft_draw_sprite.c
@@ -53,11 +53,24 @@ void
void
ft_sprite_height(t_cub *cl, t_sprite *sprite)
{
+ sprite->spriteheight = abs((int)(cl->wlist->y_size / (sprite->transformy)));
+ sprite->drawstarty = -sprite->spriteheight / 2 + cl->wlist->y_size / 2;
+ if(sprite->drawstarty < 0)
+ sprite->drawstarty = 0;
+ sprite->drawendy = sprite->spriteheight / 2 + cl->wlist->y_size / 2;
+ if(sprite->drawendy >= (int)cl->wlist->y_size)
+ sprite->drawendy = cl->wlist->y_size - 1;
}
void
ft_sprite_width(t_cub *cl, t_sprite *sprite)
{
+ sprite->spritewidth = abs((int)(cl->wlist->x_size / (sprite->transformy)));
+ sprite->drawstartx = -sprite->spritewidth / 2 + sprite->spritescreenx;
+ if(sprite->drawstartx < 0)
+ sprite->drawstartx = 0;
+ sprite->drawendx = sprite->spritewidth / 2 + sprite->spritescreenx;
+ if(sprite->drawendx >= (int)cl->wlist->x_size) sprite->drawendx = cl->wlist->x_size - 1;
}
void
@@ -69,11 +82,12 @@ void
while (i < cl->mlist->sprite_nbr)
{
sprite = cl->sprites[i];
- sprite.spritex = sprite.s_pos_x - cl->plist->pos_x;
- sprite.spritey = sprite.s_pos_y - cl->plist->pos_y;
- sprite.invdet = 1.0 / (cl->plist.plane_x * cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); //required for correct matrix multiplication
+ sprite.spritey = sprite.s_pos_x - cl->plist->pos_x;
+ sprite.spritex = sprite.s_pos_y - cl->plist->pos_y;
+ sprite.invdet = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y);
sprite.transformx = sprite.invdet * (cl->plist->dir_y * sprite.spritex- cl->plist->dir_x* sprite.spritey);
- sprite.transformy = invDet * (-cl->plist->plane_y* sprite.spritex + cl->plist->plane_x * sprite.spritey);
+ sprite.transformy = sprite.invdet * (-cl->plist->plane_y* sprite.spritex + cl->plist->plane_x * sprite.spritey);
+ sprite.spritescreenx = (int)(cl->wlist->x_size / 2) * (1 + sprite.transformx / sprite.transformy);
ft_sprite_height(cl, &sprite);
ft_sprite_width(cl, &sprite);
ft_draw_sprite(cl, &sprite);