changed functions draw line and pixel to receive an img ptr instead of the whole structure
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
static int pxl_out_limits(t_game *game, int x, int y)
|
||||
static int pxl_out_limits(t_img *img, int x, int y)
|
||||
{
|
||||
int xmax;
|
||||
int ymax;
|
||||
|
||||
xmax = game->map_img.sizel / (game->map_img.bpp / 8);
|
||||
ymax = game->map_win.size_y;
|
||||
xmax = img->szl / (img->bpp / 8);
|
||||
ymax = img->height;
|
||||
if (x < 0 || y < 0 || x > xmax || y > ymax)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void draw_pixel(t_game *game, int x, int y, int color)
|
||||
void draw_pixel(t_img *img, int x, int y, int color)
|
||||
{
|
||||
unsigned int position;
|
||||
|
||||
if (pxl_out_limits(game, x, y))
|
||||
if (pxl_out_limits(img, x, y))
|
||||
return ;
|
||||
position = y * game->map_img.sizel + x * (game->map_img.bpp / 8);
|
||||
*(unsigned int*)(game->map_img.data + position) = color;
|
||||
position = y * img->szl + x * (img->bpp / 8);
|
||||
*(unsigned int*)(img->data + position) = color;
|
||||
}
|
||||
|
||||
void draw_line(t_game *game, t_vec vec, int color)
|
||||
void draw_line(t_img *img, t_vec vec, int color)
|
||||
{
|
||||
t_coord dist;
|
||||
int i;
|
||||
@@ -34,7 +34,7 @@ void draw_line(t_game *game, t_vec vec, int color)
|
||||
j = 0;
|
||||
while (ft_abs(i) <= ft_abs(dist.x) && ft_abs(j) <= ft_abs(dist.y))
|
||||
{
|
||||
draw_pixel(game, vec.start.x + i, vec.start.y + j, color);
|
||||
draw_pixel(img, vec.start.x + i, vec.start.y + j, color);
|
||||
if (!ft_abs(dist.x) || ft_abs(j) < ft_abs(i * dist.y / dist.x))
|
||||
j += ft_sign(dist.y);
|
||||
else
|
||||
@@ -60,11 +60,11 @@ void draw_line(t_game *game, t_vec vec, int color)
|
||||
if (rotation)
|
||||
rotate(&(game->plr), &(new));
|
||||
if (!i || i == size - 1)
|
||||
draw_pixel(game, new.x, new.y, border);
|
||||
draw_pixel(&game->map_img, new.x, new.y, border);
|
||||
else if (!j || j == size - 1)
|
||||
draw_pixel(game, new.x, new.y, border);
|
||||
draw_pixel(&game->map_img, new.x, new.y, border);
|
||||
else
|
||||
draw_pixel(game, new.x, new.y, fill);
|
||||
draw_pixel(&game->map_img, new.x, new.y, fill);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
@@ -113,14 +113,14 @@ void draw_line(t_game *game, t_vec vec, int color)
|
||||
screen.end.x = rcast->screen_size.end.x + game->plr.pos.x;
|
||||
screen.end.y = rcast->screen_size.end.y + game->plr.pos.y;
|
||||
rotate(&(game->plr), &(screen.end));
|
||||
draw_line(game, screen, 0x00FFFFFF);
|
||||
draw_line(&game->map_img, screen, 0x00FFFFFF);
|
||||
// draw screen dist
|
||||
screen.start.x = rcast->screen_dist.start.x + game->plr.pos.x;
|
||||
screen.start.y = rcast->screen_dist.start.y + game->plr.pos.y;
|
||||
screen.end.x = rcast->screen_dist.end.x + game->plr.pos.x;
|
||||
screen.end.y = rcast->screen_dist.end.y + game->plr.pos.y;
|
||||
rotate(&(game->plr), &(screen.end));
|
||||
draw_line(game, screen, 0x00FFFFFF);
|
||||
draw_line(&game->map_img, screen, 0x00FFFFFF);
|
||||
}
|
||||
// tmp end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user