aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_raycasting.c
diff options
context:
space:
mode:
authorsalaaad2 <arthudurant263@gmail.com>2020-02-24 22:20:33 +0100
committersalaaad2 <arthudurant263@gmail.com>2020-02-24 22:20:33 +0100
commitfe145d4c59886b857b0966f8e9b673cfacc0695f (patch)
tree6f613a668ecd532d185b4b31d7b5fe8122d271de /src/ft_raycasting.c
parentNorme (diff)
download42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.tar.gz
42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.tar.bz2
42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.tar.xz
42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.tar.zst
42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.zip
found 2 infinit loops hehe
Diffstat (limited to 'src/ft_raycasting.c')
-rw-r--r--src/ft_raycasting.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index d51b77f..626ced4 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -13,34 +13,17 @@
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static void
- ft_calc_sprite_norme(t_cub *cl)
-{
- if (cl->sp_list.s_start_y < 0)
- cl->sp_list.s_start_y = 0;
- cl->sp_list.s_end_y = cl->sp_list.s_h / 2 + cl->wlist->y_size / 2;
- if (cl->sp_list.s_end_y > (int)cl->wlist->y_size)
- cl->sp_list.s_end_y = cl->wlist->y_size - 1;
- cl->sp_list.s_w = abs((int)(cl->wlist->x_size
- * cl->sp_list.sprite_transform_y)); /*sprite width*/
- cl->sp_list.s_start_x = -cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x;
- if (cl->sp_list.s_start_x < 0)
- cl->sp_list.s_start_y = 0;
- cl->sp_list.s_end_x = cl->sp_list.s_w / 2 + cl->wlist->x_size;
- if (cl->sp_list.s_end_x < (int)cl->wlist->x_size)
- cl->sp_list.s_end_x = cl->wlist->x_size - 1;
-}
-
-static void
ft_calc_sprite(t_cub *cl)
{
cl->sp_list.s_x = cl->sp_list.s_pos_x - cl->plist->pos_x;
cl->sp_list.s_y = cl->sp_list.s_pos_y - cl->plist->pos_y;
- cl->sp_list.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_x
- - cl->plist->dir_y * cl->plist->plane_y);
+ cl->sp_list.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_y
+ - cl->plist->dir_x * cl->plist->plane_y);
cl->sp_list.sprite_transform_x = cl->sp_list.inv_c_m
* (cl->plist->dir_y * cl->sp_list.s_x
- cl->plist->dir_x * cl->sp_list.s_y);
@@ -52,11 +35,33 @@ static void
/ cl->sp_list.sprite_transform_y));
cl->sp_list.s_h =
abs((int)(cl->wlist->y_size * cl->sp_list.sprite_transform_y));
- cl->sp_list.s_start_y = -cl->sp_list.s_h / 2 + cl->wlist->y_size / 2;
ft_calc_sprite_norme(cl);
}
void
+ ft_calc_sprite_norme(t_cub *cl)
+{
+ cl->sp_list.s_start_y = -cl->sp_list.s_h / 2 + cl->wlist->y_size / 2;
+ if (cl->sp_list.s_start_y < 0)
+ cl->sp_list.s_start_y = 0;
+ cl->sp_list.s_end_y = cl->sp_list.s_h / 2 + cl->wlist->y_size / 2;
+ if (cl->sp_list.s_end_y > (int)cl->wlist->y_size)
+ cl->sp_list.s_end_y = cl->wlist->y_size - 1;
+ cl->sp_list.s_w = abs((int)(cl->wlist->x_size
+ * cl->sp_list.sprite_transform_y)); /*sprite width*/
+ cl->sp_list.s_start_x = -cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x;
+ if (cl->sp_list.s_start_x < 0)
+ cl->sp_list.s_start_y = 0;
+ cl->sp_list.s_end_x = cl->sp_list.s_w / 2 + cl->wlist->x_size;
+ if (cl->sp_list.s_end_x < (int)cl->wlist->x_size)
+ cl->sp_list.s_end_x = cl->wlist->x_size - 1;
+ /*ft_printf("start x: %d\nstart y : %d\n", cl->sp_list.s_start_x, cl->sp_list.s_start_y);*/
+ /*ft_printf("end x: %d\nend y : %d\n", cl->sp_list.s_end_x, cl->sp_list.s_end_y);*/
+ /*ft_draw_sprite(cl);*/
+}
+
+
+void
ft_calc_tex(t_cub *clist)
{
if (clist->rlist.side == 0)
@@ -112,6 +117,7 @@ void
i = 0;
wl = cl->wlist;
+ ft_calc_sprite(cl);
while (i < wl->x_size)
{
ft_initray(cl, i);
@@ -124,8 +130,6 @@ void
cl->rlist.wall_b = wl->y_size - 1;
ft_choose_tex(cl);
ft_calc_tex(cl);
- ft_calc_sprite(cl);
- /* ft_draw_sprite(cl , i); */
ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b);
i++;
}