drawpixel fonctionne pour la limite horizontale mais pas verticale, et implementation macro lettres + mouvements

This commit is contained in:
hugogogo
2021-07-19 08:49:32 +02:00
parent 17352e6e50
commit fce788547a
5 changed files with 46 additions and 240 deletions

View File

@@ -38,7 +38,8 @@ void draw_image(t_fdf *fdf)
new_x = x * cos(fdf->rad_y) + y * sin(fdf->rad_y);
new_y = y * cos(fdf->rad_y) - x * sin(fdf->rad_y);
new_y = new_y * cos(fdf->rad_x) - z * sin(fdf->rad_x);
new_x += 100;
new_x += fdf->margin + fdf->mov_x;
new_y += fdf->margin + fdf->mov_y;
draw_pixel(fdf, new_x, new_y, 0xffffff);
}
}
@@ -77,6 +78,14 @@ int keypress(int keycode, t_fdf *fdf)
(fdf->rot_y) += 1;
else if (keycode == DOWN)
(fdf->rot_y) -= 1;
else if (keycode == Q)
(fdf->mov_x) -= 6;
else if (keycode == D)
(fdf->mov_x) += 6;
else if (keycode == Z)
(fdf->mov_y) += 6;
else if (keycode == S)
(fdf->mov_y) -= 6;
else
print_keycode(keycode);
// calculate radians
@@ -97,8 +106,12 @@ int print_keycode(int keycode)
void draw_pixel(t_fdf *fdf, int x, int y, int color)
{
int position;
int xmax;
int ymax;
if (x < 0 || y < 0 || x > fdf->img_sizel || y > fdf->map_size_y)
xmax = fdf->img_sizel / (fdf->img_bpp / 8);
ymax = fdf->map_size_y;
if (x < 0 || y < 0 || x > xmax || y > ymax)
return ;
position = y * fdf->img_sizel + x * fdf->img_bpp / 8;
*(unsigned int*)(fdf->img_addr + position) = color;
@@ -137,6 +150,9 @@ t_fdf *init_fdf(void)
// view rotation
fdf->rot_x = 0;
fdf->rot_y = 0;
// x and y deplacements
fdf->mov_x = 0;
fdf->mov_y = 0;
// init connexion to server
fdf->mlx_ptr = mlx_init();
// create the window