fix 1 000 000 problem

This commit is contained in:
kinou-p 2022-06-13 11:14:41 +02:00
parent edba4a3e76
commit 99c3b6376b
7 changed files with 50 additions and 16 deletions

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/02/13 16:27:49 by apommier #+# #+# #
# Updated: 2022/05/06 18:52:57 by apommier ### ########.fr #
# Updated: 2022/06/11 13:31:36 by apommier ### ########.fr #
# #
# **************************************************************************** #
@ -14,6 +14,8 @@ NAME = Cub3D
SRCS = srcs/main.c\
srcs/get_texture_array.c\
srcs/cast_ray.c\
srcs/parsing/parse_map.c\
srcs/parsing/check_color_texture.c\
srcs/utils.c
OBJS = ${SRCS:.c=.o}
CC = gcc

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
/* Updated: 2022/06/01 19:21:40 by apommier ### ########.fr */
/* Updated: 2022/06/11 20:33:40 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,6 +25,12 @@
# define PI 3.1415926535
typedef struct s_root {
int size;
int height;
int error;
} t_root;
typedef struct ray_info{
double ty;
double tx;
@ -36,12 +42,12 @@ typedef struct ray_info{
} ray;
typedef struct all_wall_texture{
unsigned char *north;
unsigned char *east;
unsigned char *west;
unsigned char *south;
unsigned char *basic;
} sprite;
typedef struct s_color{
@ -60,6 +66,8 @@ typedef struct map_information{
int size;
int x;
int y;
int max;
int error;
} map_info;
typedef struct player_position
@ -85,8 +93,12 @@ typedef struct s_data {
player player;
} t_data;
char *transform_map(char **double_map, t_data *img);
int check_texture_color(char **tab, t_data *img);
int check_map(char **av, t_data *img);
void ft_exit(char *str);
void set_back(t_data *img);
unsigned char *get_texture(int type);
unsigned char *get_texture(char type, char *path, t_data *img);
int get_color(char one, char two, char three);
double reset_angle(double angle);
double deg_to_rad(double angle);

9
map/little.cub Normal file
View File

@ -0,0 +1,9 @@
NO ./sprite/brick_wall.ppm
SO ./sprite/brick_wall.ppm
EA ./sprite/brick_wall.ppm
WE ./sprite/brick_wall.ppm
1111
1001
10E1
1111

View File

@ -4,9 +4,11 @@ EA ./sprite/brick_wall.ppm
WE ./sprite/brick_wall.ppm
111111111
110000001
1000000011111
10E000001
110000001
111111111
11111111
11000001
10000001
10E00001
11000001
11000001
11000001
11111111

View File

@ -121,7 +121,7 @@ void draw_ray3d(t_data *img, ray ray)
int color;
int texture_size = 64;
line_height = img->map.size * 960 / ray.dist;
line_height = /*img->map.size*/64 * 960 / ray.dist;
//if (line_height > 5000)
// line_height = 5000;
//if (line_height > 5000)
@ -148,13 +148,15 @@ void draw_ray3d(t_data *img, ray ray)
my = (int)myy;//gap;
ray.pixel = ((my) * 64 + mx)* 3 + 1;
x = -1;
if (ray.pixel > 12186)
if (ray.pixel > 12185)//here read
color = 0;
else if (ray.pixel != 0)
color = get_color(img->map.texture.north[ray.pixel], img->map.texture.north[ray.pixel + 1], img->map.texture.north[ray.pixel + 2]);//here read
else
color = get_color(img->map.texture.north[ray.pixel], img->map.texture.north[ray.pixel + 1], img->map.texture.north[ray.pixel + 2]);
color = 0;
while (++x < /*img->map.x / 2*/4)
{
if (ray.wall_type)
if (ray.wall_type)//here read
{
//mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 4 + x, y + line_offset , color);
set_pixel(img, color, ray.index * /*(img->map.x / 2)*/4 + x, y + line_offset);
@ -314,6 +316,7 @@ void draw_ray(t_data *img)
int wall_type;
ray ray_info;
wall_type = 0;
if (dist_h != -1 && (dist_h < dist_v || dist_v == -1))
{
//print_ray2(img, cos(deg_to_rad(ray_angle)), -sin(deg_to_rad(ray_angle)), fabs(dist_h));
@ -333,8 +336,12 @@ void draw_ray(t_data *img)
wall_type = 1;
}
else
{
ray_info.mp = 0;
dist_f = 0;
}
ray_info.ty = ray_y;
ray_info.pixel = 0;
ray_info.tx = ray_x;
ray_info.index = nb_ray;
ray_info.wall_type = wall_type;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
/* Updated: 2022/06/11 17:23:14 by apommier ### ########.fr */
/* Updated: 2022/06/13 01:49:43 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -89,6 +89,7 @@ unsigned char *get_texture(char type, char *path, t_data *img)
// printf("c= %d ", ret[count]);
count++;
}
printf("texture size = %d\n", count);
close(fd);
put_texture_in_struct(type, ret, img);
return (ret);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 16:42:55 by apommier #+# #+# */
/* Updated: 2022/06/11 20:32:22 by apommier ### ########.fr */
/* Updated: 2022/06/12 21:54:23 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -108,6 +108,7 @@ int main(int argc, char **argv)
set_map(&img);
if (check_map(argv, &img))
return (0);
printf("size= %d\n", img.map.size);
img.mlx = mlx_init();
if (!img.mlx)
ft_error("Error: mlx_init fail");