add place for game window
This commit is contained in:
@@ -134,7 +134,7 @@ void draw(t_game *game)
|
||||
|
||||
// tmp, to draw map
|
||||
draw_screen(game, &(game->rcast));
|
||||
mlx_put_image_to_window(game->mlx_ptr, game->map_win.ptr, game->map_img.ptr, 0, 0);
|
||||
mlx_put_image_to_window(game->mlx_ptr, game->map_win.ptr, game->map_img.ptr, 0, SCREEN_HEIGHT);
|
||||
// tmp end
|
||||
|
||||
// mlx_put_image_to_window(game->mlx_ptr, game->win.ptr, game->img.ptr, 0, 0);
|
||||
|
||||
@@ -27,7 +27,6 @@ static void init_raycast(t_rcast *rcast, t_vec *ray)
|
||||
|
||||
static void init_first_step(t_rcast *rcast, t_vec *ray)
|
||||
{
|
||||
// first next time ray cross grid
|
||||
rcast->first_next_x = ray->start.x % rcast->cell;
|
||||
if (rcast->first_next_x && rcast->ray_sign_x < 0)
|
||||
rcast->first_next_x = rcast->cell - rcast->first_next_x;
|
||||
@@ -58,70 +57,6 @@ static void next_cell(t_rcast *rcast)
|
||||
}
|
||||
}
|
||||
|
||||
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) / (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) / (double)rcast->slope_y;
|
||||
ray->end.x = ray->start.x + (double)rcast->slope_x * rcast->ratio;
|
||||
}
|
||||
}
|
||||
*/
|
||||
int *nd1;
|
||||
int *cell1;
|
||||
int *sign1;
|
||||
int *st1;
|
||||
int *slp1;
|
||||
int *nd2;
|
||||
int *st2;
|
||||
int *slp2;
|
||||
|
||||
if (rcast->is_x)
|
||||
{
|
||||
nd1 = &(ray->end.x);
|
||||
cell1 = &(rcast->cell_x);
|
||||
sign1 = &(rcast->ray_sign_x);
|
||||
st1 = &(ray->start.x);
|
||||
slp1 = &(rcast->slope_x);
|
||||
nd2 = &(ray->end.y);
|
||||
st2 = &(ray->start.y);
|
||||
slp2 = &(rcast->slope_y);
|
||||
}
|
||||
else
|
||||
{
|
||||
nd1 = &(ray->end.y);
|
||||
cell1 = &(rcast->cell_y);
|
||||
sign1 = &(rcast->ray_sign_y);
|
||||
st1 = &(ray->start.y);
|
||||
slp1 = &(rcast->slope_y);
|
||||
nd2 = &(ray->end.x);
|
||||
st2 = &(ray->start.x);
|
||||
slp2 = &(rcast->slope_x);
|
||||
}
|
||||
*nd1 = *cell1 * rcast->cell;
|
||||
if (*sign1 == 1)
|
||||
*nd1 += rcast->cell;
|
||||
if (*slp1)
|
||||
*nd2 = *st2 + (double)(*slp2) * (double)(*nd1 - *st1) / (double)(*slp1);
|
||||
}
|
||||
|
||||
void ray_intersect(t_game *game, t_rcast *rcast, t_vec *ray)
|
||||
{
|
||||
ray->start.x = rcast->ray.start.x + game->plr.pos.x;
|
||||
@@ -132,9 +67,6 @@ void ray_intersect(t_game *game, t_rcast *rcast, t_vec *ray)
|
||||
rotate(&(game->plr), &(ray->end));
|
||||
init_raycast(rcast, ray);
|
||||
init_first_step(rcast, ray);
|
||||
// loop through grid
|
||||
while (!is_wall(game, rcast->cell_x, rcast->cell_y))
|
||||
next_cell(rcast);
|
||||
// end ray position
|
||||
calcul_ray_end(rcast, ray);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
#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)
|
||||
{
|
||||
(void)game;
|
||||
(void)rcast;
|
||||
(void)ray;
|
||||
}
|
||||
|
||||
void raycast(t_game *game, t_rcast *rcast)
|
||||
{
|
||||
t_vec ray;
|
||||
@@ -10,10 +47,11 @@ void raycast(t_game *game, t_rcast *rcast)
|
||||
ray_intersect(game, rcast, &ray);
|
||||
|
||||
// tmp, to draw the map
|
||||
calcul_ray_end(rcast, &ray);
|
||||
draw_line(game, ray, 0x00FF00FF);
|
||||
// tmp end
|
||||
|
||||
// draw_column();
|
||||
draw_column(game, rcast, &ray);
|
||||
(rcast->ray_nb)++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user