74 lines
1.7 KiB
C
74 lines
1.7 KiB
C
#include "cube3d.h"
|
|
|
|
// tmp, to draw rays
|
|
static void calcul_ray_end(t_rcast *rcast, t_vec *ray)
|
|
{
|
|
if (rcast->is_x)
|
|
{
|
|
ray->end.x = rcast->cell_x * rcast->cell;
|
|
if (rcast->ray_sign_x == 1)
|
|
ray->end.x += rcast->cell;
|
|
if (rcast->slope_x)
|
|
{
|
|
rcast->ratio = (double)(ray->end.x - ray->start.x);
|
|
rcast->ratio /= (double)rcast->slope_x;
|
|
ray->end.y = ray->start.y + (double)rcast->slope_y * rcast->ratio;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ray->end.y = rcast->cell_y * rcast->cell;
|
|
if (rcast->ray_sign_y == 1)
|
|
ray->end.y += rcast->cell;
|
|
if (rcast->slope_y)
|
|
{
|
|
rcast->ratio = (double)(ray->end.y - ray->start.y);
|
|
rcast->ratio /= (double)rcast->slope_y;
|
|
ray->end.x = ray->start.x + (double)rcast->slope_x * rcast->ratio;
|
|
}
|
|
}
|
|
}
|
|
// tmp end
|
|
|
|
void draw_column(t_game *game, t_rcast *rcast, t_vec *ray)
|
|
{
|
|
t_vec wall;
|
|
|
|
(void)game;
|
|
(void)rcast;
|
|
(void)ray;
|
|
(void)wall;
|
|
|
|
wall.start.x = rcast->ray_nb;
|
|
wall.end.x = rcast->ray_nb;
|
|
if (rcast->is_x == 1 && rcast->slope_y != 0)
|
|
{
|
|
rcast->wall_height = rcast->next_x - rcast->ray_step_x;
|
|
rcast->wall_height /= ft_abs(rcast->slope_y);
|
|
rcast->wall_height /= 2;
|
|
//printf("rcast->wall: %i\n", rcast->wall_height);
|
|
wall.start.y = rcast->screen_center / 2 + rcast->wall_height;
|
|
wall.end.y = rcast->screen_center / 2 - rcast->wall_height;
|
|
}
|
|
// draw_line(&game->img, wall, 0x00FF0000);
|
|
}
|
|
|
|
void raycast(t_game *game, t_rcast *rcast)
|
|
{
|
|
t_vec ray;
|
|
|
|
rcast->ray_nb = 0;
|
|
while (rcast->ray_nb <= rcast->screen_def)
|
|
{
|
|
ray_intersect(game, rcast, &ray);
|
|
|
|
// tmp, to draw the map
|
|
calcul_ray_end(rcast, &ray);
|
|
draw_line(&game->map_img, ray, 0x00FF00FF);
|
|
// tmp end
|
|
|
|
draw_column(game, rcast, &ray);
|
|
(rcast->ray_nb)++;
|
|
}
|
|
}
|