comment
This commit is contained in:
parent
e58fd78ef7
commit
c88649051a
@ -1,6 +1,6 @@
|
||||
NO ./sprite/magma.ppm
|
||||
SO ./sprite/magma.ppm
|
||||
EA ./sprite/obsidian.ppm
|
||||
SO ./sprite/stone_bricks.ppm
|
||||
EA ./sprite/glowstone.ppm
|
||||
WE ./sprite/obsidian.ppm
|
||||
|
||||
|
||||
|
||||
@ -17,7 +17,6 @@ void print_ray2(t_data *img, double vx, double vy, double dist)
|
||||
int i = -1;
|
||||
int red = 0;
|
||||
|
||||
//printf("in print ray2\n");
|
||||
red = red << 8;
|
||||
red +=255;
|
||||
red = red << 8;
|
||||
@ -72,28 +71,10 @@ int get_dark_red()
|
||||
void set_pixel(t_data *img, int color, int x, int y)
|
||||
{
|
||||
int pixel;
|
||||
//int R;
|
||||
//int G;
|
||||
//int B;
|
||||
|
||||
//printf("color in set = %d\n", color);
|
||||
|
||||
/*color = color >> 24;
|
||||
printf("color= %d\n", color);
|
||||
//color += R;
|
||||
color = color >> 16;
|
||||
printf("color= %d\n", color);
|
||||
//color += G;
|
||||
color = color >> 8;
|
||||
printf("color= %d\n", color);
|
||||
//color += B;*/
|
||||
|
||||
|
||||
//printf("1= %d 2= %d 3= %d 4= %d\n", (color >> 24) & 0xFF, (color >> 16) & 0xFF, (color >> 8) & 0xFF, (color) & 0xFF);
|
||||
if (y < 0 || y > 520 || x < 0 || x > 960)
|
||||
return ;
|
||||
pixel = (y * img->size_line) + (x * 4);
|
||||
//printf("x= %d y= %d pixel value= %d tabsize = %d\n", x, y, pixel, 512 * 960 * 4);
|
||||
if (img->endian == 1) // Most significant (Alpha) byte first
|
||||
{
|
||||
img->buffer[pixel + 0] = 0;
|
||||
@ -122,11 +103,6 @@ void draw_ray3d(t_data *img, ray ray)
|
||||
int texture_size = 64;
|
||||
|
||||
line_height = /*img->map.size*/64 * 960 / ray.dist;
|
||||
//if (line_height > 5000)
|
||||
// line_height = 5000;
|
||||
//if (line_height > 5000)
|
||||
// line_height = 5000;
|
||||
//printf("ray dist= %f line height= %f\n", ray.dist, line_height);
|
||||
line_offset = 256 - ((int)line_height) / 2;
|
||||
double gap = 1;
|
||||
double myy = 0;
|
||||
@ -142,8 +118,6 @@ void draw_ray3d(t_data *img, ray ray)
|
||||
}
|
||||
while (y < line_height - 8 && y < 512)
|
||||
{
|
||||
//if (line_height > 512)
|
||||
// int diff = line_height - 512 \ 2;
|
||||
myy += gap;
|
||||
my = (int)myy;//gap;
|
||||
ray.pixel = ((my) * 64 + mx)* 3 + 1;
|
||||
@ -167,24 +141,7 @@ void draw_ray3d(t_data *img, ray ray)
|
||||
color = 0;
|
||||
while (++x < /*img->map.x / 2*/4)
|
||||
{
|
||||
//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);
|
||||
//set_pixel(img, color, ray.index * (img->map.x / 2) + x, y + line_offset);
|
||||
//}
|
||||
// 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);
|
||||
// //set_pixel(img, color, ray.index * (img->map.x / 2) + x, y + line_offset);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 4 + x, y + line_offset , (color >> 1) & 8355711);
|
||||
// set_pixel(img, (color >> 1) & 8355711, ray.index * /*(img->map.x / 2)*/4 + x, y + line_offset);
|
||||
// //set_pixel(img, (color >> 1) & 8355711, ray.index * (img->map.x / 2) + x, y + line_offset);
|
||||
// }
|
||||
}
|
||||
y++;
|
||||
}
|
||||
@ -253,7 +210,7 @@ void draw_ray(t_data *img)
|
||||
ray_y = (img->player.x - ray_x) * aTan + img->player.y;
|
||||
next_x = 64;
|
||||
next_y = -next_x * aTan;
|
||||
vertical_type = 'W';
|
||||
vertical_type = 'E';
|
||||
}
|
||||
else if (cos(deg_to_rad(ray_angle)) < -0.001)//looking right
|
||||
{
|
||||
@ -261,7 +218,7 @@ void draw_ray(t_data *img)
|
||||
ray_y = (img->player.x - ray_x) * aTan + img->player.y;
|
||||
next_x = -64;
|
||||
next_y = -next_x * aTan;
|
||||
vertical_type = 'E';
|
||||
vertical_type = 'W';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/13 20:41:01 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/14 16:26:14 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -65,12 +65,10 @@ unsigned char *get_texture(char type, char *path, t_data *img)
|
||||
swap = get_next_line(fd);
|
||||
}
|
||||
close(fd);
|
||||
//printf("count= %d\n", count);
|
||||
ret = ft_calloc(sizeof(char), count);
|
||||
fd = open(path, O_RDONLY);
|
||||
if (!ret)
|
||||
return (0);
|
||||
//ret[count] = -1;
|
||||
count = 0;
|
||||
while (swap || !count)
|
||||
{
|
||||
@ -82,14 +80,10 @@ unsigned char *get_texture(char type, char *path, t_data *img)
|
||||
free(swap);
|
||||
swap = get_next_line(fd);
|
||||
}
|
||||
//printf("c= %d ", (unsigned char)ft_atoi(swap));
|
||||
if (swap)
|
||||
ret[count] = (unsigned char)ft_atoi(swap);
|
||||
//if (swap)
|
||||
// printf("c= %d ", ret[count]);
|
||||
count++;
|
||||
}
|
||||
//printf("texture size = %d\n", count);
|
||||
close(fd);
|
||||
put_texture_in_struct(type, ret, img);
|
||||
return (ret);
|
||||
|
||||
95
srcs/main.c
95
srcs/main.c
@ -6,23 +6,12 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/02/13 16:42:55 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/14 16:01:15 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/14 16:25:41 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/Cub3D.h"
|
||||
|
||||
/*void print_ray(t_data *img)
|
||||
{
|
||||
int i = -1;
|
||||
while (++i < 15)
|
||||
{
|
||||
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_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_test, img->mlx_win_test, (img->player.x + (img->player.vx) * i), (img->player.y + (img->player.vy) * i) + 1, 255 << 8);
|
||||
}
|
||||
}*/
|
||||
|
||||
void set_map(t_data *img)
|
||||
{
|
||||
img->map.texture.north = 0;
|
||||
@ -31,66 +20,6 @@ void set_map(t_data *img)
|
||||
img->map.texture.west = 0;
|
||||
}
|
||||
|
||||
/*void print_case(char type, t_data *img, int y, int x)
|
||||
{
|
||||
int *buffer = 0;
|
||||
int img_width;
|
||||
int img_height;
|
||||
|
||||
//printf("type= %c\n", type);
|
||||
if (type == '1')
|
||||
buffer = mlx_xpm_file_to_image(img->mlx_test, "./sprite/wall.xpm",
|
||||
&img_width, &img_height);
|
||||
else if (type == '0')
|
||||
buffer = mlx_xpm_file_to_image(img->mlx_test, "./sprite/back.xpm",
|
||||
&img_width, &img_height);
|
||||
if (!buffer)
|
||||
ft_error("no buffer");
|
||||
mlx_put_image_to_window(img->mlx_test, img->mlx_win_test, buffer, x, y);
|
||||
mlx_destroy_image(img->mlx_test, buffer);
|
||||
}
|
||||
|
||||
void print_map(map_info map, t_data *img)
|
||||
{
|
||||
int i = 0;
|
||||
int j;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
while (i < map.size)
|
||||
{
|
||||
j = -1;
|
||||
x = 0;
|
||||
while (++j < 8)
|
||||
{
|
||||
print_case(map.[i], img, (y * 64), (x * 64));
|
||||
i++;
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
void print_line(t_data *img, double x, double y)
|
||||
{
|
||||
double i = -1;
|
||||
int j = -1;
|
||||
while (++i < x && ++j < y)
|
||||
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)
|
||||
{
|
||||
int *buffer = 0;
|
||||
int img_width;
|
||||
int img_height;
|
||||
|
||||
buffer = mlx_xpm_file_to_image(img->mlx_test, "./sprite/player.xpm",
|
||||
&img_width, &img_height);
|
||||
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_test, buffer);
|
||||
}*/
|
||||
|
||||
int key_pressed(int type, t_data *img)
|
||||
{
|
||||
if (type == 65307)
|
||||
@ -141,15 +70,7 @@ int loop(t_data *img)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_data img;
|
||||
//sprite texture;
|
||||
|
||||
//texture.north = get_texture(1, 0, img);
|
||||
//int index= -1;
|
||||
/*while (texture.north[++index] != -1)
|
||||
{
|
||||
printf("element= %d\n", texture.north[index]);
|
||||
}
|
||||
printf("end element= %d\n", texture.north[index]);*/
|
||||
if (argc != 2)
|
||||
ft_error("Error: bad number of arguments, only need a map");
|
||||
set_map(&img);
|
||||
@ -158,26 +79,16 @@ int main(int argc, char **argv)
|
||||
if (check_map(argv, &img))
|
||||
return (0);
|
||||
img.map.texture.basic = get_texture(0, 0, &img);
|
||||
printf("size= %d\n", img.map.size);
|
||||
img.mlx = mlx_init();
|
||||
if (!img.mlx)
|
||||
ft_error("Error: mlx_init fail");
|
||||
img.mlx_win = mlx_new_window(img.mlx, 960, 512, "Cub3D");
|
||||
//img.player.x = 64 * 3 + 32;
|
||||
//img.player.y = 64 + 32;
|
||||
//img.player.angle = 90;
|
||||
img.player.vx = cos(deg_to_rad(img.player.angle));
|
||||
img.player.vy = sin(deg_to_rad(img.player.angle));
|
||||
img.player.vx = sin(deg_to_rad(img.player.angle));
|
||||
img.player.vy = cos(deg_to_rad(img.player.angle));
|
||||
img.player.front = 0;
|
||||
img.player.side = 0;
|
||||
img.player.angle_side = 0;
|
||||
img.player.shift = 0;
|
||||
|
||||
//print_map(img.map, &img);
|
||||
//print_player(img.player, &img);
|
||||
//print_ray(&img);
|
||||
|
||||
|
||||
mlx_hook(img.mlx_win, 2, 1L << 0, key_pressed, &img);
|
||||
mlx_hook(img.mlx_win, 3, 1L << 1, key_released, &img);
|
||||
mlx_loop_hook(img.mlx, loop, &img);
|
||||
|
||||
92
srcs/utils.c
92
srcs/utils.c
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/14 14:58:03 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/14 16:27:38 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -107,52 +107,6 @@ int update_pos(t_data *img)
|
||||
return (0);
|
||||
}
|
||||
|
||||
// int is_good(t_data *img, int type)
|
||||
// {
|
||||
// if (type == 'w')
|
||||
// {
|
||||
// img->player.x += img->player.vx * 5;
|
||||
// img->player.y += img->player.vy * 5;
|
||||
// }
|
||||
// else if (type == 's')
|
||||
// {
|
||||
// img->player.x -= img->player.vx * 5;
|
||||
// img->player.y -= img->player.vy * 5;
|
||||
// }
|
||||
// else if (type == 'a')
|
||||
// {
|
||||
// img->player.x += img->player.vy * 5;
|
||||
// img->player.y -= img->player.vx * 5;
|
||||
// }
|
||||
// else if (type == 'd')
|
||||
// {
|
||||
// img->player.x -= img->player.vy * 5;
|
||||
// img->player.y += img->player.vx * 5;
|
||||
// }
|
||||
// else if (type == 65361)//fleche gauche
|
||||
// {
|
||||
// img->player.angle += 5;
|
||||
// img->player.angle = reset_angle(img->player.angle);
|
||||
// img->player.vx = cos(deg_to_rad(img->player.angle));
|
||||
// img->player.vy = -sin(deg_to_rad(img->player.angle));
|
||||
// }
|
||||
// else if (type == 65363)//fleche droite
|
||||
// {
|
||||
// img->player.angle -= 5;
|
||||
// img->player.angle = reset_angle(img->player.angle);
|
||||
// img->player.vx = cos(deg_to_rad(img->player.angle));
|
||||
// img->player.vy = -sin(deg_to_rad(img->player.angle));
|
||||
// }
|
||||
// else
|
||||
// return (0);
|
||||
// //printf("after player: x= %d y= %d\n", img->player.x, img->player.y);
|
||||
// return (1);
|
||||
// }
|
||||
|
||||
/*int create_trgb(int t, int r, int g, int b)
|
||||
{
|
||||
return (t << 24 | r << 16 | g << 8 | b);
|
||||
}*/
|
||||
int create_trgb(unsigned char t, unsigned char r, unsigned char g, unsigned char b)
|
||||
{
|
||||
return (*(int *)(unsigned char [4]){b, g, r, t});
|
||||
@ -160,16 +114,6 @@ int create_trgb(unsigned char t, unsigned char r, unsigned char g, unsigned char
|
||||
|
||||
void set_back(t_data *img)
|
||||
{
|
||||
//int x = 0;
|
||||
//int y = 0;
|
||||
//int *buffer;
|
||||
//int color;
|
||||
|
||||
//color = get_color(128, 128, 128);
|
||||
//printf("test= %d\n", img->buffer[0]);
|
||||
//img->buffer;
|
||||
|
||||
|
||||
/*for(int y = 0; y < 512; ++y)
|
||||
for(int x = 0; x < 960; ++x)
|
||||
{
|
||||
@ -234,38 +178,4 @@ void set_back(t_data *img)
|
||||
}
|
||||
x += 4;
|
||||
}
|
||||
//img->buffer = (char *)tmp;
|
||||
/*while (x < 960)
|
||||
{
|
||||
y = 0;
|
||||
while (y < 512)
|
||||
{
|
||||
mlx_pixel_put(img->mlx, img->mlx_win, x , y, get_color(128, 128, 128));
|
||||
//img->buffer[1] = color;
|
||||
//mlx_pixel_put(img->mlx, img->mlx_win, x , y - 160, get_color(0, 255, 255));
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}*/
|
||||
}
|
||||
|
||||
// int key_press(int code, t_data *img)
|
||||
// {
|
||||
// //printf("touche ");
|
||||
// if (code == 65307)
|
||||
// quit_game(img);
|
||||
// else
|
||||
// {
|
||||
// if (is_good(img, code))
|
||||
// {
|
||||
// //printf("code = %d\n", code);
|
||||
// //mlx_clear_window(img->mlx, img->mlx_win);
|
||||
// //print_map(img->map, img);
|
||||
// //print_player(img->player, img);
|
||||
// //set_back(img);
|
||||
// draw_ray(img);
|
||||
// //print_ray(img);
|
||||
// }
|
||||
// }
|
||||
// return (1);
|
||||
//}
|
||||
Loading…
Reference in New Issue
Block a user