aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2020-02-21 21:44:26 +0100
committersalaaad2 <arthurdurant263@gmail.com>2020-02-21 21:44:26 +0100
commit2bc91ff7a1cdb2c7a97df74d89609e0c3ca1bb8e (patch)
treebd46024aafd3a00d6ba9e140a7e8d4473c8a7bed
parenton est la (diff)
download42-cub3d-2bc91ff7a1cdb2c7a97df74d89609e0c3ca1bb8e.tar.gz
42-cub3d-2bc91ff7a1cdb2c7a97df74d89609e0c3ca1bb8e.tar.bz2
42-cub3d-2bc91ff7a1cdb2c7a97df74d89609e0c3ca1bb8e.tar.xz
42-cub3d-2bc91ff7a1cdb2c7a97df74d89609e0c3ca1bb8e.tar.zst
42-cub3d-2bc91ff7a1cdb2c7a97df74d89609e0c3ca1bb8e.zip
que des maths
-rw-r--r--inc/cub3d.h1
-rw-r--r--inc/cub3d_structs.h10
-rw-r--r--src/ft_get_sprite.c20
-rw-r--r--src/ft_raycasting.c12
4 files changed, 39 insertions, 4 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 09ea32e..87f6ef3 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -83,6 +83,5 @@ void ft_draw_circle(int32_t a, int32_t b,
int32_t color, t_cub *cl);
void ft_draw_texture(t_cub *cl, int x, int y, int tex_y);
int8_t ft_check_not_found(const char *path);
-void ft_calc_tex(t_cub *clist);
# endif
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 7731563..72cc377 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -49,14 +49,19 @@ typedef struct s_rgb
typedef struct s_sprite
{
- int32_t s_x;
- int32_t s_y;
+ int32_t s_pos_x;
+ int32_t s_pos_y;
+ double s_x;
+ double s_y;
int32_t s_h;
int32_t s_w;
int32_t s_start_x;
int32_t s_start_y;
int32_t s_tex_y;
+ double sprite_transform_x;
+ double sprite_transform_y;
double sprite_dist;
+ double inv_c_m;
} t_sprite;
typedef struct s_player
@@ -128,6 +133,7 @@ typedef struct s_cub
struct s_rgb f_rgb;
struct s_rgb c_rgb;
struct s_img tlist[5];
+ struct s_sprite sp_list;
} t_cub;
# endif
diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c
index 43de290..806489f 100644
--- a/src/ft_get_sprite.c
+++ b/src/ft_get_sprite.c
@@ -17,8 +17,26 @@
void
ft_get_sprite_spawn(t_cub *clist)
{
+ size_t x;
+ size_t y;
- (void)clist;
+ x = 1;
+ y = 1;
+ while (clist->mlist->map[y])
+ {
+ while (clist->mlist->map[y][x])
+ {
+ if (ft_ischarset("2", clist->mlist->map[y][x]))
+ {
+ clist->sp_list.s_pos_x = x + 0.5;
+ clist->sp_list.s_pos_y = y + 0.5;
+ return ;
+ }
+ x++;
+ }
+ x = 1;
+ y++;
+ }
}
int8_t
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index dd2be64..589d2da 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -16,6 +16,17 @@
#include <math.h>
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.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);
+ cl->sp_list.sprite_transform_y = cl->sp_list.inv_c_m * (cl->plist->plane_y * cl->sp_list.s_x - cl->plist->plane_x * cl->sp_list.s_y);
+
+}
+
+static void
ft_calc_tex(t_cub *clist)
{
if (clist->rlist.side == 0)
@@ -83,6 +94,7 @@ void
cl->rlist.wall_b = wl->y_size - 1;
ft_choose_tex(cl);
ft_calc_tex(cl);
+ ft_calc_sprite(cl);
ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b);
i++;
}