fix 1 000 000 problem
This commit is contained in:
parent
edba4a3e76
commit
99c3b6376b
4
Makefile
4
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/02/13 16:27:49 by apommier #+# #+# #
|
# 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 = srcs/main.c\
|
||||||
srcs/get_texture_array.c\
|
srcs/get_texture_array.c\
|
||||||
srcs/cast_ray.c\
|
srcs/cast_ray.c\
|
||||||
|
srcs/parsing/parse_map.c\
|
||||||
|
srcs/parsing/check_color_texture.c\
|
||||||
srcs/utils.c
|
srcs/utils.c
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
|
/* 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
|
# define PI 3.1415926535
|
||||||
|
|
||||||
|
typedef struct s_root {
|
||||||
|
int size;
|
||||||
|
int height;
|
||||||
|
int error;
|
||||||
|
} t_root;
|
||||||
|
|
||||||
typedef struct ray_info{
|
typedef struct ray_info{
|
||||||
double ty;
|
double ty;
|
||||||
double tx;
|
double tx;
|
||||||
@ -36,12 +42,12 @@ typedef struct ray_info{
|
|||||||
|
|
||||||
} ray;
|
} ray;
|
||||||
|
|
||||||
|
|
||||||
typedef struct all_wall_texture{
|
typedef struct all_wall_texture{
|
||||||
unsigned char *north;
|
unsigned char *north;
|
||||||
unsigned char *east;
|
unsigned char *east;
|
||||||
unsigned char *west;
|
unsigned char *west;
|
||||||
unsigned char *south;
|
unsigned char *south;
|
||||||
|
unsigned char *basic;
|
||||||
} sprite;
|
} sprite;
|
||||||
|
|
||||||
typedef struct s_color{
|
typedef struct s_color{
|
||||||
@ -60,6 +66,8 @@ typedef struct map_information{
|
|||||||
int size;
|
int size;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
int max;
|
||||||
|
int error;
|
||||||
} map_info;
|
} map_info;
|
||||||
|
|
||||||
typedef struct player_position
|
typedef struct player_position
|
||||||
@ -85,8 +93,12 @@ typedef struct s_data {
|
|||||||
player player;
|
player player;
|
||||||
} t_data;
|
} 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);
|
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);
|
int get_color(char one, char two, char three);
|
||||||
double reset_angle(double angle);
|
double reset_angle(double angle);
|
||||||
double deg_to_rad(double angle);
|
double deg_to_rad(double angle);
|
||||||
|
|||||||
9
map/little.cub
Normal file
9
map/little.cub
Normal 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
|
||||||
14
map/map8.cub
14
map/map8.cub
@ -4,9 +4,11 @@ EA ./sprite/brick_wall.ppm
|
|||||||
WE ./sprite/brick_wall.ppm
|
WE ./sprite/brick_wall.ppm
|
||||||
|
|
||||||
|
|
||||||
111111111
|
11111111
|
||||||
110000001
|
11000001
|
||||||
1000000011111
|
10000001
|
||||||
10E000001
|
10E00001
|
||||||
110000001
|
11000001
|
||||||
111111111
|
11000001
|
||||||
|
11000001
|
||||||
|
11111111
|
||||||
@ -121,7 +121,7 @@ void draw_ray3d(t_data *img, ray ray)
|
|||||||
int color;
|
int color;
|
||||||
int texture_size = 64;
|
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)
|
//if (line_height > 5000)
|
||||||
// line_height = 5000;
|
// line_height = 5000;
|
||||||
//if (line_height > 5000)
|
//if (line_height > 5000)
|
||||||
@ -148,13 +148,15 @@ void draw_ray3d(t_data *img, ray ray)
|
|||||||
my = (int)myy;//gap;
|
my = (int)myy;//gap;
|
||||||
ray.pixel = ((my) * 64 + mx)* 3 + 1;
|
ray.pixel = ((my) * 64 + mx)* 3 + 1;
|
||||||
x = -1;
|
x = -1;
|
||||||
if (ray.pixel > 12186)
|
if (ray.pixel > 12185)//here read
|
||||||
color = 0;
|
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
|
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)
|
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);
|
//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);
|
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;
|
int wall_type;
|
||||||
ray ray_info;
|
ray ray_info;
|
||||||
|
|
||||||
|
wall_type = 0;
|
||||||
if (dist_h != -1 && (dist_h < dist_v || dist_v == -1))
|
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));
|
//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;
|
wall_type = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
ray_info.mp = 0;
|
||||||
dist_f = 0;
|
dist_f = 0;
|
||||||
|
}
|
||||||
ray_info.ty = ray_y;
|
ray_info.ty = ray_y;
|
||||||
|
ray_info.pixel = 0;
|
||||||
ray_info.tx = ray_x;
|
ray_info.tx = ray_x;
|
||||||
ray_info.index = nb_ray;
|
ray_info.index = nb_ray;
|
||||||
ray_info.wall_type = wall_type;
|
ray_info.wall_type = wall_type;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
|
/* 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]);
|
// printf("c= %d ", ret[count]);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
printf("texture size = %d\n", count);
|
||||||
close(fd);
|
close(fd);
|
||||||
put_texture_in_struct(type, ret, img);
|
put_texture_in_struct(type, ret, img);
|
||||||
return (ret);
|
return (ret);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 16:42:55 by apommier #+# #+# */
|
/* 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);
|
set_map(&img);
|
||||||
if (check_map(argv, &img))
|
if (check_map(argv, &img))
|
||||||
return (0);
|
return (0);
|
||||||
|
printf("size= %d\n", img.map.size);
|
||||||
img.mlx = mlx_init();
|
img.mlx = mlx_init();
|
||||||
if (!img.mlx)
|
if (!img.mlx)
|
||||||
ft_error("Error: mlx_init fail");
|
ft_error("Error: mlx_init fail");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user