Added memorybook to parsing and cleaned most of the files
This commit is contained in:
@@ -1,65 +1,16 @@
|
||||
#include "cube3d.h"
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* draw.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:55:29 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:55:31 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
// tmp draw map
|
||||
// static void draw_square(t_game *game, t_coord pos, int border, int fill, int size, int rotation)
|
||||
// {
|
||||
// int i;
|
||||
// int j;
|
||||
// t_coord new;
|
||||
//
|
||||
// i = 0;
|
||||
// while (i < size)
|
||||
// {
|
||||
// j = 0;
|
||||
// while (j < size)
|
||||
// {
|
||||
// new.x = pos.x + j;
|
||||
// new.y = pos.y + i;
|
||||
// if (rotation)
|
||||
// rotate(&(game->plr), &(new));
|
||||
// if (!i || i == size - 1)
|
||||
// draw_pixel(&game->map_img, new.x, new.y, border);
|
||||
// else if (!j || j == size - 1)
|
||||
// draw_pixel(&game->map_img, new.x, new.y, border);
|
||||
// else
|
||||
// draw_pixel(&game->map_img, new.x, new.y, fill);
|
||||
// j++;
|
||||
// }
|
||||
// i++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static void draw_map(t_game *game)
|
||||
// {
|
||||
// t_coord incr;
|
||||
// t_coord pos;
|
||||
// int cell;
|
||||
//
|
||||
// cell = game->map.cell;
|
||||
// incr.x = 0;
|
||||
// pos.x = 0;
|
||||
// pos.y = 0;
|
||||
// while ((game->map.content)[incr.x])
|
||||
// {
|
||||
// incr.y = 0;
|
||||
// while ((game->map.content)[incr.x][incr.y])
|
||||
// {
|
||||
// if ((game->map.content)[incr.x][incr.y] == '1' )
|
||||
// draw_square(game, pos, 0x00999999, 0x00000000, cell, 0);
|
||||
// else
|
||||
// draw_square(game, pos, 0x00555555, 0x00333333, cell, 0);
|
||||
// (incr.y)++;
|
||||
// pos.x += cell;
|
||||
// }
|
||||
// (incr.x)++;
|
||||
// pos.x = 0;
|
||||
// pos.y += cell;
|
||||
// }
|
||||
// pos.x = game->plr.pos.x - cell / 2;
|
||||
// pos.y = game->plr.pos.y - cell / 2;
|
||||
// draw_square(game, pos, 0x00999900, 0x00330033, cell, 1);
|
||||
// }
|
||||
// tmp end
|
||||
#include "cube3d.h"
|
||||
|
||||
static int pxl_out_limits(t_img *img, int x, int y)
|
||||
{
|
||||
@@ -80,7 +31,7 @@ void draw_pixel(t_img *img, int x, int y, int color)
|
||||
if (pxl_out_limits(img, x, y))
|
||||
return ;
|
||||
position = y * img->szl + x * (img->bpp / 8);
|
||||
*(unsigned int*)(img->data + position) = color;
|
||||
*(unsigned int *)(img->data + position) = color;
|
||||
}
|
||||
|
||||
void draw_line(t_img *img, t_vec *vec, int color)
|
||||
@@ -105,16 +56,6 @@ void draw_line(t_img *img, t_vec *vec, int color)
|
||||
|
||||
void draw(t_game *game)
|
||||
{
|
||||
// tmp draw map
|
||||
// draw_map(game);
|
||||
// tmp end
|
||||
|
||||
raycast(game, &(game->rcast));
|
||||
|
||||
// tmp draw map
|
||||
// draw_screen(game, &(game->rcast));
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* draw_column.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:51:59 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:52:01 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
static void draw_floor_ceiling(t_game *game, t_rcast *rcast, t_txt *txt)
|
||||
@@ -40,16 +52,6 @@ static void draw_txt_column(t_game *game, t_wall *wall, t_img *txt_img)
|
||||
int j;
|
||||
|
||||
img_x = (wall->posx * txt_img->width) / game->rcast.cell;
|
||||
|
||||
// tmp draw map
|
||||
// if (game->ray_activ)
|
||||
// {
|
||||
// printf("img_x:%i ", img_x);
|
||||
// draw_line(&game->img, &wall->vec, 0x00FF00FF);
|
||||
// return ;
|
||||
// }
|
||||
// tmp end
|
||||
|
||||
j = wall->limit;
|
||||
i = 0;
|
||||
while (j < wall->height - wall->limit)
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ray_intersect.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:52:25 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:52:27 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
static void init_ray_params(t_rcast *rcast, t_vec *ray)
|
||||
|
||||
@@ -1,34 +1,16 @@
|
||||
#include "cube3d.h"
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* raycast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:54:22 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:54:23 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
// tmp draw map
|
||||
// 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
|
||||
#include "cube3d.h"
|
||||
|
||||
static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
||||
{
|
||||
@@ -37,42 +19,22 @@ static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
||||
if (rcast->is_x == 1)
|
||||
{
|
||||
tmp = wall->delta;
|
||||
// tmp += rcast->slope_y;
|
||||
tmp *= -rcast->ray_sign_y;
|
||||
tmp /= ft_abs(rcast->slope_x);
|
||||
tmp += game->plr.pos.y;
|
||||
|
||||
// tmp draw map
|
||||
// if (game->ray_activ)
|
||||
// printf("tmp:%i ", tmp);
|
||||
// tmp end
|
||||
|
||||
wall->posx = tmp % rcast->cell;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = wall->delta;
|
||||
// tmp += rcast->slope_x;
|
||||
tmp *= -rcast->ray_sign_x;
|
||||
tmp /= ft_abs(rcast->slope_y);
|
||||
tmp += game->plr.pos.x;
|
||||
|
||||
// tmp draw map
|
||||
// if (game->ray_activ)
|
||||
// printf("tmp:%i ", tmp);
|
||||
// tmp end
|
||||
|
||||
wall->posx = tmp % rcast->cell;
|
||||
}
|
||||
|
||||
// tmp draw map
|
||||
// if (game->ray_activ)
|
||||
// printf("wall->posx:%i ", wall->posx);
|
||||
// tmp end
|
||||
|
||||
}
|
||||
|
||||
static void fill_wall_vector(t_rcast *rcast, t_wall *wall)
|
||||
static void fill_wall_vector(t_rcast *rcast, t_wall *wall)
|
||||
{
|
||||
int height;
|
||||
|
||||
@@ -117,35 +79,10 @@ void raycast(t_game *game, t_rcast *rcast)
|
||||
rcast->ray_nb = 0;
|
||||
while (rcast->ray_nb <= rcast->screen_width)
|
||||
{
|
||||
|
||||
// tmp draw map
|
||||
// // rays
|
||||
// game->ray_activ = 0;
|
||||
// if (rcast->ray_nb == game->ray_highlight)
|
||||
// {
|
||||
// game->ray_activ = 1;
|
||||
// game->ray = ray;
|
||||
// }
|
||||
// tmp end
|
||||
|
||||
ray_intersect_wall(game, rcast, &ray);
|
||||
|
||||
// tmp draw map
|
||||
// calcul_ray_end(rcast, &ray);
|
||||
// if (game->ray_activ)
|
||||
// draw_line(&game->map_img, &ray, 0x00FF00FF);
|
||||
// else if (rcast->ray_nb % 10 == 0)
|
||||
// draw_line(&game->map_img, &ray, 0x00FFFFFF);
|
||||
// tmp end
|
||||
|
||||
calcul_wall(rcast);
|
||||
calcul_img_column(game, rcast, &rcast->wall);
|
||||
draw_column(game, rcast, &rcast->wall, &game->txt);
|
||||
(rcast->ray_nb)++;
|
||||
}
|
||||
|
||||
// tmp draw map
|
||||
// printf("\n\n");
|
||||
// tmp end
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user