full screen

This commit is contained in:
kinou-p 2022-05-19 19:34:30 +02:00
parent 95d5361d7a
commit e731d9d1ba
5 changed files with 123 additions and 147 deletions

View File

@ -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/05/17 22:51:01 by apommier ### ########.fr */ /* Updated: 2022/05/19 14:19:57 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,10 +26,10 @@
# define PI 3.1415926535 # define PI 3.1415926535
typedef struct ray_info{ typedef struct ray_info{
float ty; double ty;
float tx; double tx;
float mp; double mp;
float dist; double dist;
int index; int index;
int wall_type; int wall_type;
int pixel; int pixel;
@ -57,16 +57,18 @@ typedef struct map_information{
typedef struct player_position typedef struct player_position
{ {
float x; double x;
float y; double y;
float angle; double angle;
float vx; double vx;
float vy; double vy;
} player; } player;
typedef struct s_data { typedef struct s_data {
void *mlx; void *mlx;
void *mlx_win; void *mlx_win;
void *mlx_test;
void *mlx_win_test;
char **double_map; char **double_map;
map_info map; map_info map;
player player; player player;
@ -74,8 +76,8 @@ typedef struct s_data {
int *get_texture(int type); int *get_texture(int type);
int get_color(char one, char two, char three); int get_color(char one, char two, char three);
int reset_angle(int angle); double reset_angle(double angle);
float deg_to_rad(int angle); double deg_to_rad(double angle);
void draw_ray(t_data *img); void draw_ray(t_data *img);
void print_ray(t_data *img); void print_ray(t_data *img);
int key_press(int code, t_data *img); int key_press(int code, t_data *img);

View File

@ -6,26 +6,27 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/04 18:08:14 by apommier #+# #+# */ /* Created: 2022/05/04 18:08:14 by apommier #+# #+# */
/* Updated: 2022/05/18 19:13:39 by apommier ### ########.fr */ /* Updated: 2022/05/19 19:04:22 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../includes/Cub3D.h" #include "../includes/Cub3D.h"
void print_ray2(t_data *img, float vx, float vy, float dist) void print_ray2(t_data *img, double vx, double vy, double dist)
{ {
int i = -1; int i = -1;
int red = 0; int red = 0;
//printf("in print ray2\n");
red = red << 8; red = red << 8;
red +=255; red +=255;
red = red << 8; red = red << 8;
red = red << 8; red = red << 8;
while (++i < dist) while (++i < dist)
{ {
mlx_pixel_put(img->mlx, img->mlx_win, (img->player.x + (vx) * i) , (img->player.y + (vy) * i) , red); mlx_pixel_put(img->mlx_test, img->mlx_win_test, (img->player.x + (vx) * i) , (img->player.y + (vy) * i) , red);
mlx_pixel_put(img->mlx, img->mlx_win, (img->player.x + (vx) * i) + 1, (img->player.y + (vy) * i) , red); mlx_pixel_put(img->mlx_test, img->mlx_win_test, (img->player.x + (vx) * i) + 1, (img->player.y + (vy) * i) , red);
mlx_pixel_put(img->mlx, img->mlx_win, (img->player.x + (vx) * i) , (img->player.y + (vy) * i) + 1, red); mlx_pixel_put(img->mlx_test, img->mlx_win_test, (img->player.x + (vx) * i) , (img->player.y + (vy) * i) + 1, red);
} }
} }
@ -66,13 +67,13 @@ int get_dark_red()
void draw_ray3d(t_data *img, ray ray) void draw_ray3d(t_data *img, ray ray)
{ {
float line_height; double line_height;
float line_offset; double line_offset;
int x = 0; int x = 0;
float y = 0; double y = 0;
int mx = 0; int mx = 0;
int my = 0; int my = 0;
int pixel; //int pixel;
int color; int color;
int texture_size = 64; int texture_size = 64;
//char *wall; //char *wall;
@ -89,8 +90,8 @@ void draw_ray3d(t_data *img, ray ray)
}*/ }*/
// float ty=ty_off*ty_step;//+hmt*32; // double ty=ty_off*ty_step;//+hmt*32;
// float tx; // double tx;
// if(shade==1) // if(shade==1)
// { // {
// tx=(int)(rx/2.0)%32; // tx=(int)(rx/2.0)%32;
@ -106,17 +107,17 @@ void draw_ray3d(t_data *img, ray ray)
//pixel = ((int)ty * 32 + (int)tx) * 3 + (hmt * 32 * 32 * 3); //pixel = ((int)ty * 32 + (int)tx) * 3 + (hmt * 32 * 32 * 3);
int copy = ray.ty; //int copy = ray.ty;
//i = 0; //i = 0;
line_height = img->map.size * 320 / ray.dist; line_height = img->map.size * 960 / ray.dist;
if (line_height > 320) //if (line_height > 512)
line_height = 320; // line_height = 512;
line_offset = 160 - line_height / 2; line_offset = 256 - line_height / 2;
float gap = 1; double gap = 1;
float old_y = 0; //double old_y = 0;
float myy = 0; double myy = 0;
printf("mp= %f modulo texture_size= %d\n", ray.mp, ((int)ray.mp / 4) % texture_size); //printf("mp= %f modulo texture_size= %d\n", ray.mp, ((int)ray.mp / 4) % texture_size);
//while (x < 8) //while (x < 8)
//{ //{
@ -125,7 +126,7 @@ void draw_ray3d(t_data *img, ray ray)
myy = 0; myy = 0;
//double step = 1.0 * texHeight / lineHeight; //double step = 1.0 * texHeight / lineHeight;
gap = (texture_size / line_height); gap = (texture_size / line_height);
old_y = 0; //old_y = 0;
//ray.ty = ; //ray.ty = ;
mx = ((int)ray.mp) % texture_size; mx = ((int)ray.mp) % texture_size;
//int texX = int(wallX * double(texWidth)); //int texX = int(wallX * double(texWidth));
@ -148,18 +149,18 @@ void draw_ray3d(t_data *img, ray ray)
//ray.pixel = ((((int)ray.mp) % 16) * 16 + gap /*+ x*/) * 3 + 1 ; //ray.pixel = ((((int)ray.mp) % 16) * 16 + gap /*+ x*/) * 3 + 1 ;
ray.pixel = ((my) * texture_size + mx)* 3 - 1; ray.pixel = ((my) * texture_size + mx)* 3 - 1;
x = -1; x = -1;
//printf("my= %d mx= %d pixel= %d\n", my, mx, ray.pixel); //printf("x= %d y= %f pixel= %d\n", ray.index /** 2 + 530 + x*/, y, ray.pixel);
color = get_color(img->map.texture.north[ray.pixel], img->map.texture.north[ray.pixel + 1], img->map.texture.north[ray.pixel + 2]); color = get_color(img->map.texture.north[ray.pixel], img->map.texture.north[ray.pixel + 1], img->map.texture.north[ray.pixel + 2]);
while (++x < 8) while (++x < 4)
{ {
if (ray.wall_type) if (ray.wall_type)
mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 8 + 530 + x, y + line_offset , color); mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 4 + x, y + line_offset , color);
else else
mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 8 + 530 + x, y + line_offset , (color >> 1) & 8355711); mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 4 + x, y + line_offset , (color >> 1) & 8355711);
} }
//printf("pixel=%d ", ray.pixel); //printf("pixel=%d ", ray.pixel);
//if (ray.wall_type) //if (ray.wall_type)
int l = 0; //int l = 0;
//while (l < 8) //while (l < 8)
//{ //{
//x = -1; //x = -1;
@ -173,32 +174,32 @@ void draw_ray3d(t_data *img, ray ray)
} }
x++; x++;
//} //}
printf("\n"); //printf("\n");
//ray.tx++; //ray.tx++;
} }
void draw_ray(t_data *img) void draw_ray(t_data *img)
{ {
float ray_angle = 0; //ray angle double ray_angle = 0; //ray angle
float ray_y = 0; //where ray touch x double ray_y = 0; //where ray touch x
float ray_x = 0; //where ray touch y double ray_x = 0; //where ray touch y
float next_x = 0; double next_x = 0;
float next_y = 0; double next_y = 0;
float dist_v; double dist_v;
float dist_h; double dist_h;
float dist_f; double dist_f;
float vx = 0; double vx = 0;
float vy = 0; double vy = 0;
int count = 0; int count = 0;
float aTan = 0; double aTan = 0;
int nb_ray = -1; int nb_ray = -1;
int my = 0; int my = 0;
int mx = 0; int mx = 0;
int mp = 0; int mp = 0;
(void)dist_f; (void)dist_f;
printf("---NEW RAY----\n\n"); //printf("---NEW RAY----\n\n");
//printf("\nENTER DRAW RAY\n"); //printf("\nENTER DRAW RAY\n");
//while (++k < ft_strlen(img->map.simple_map)) //while (++k < ft_strlen(img->map.simple_map))
// printf("%d--- %c\n", k, img->map.simple_map[k]); // printf("%d--- %c\n", k, img->map.simple_map[k]);
@ -206,7 +207,7 @@ void draw_ray(t_data *img)
count = 0; count = 0;
ray_angle = reset_angle(img->player.angle + 30); ray_angle = reset_angle(img->player.angle + 30);
//ray_angle = reset_angle(img->player.angle); //ray_angle = reset_angle(img->player.angle);
while (++nb_ray < 60) while (++nb_ray < 240)
{ {
//if (nb_ray) //if (nb_ray)
@ -218,6 +219,12 @@ void draw_ray(t_data *img)
//printf("player_angle= %f ray_angle= %f\n", img->player.angle, ray_angle); //printf("player_angle= %f ray_angle= %f\n", img->player.angle, ray_angle);
//----------start vertical ray---------- //----------start vertical ray----------
aTan = tan(deg_to_rad(ray_angle)); aTan = tan(deg_to_rad(ray_angle));
//if (aTan != tan(deg_to_rad(ray_angle - 0.25)))
//double test = 0.1111111111111;
//printf("test= %f\n", test);
//printf("ray_angle = %f\n", ray_angle);
//printf("in atan= %f\n", deg_to_rad(ray_angle));
//printf("atan= %f\n", aTan);
if (cos(deg_to_rad(ray_angle)) > 0.001)//looking left if (cos(deg_to_rad(ray_angle)) > 0.001)//looking left
{ {
ray_x = (((int)img->player.x>>6)<<6) + 64; ray_x = (((int)img->player.x>>6)<<6) + 64;
@ -322,29 +329,29 @@ void draw_ray(t_data *img)
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));
dist_f = dist_h; dist_f = dist_h;
printf("rx= %f ry= %f\n", ray_x, ray_y); //printf("rx= %f ry= %f\n", ray_x, ray_y);
ray_info.mp = ray_x; ray_info.mp = ray_x;
wall_type = 0; wall_type = 0;
} }
else if (dist_v != -1) else if (dist_v != -1)
{ {
dist_f = dist_v; dist_f = dist_v;
printf("vx= %f vy= %f\n", vx, vy); //printf("vx= %f vy= %f\n", vx, vy);
ray_x = vx; ray_x = vx;
ray_y = vy; ray_y = vy;
ray_info.mp = vy; ray_info.mp = vy;
print_ray2(img, cos(deg_to_rad(ray_angle)), -sin(deg_to_rad(ray_angle)), fabs(dist_v)); //print_ray2(img, cos(deg_to_rad(ray_angle)), -sin(deg_to_rad(ray_angle)), fabs(dist_v));
wall_type = 1; wall_type = 1;
} }
else else
dist_f = 0; dist_f = 0;
float tx; double tx;
float ty_off = 0; //double ty_off = 0;
float ty_step = 32.0/dist_f; //double ty_step = 32.0/dist_f;
//float ty = ; //double ty = ;
/*if(dist_f > 640) /*if(dist_f > 640)
{ {
ty_off = (dist_f - 320) / 2.0; ty_off = (dist_f - 320) / 2.0;
@ -356,17 +363,19 @@ void draw_ray(t_data *img)
//if(ray_angle > 180) //if(ray_angle > 180)
// tx = 15 - tx; // tx = 15 - tx;
//ray_info.pixel = ((int)ty * 16 + (int)tx) * 3 + 3; //ray_info.pixel = ((int)ty * 16 + (int)tx) * 3 + 3;
printf("nb_ray= %d\n", nb_ray); //printf("nb_ray= %d\n", nb_ray);
ray_info.ty = ray_y; ray_info.ty = ray_y;
ray_info.tx = ray_x; ray_info.tx = ray_x;
//ray_info.mp = ray_info.mp / 2;
ray_info.index = nb_ray; ray_info.index = nb_ray;
ray_info.wall_type = wall_type; ray_info.wall_type = wall_type;
int ca = reset_angle(img->player.angle - ray_angle); //fisheye int ca = reset_angle(img->player.angle - ray_angle); //fisheye
dist_f = dist_f * cos(deg_to_rad(ca)); dist_f = dist_f * cos(deg_to_rad(ca));
ray_info.dist = dist_f; //fisheye ray_info.dist = dist_f; //fisheye
draw_ray3d(img, ray_info); draw_ray3d(img, ray_info);
//ray_angle -= 0.5;
ray_angle = reset_angle(ray_angle - 1); //printf("entre ray_angle = %f\n", ray_angle);
ray_angle = reset_angle(ray_angle - 0.25);
//printf("after ray_angle = %f\n", ray_angle);
} }
} }

View File

@ -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/05/17 23:49:38 by apommier ### ########.fr */ /* Updated: 2022/05/19 19:11:07 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,12 +16,10 @@ int *get_texture(int type)
{ {
int fd; int fd;
int *ret; int *ret;
//int start = 1;
int count; int count;
int len;
char *swap = 0; char *swap = 0;
//line = 0; (void)type;
count = 0; count = 0;
fd = open("./sprite/brick_wall.ppm", O_RDONLY); fd = open("./sprite/brick_wall.ppm", O_RDONLY);
while (swap || !count) while (swap || !count)
@ -33,54 +31,20 @@ int *get_texture(int type)
} }
close(fd); close(fd);
ret = ft_calloc(sizeof(int), count + 1); ret = ft_calloc(sizeof(int), count + 1);
//char **ret2 = ft_calloc(sizeof(ret), count + 1);
fd = open("./sprite/brick_wall.ppm", O_RDONLY); fd = open("./sprite/brick_wall.ppm", O_RDONLY);
if (!ret) if (!ret)
return (0); return (0);
ret[count] = -1; ret[count] = -1;
len = count;
count = 0; count = 0;
while (swap || !count) while (swap || !count)
{ {
if (swap) if (swap)
free(swap); free(swap);
swap = get_next_line(fd); swap = get_next_line(fd);
//printf("swap= %s\n", swap);
ret[count] = (int)ft_atoi(swap); ret[count] = (int)ft_atoi(swap);
count++; count++;
} }
int k = 0;
/*while (len)
{
printf("nbr= %d", ret[len--]);
}*/
printf("nrb3= %d\n", ret[1]);
//print_double_fd(ret2, 1);
//free_double(ret2);
close(fd); close(fd);
/*int v = 0;
int b = 0;
int pixel = 0;
//printf("pixel=%d ", ray.pixel);
while (v < 16)
{
while (b < 16)
{
pixel = (v * 3) + b;
int color = get_color(ret[pixel], ret[pixel + 1], ret[pixel + 2]);
mlx_pixel_put(img->mlx, img->mlx_win, v, b, color);
b++;
}
v++;
}*/
return (ret); return (ret);
} }

View File

@ -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/05/17 23:52:27 by apommier ### ########.fr */ /* Updated: 2022/05/19 19:09:32 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,9 +17,9 @@ void print_ray(t_data *img)
int i = -1; int i = -1;
while (++i < 15) while (++i < 15)
{ {
mlx_pixel_put(img->mlx, img->mlx_win, (img->player.x + (img->player.vx) * i), (img->player.y + (img->player.vy) * i) , 255 << 8); mlx_pixel_put(img->mlx_test, img->mlx_win_test, (img->player.x + (img->player.vx) * i), (img->player.y + (img->player.vy) * i) , 255 << 8);
mlx_pixel_put(img->mlx, img->mlx_win, (img->player.x + (img->player.vx) * i) + 1, (img->player.y + (img->player.vy) * i) , 255 << 8); mlx_pixel_put(img->mlx_test, img->mlx_win_test, (img->player.x + (img->player.vx) * i) + 1, (img->player.y + (img->player.vy) * i) , 255 << 8);
mlx_pixel_put(img->mlx, img->mlx_win, (img->player.x + (img->player.vx) * i), (img->player.y + (img->player.vy) * i) + 1, 255 << 8); mlx_pixel_put(img->mlx_test, img->mlx_win_test, (img->player.x + (img->player.vx) * i), (img->player.y + (img->player.vy) * i) + 1, 255 << 8);
} }
} }
@ -117,15 +117,15 @@ void print_case(char type, t_data *img, int y, int x)
//printf("type= %c\n", type); //printf("type= %c\n", type);
if (type == '1') if (type == '1')
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/wall.xpm", buffer = mlx_xpm_file_to_image(img->mlx_test, "./sprite/wall.xpm",
&img_width, &img_height); &img_width, &img_height);
else if (type == '0') else if (type == '0')
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/back.xpm", buffer = mlx_xpm_file_to_image(img->mlx_test, "./sprite/back.xpm",
&img_width, &img_height); &img_width, &img_height);
if (!buffer) if (!buffer)
ft_error("no buffer"); ft_error("no buffer");
mlx_put_image_to_window(img->mlx, img->mlx_win, buffer, x, y); mlx_put_image_to_window(img->mlx_test, img->mlx_win_test, buffer, x, y);
mlx_destroy_image(img->mlx, buffer); mlx_destroy_image(img->mlx_test, buffer);
} }
void print_map(map_info map, t_data *img) void print_map(map_info map, t_data *img)
@ -159,19 +159,19 @@ void print_map(map_info map, t_data *img)
{ {
print_case(map[j][i], img, (j * 64), (i * 64)); print_case(map[j][i], img, (j * 64), (i * 64));
i++; i++;
x++; x++;
} }
j++; j++;
y++; y++;
}*/ }*/
} }
void print_line(t_data *img, float x, float y) void print_line(t_data *img, double x, double y)
{ {
float i = -1; double i = -1;
int j = -1; int j = -1;
while (++i < x && ++j < y) while (++i < x && ++j < y)
mlx_pixel_put(img->mlx, img->mlx_win, (img->player.x + (img->player.vx / 5) * i) + 2, (img->player.y + (img->player.vy / 5) * i) + 2, 65); mlx_pixel_put(img->mlx_test, img->mlx_win_test, (img->player.x + (img->player.vx / 5) * i) + 2, (img->player.y + (img->player.vy / 5) * i) + 2, 65);
} }
void print_player(player player, t_data *img) void print_player(player player, t_data *img)
@ -180,10 +180,10 @@ void print_player(player player, t_data *img)
int img_width; int img_width;
int img_height; int img_height;
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/player.xpm", buffer = mlx_xpm_file_to_image(img->mlx_test, "./sprite/player.xpm",
&img_width, &img_height); &img_width, &img_height);
mlx_put_image_to_window(img->mlx, img->mlx_win, buffer, player.x - 3.5 , player.y -3.5); mlx_put_image_to_window(img->mlx_test, img->mlx_win_test, buffer, player.x - 3.5 , player.y -3.5);
mlx_destroy_image(img->mlx, buffer); mlx_destroy_image(img->mlx_test, buffer);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
@ -195,11 +195,18 @@ int main(int argc, char **argv)
if (argc != 2) if (argc != 2)
ft_error("Error: bad number of arguments, only need a map"); ft_error("Error: bad number of arguments, only need a map");
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");
img.map = set_map(argv); img.map = set_map(argv);
img.mlx_win = mlx_new_window(img.mlx, 1024, 512, "Cub3D"); img.mlx_win = mlx_new_window(img.mlx, 960, 512, "Cub3D");
//img.mlx_test = mlx_init();
//img.mlx_win_test = mlx_new_window(img.mlx, 512, 512, "Cub3D_test");
//img->player.x=150; img->player.y=400; pa=90; //img->player.x=150; img->player.y=400; pa=90;
//pdx=cos(deg_to_rad(pa)); pdy=-sin(deg_to_rad(pa)); //pdx=cos(deg_to_rad(pa)); pdy=-sin(deg_to_rad(pa));
img.map.texture = texture; img.map.texture = texture;
@ -208,14 +215,8 @@ int main(int argc, char **argv)
img.player.angle = 90; img.player.angle = 90;
img.player.vx = cos(deg_to_rad(img.player.angle)); img.player.vx = cos(deg_to_rad(img.player.angle));
img.player.vy = sin(deg_to_rad(img.player.angle)); img.player.vy = sin(deg_to_rad(img.player.angle));
print_map(img.map, &img); //print_map(img.map, &img);
print_player(img.player, &img); //print_player(img.player, &img);
//print_ray(&img); //print_ray(&img);
mlx_hook(img.mlx_win, 2, 1L << 0, &key_press, &img); mlx_hook(img.mlx_win, 2, 1L << 0, &key_press, &img);
mlx_hook(img.mlx_win, 17, 0L, &quit_game, &img); mlx_hook(img.mlx_win, 17, 0L, &quit_game, &img);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */ /* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
/* Updated: 2022/05/18 00:08:25 by apommier ### ########.fr */ /* Updated: 2022/05/19 15:32:21 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,17 +23,17 @@ int quit_game(t_data *img)
exit(0); exit(0);
} }
float deg_to_rad(int angle) double deg_to_rad(double angle)
{ {
return (angle * M_PI / 180.0); return (angle * 3.14159265358979323846 / 180.0);
} }
int reset_angle(int angle) double reset_angle(double angle)
{ {
if (angle > 359) if (angle > 359)
angle -= 360; angle -= 360.0;
if (angle < 0) if (angle < 0)
angle += 360; angle += 360.0;
return (angle); return (angle);
} }
@ -49,8 +49,8 @@ void ft_error(char *error_msg)
int is_good(t_data *img, int type) int is_good(t_data *img, int type)
{ {
//printf("touche= %c\n", type); //printf("touche= %c\n", type);
//printf("vx= %f vy= %f\n", img->player.vx, img->player.vy); //printf("vx= %d vy= %d\n", img->player.vx, img->player.vy);
//printf("player: x= %f y= %f\n", img->player.x, img->player.y); //printf("player: x= %d y= %d\n", img->player.x, img->player.y);
// //
/*if(key=='a'){ pa+=5; pa=FixAng(pa); pdx=cos(deg_to_rad(pa)); pdy=-sin(deg_to_rad(pa));} /*if(key=='a'){ pa+=5; pa=FixAng(pa); pdx=cos(deg_to_rad(pa)); pdy=-sin(deg_to_rad(pa));}
@ -94,19 +94,19 @@ int is_good(t_data *img, int type)
} }
else else
return (0); return (0);
//printf("after player: x= %f y= %f\n", img->player.x, img->player.y); //printf("after player: x= %d y= %d\n", img->player.x, img->player.y);
return (1); return (1);
} }
void print_back(t_data *img) void print_back(t_data *img)
{ {
int x = 530; int x = 0;
int y = 160; int y = 0;
while (x < 1024) while (x < 1024)
{ {
y = 0; y = 0;
while (y < 320) while (y < 512)
{ {
mlx_pixel_put(img->mlx, img->mlx_win, x , y, get_color(128, 128, 128)); mlx_pixel_put(img->mlx, img->mlx_win, x , y, get_color(128, 128, 128));
//mlx_pixel_put(img->mlx, img->mlx_win, x , y - 160, get_color(0, 255, 255)); //mlx_pixel_put(img->mlx, img->mlx_win, x , y - 160, get_color(0, 255, 255));
@ -126,22 +126,22 @@ int key_press(int code, t_data *img)
{ {
//printf("code = %d\n", code); //printf("code = %d\n", code);
//mlx_clear_window(img->mlx, img->mlx_win); //mlx_clear_window(img->mlx, img->mlx_win);
print_map(img->map, img); //print_map(img->map, img);
print_player(img->player, img); //print_player(img->player, img);
print_back(img); print_back(img);
draw_ray(img); draw_ray(img);
print_ray(img); //print_ray(img);
} }
} }
int y = 0; // int y = 0;
int x = 0; // int x = 0;
int pixel = 0; // int pixel = 0;
int color; // int color;
//printf("pixel=%d ", ray.pixel); //printf("pixel=%d ", ray.pixel);
while (x < 16) /*while (x < 16)
{ {
y = 0; y = 0;
while (y < 16) while (y < 16)
@ -153,7 +153,7 @@ int key_press(int code, t_data *img)
y++; y++;
} }
x++; x++;
} }*/