「✨」 feat(Texture): Fully working 👍
This commit is contained in:
BIN
img/flo.png
BIN
img/flo.png
Binary file not shown.
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 13 KiB |
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/04 14:06:39 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/09 15:54:46 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/11/10 13:48:57 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -29,6 +29,6 @@
|
||||
# define FOV 70
|
||||
|
||||
# define CHUNK_SIZE 64
|
||||
# define TEXTURE_SIZE 128
|
||||
# define TEXTURE_SIZE 64
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/07 16:55:09 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/06 13:21:38 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/11/10 14:26:42 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -36,6 +36,12 @@ void setup_dda_ver(t_player *play, t_ray *ray, t_dda *dda)
|
||||
ray->pos.x = (((int)play->coord.x >> 6) << 6) + CHUNK_SIZE;
|
||||
ray->pos.y = (play->coord.x - ray->pos.x) * ray->tan + play->coord.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
dda->s = false;
|
||||
ray->pos.x = play->coord.x;
|
||||
ray->pos.y = play->coord.y;
|
||||
}
|
||||
}
|
||||
|
||||
void setup_dda_hor(t_player *play, t_ray *ray, t_dda *dda)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/28 15:48:39 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/09 17:38:48 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/11/10 15:44:00 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -54,7 +54,39 @@ void draw_celling(t_render *render)
|
||||
}
|
||||
}
|
||||
|
||||
void print_line(t_render *render, t_ray *ray, int x)
|
||||
int get_color(t_ray *ray, t_dda *dda, t_render *render, int line_start, int line_stop, int line_size)
|
||||
{
|
||||
int x;
|
||||
int h;
|
||||
int color;
|
||||
void **texture;
|
||||
|
||||
(void)ray;
|
||||
line_stop = line_size / 2 + WINDOW_H / 2;
|
||||
if (dda->distance.y < dda->distance.x)
|
||||
{
|
||||
x = (int)dda->hori.x % CHUNK_SIZE;
|
||||
h = abs((line_stop - line_start) * TEXTURE_SIZE / line_size - 63);
|
||||
if (ray->angle < M_PI)
|
||||
texture = &render->texture[0];
|
||||
else
|
||||
texture = &render->texture[2];
|
||||
color = mlx_get_image_pixel(render->mlx, *texture, x, h);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = (int)dda->vert.y % CHUNK_SIZE;
|
||||
h = abs((line_stop - line_start) * TEXTURE_SIZE / line_size - 63);
|
||||
if (ray->angle <= 3 * M_PI / 2 && ray->angle >= M_PI / 2)
|
||||
texture = &render->texture[1];
|
||||
else
|
||||
texture = &render->texture[3];
|
||||
color = mlx_get_image_pixel(render->mlx, *texture, x, h);
|
||||
}
|
||||
return (color);
|
||||
}
|
||||
|
||||
void print_line(t_render *render, t_ray *ray, int x, t_dda *dda)
|
||||
{
|
||||
int line_size;
|
||||
int line_stop;
|
||||
@ -70,7 +102,7 @@ void print_line(t_render *render, t_ray *ray, int x)
|
||||
while (line_start < line_stop)
|
||||
{
|
||||
if (x < WINDOW_W && x >= 0)
|
||||
mlx_set_image_pixel(render->mlx, render->img, x, line_start, WHITE);
|
||||
mlx_set_image_pixel(render->mlx, render->img, x, line_start, get_color(ray, dda, render, line_start, line_stop, line_size));
|
||||
line_start++;
|
||||
}
|
||||
}
|
||||
@ -92,7 +124,7 @@ void render_frame(t_render *render)
|
||||
dda_algo(render, &dda, &ray);
|
||||
ang = cos(render->player->direction - ray.angle);
|
||||
ray.distance *= ang;
|
||||
print_line(render, &ray, i);
|
||||
print_line(render, &ray, i, &dda);
|
||||
ray.angle += (M_PI / 180) / ((float)WINDOW_W / FOV);
|
||||
fix_ang(&ray.angle);
|
||||
i--;
|
||||
|
Reference in New Issue
Block a user