affichage pas ouf car une seule image et erreur dans la size de l'image
This commit is contained in:
43
srcs/fdf.c
43
srcs/fdf.c
@@ -1,4 +1,5 @@
|
||||
#include "fdf.h"
|
||||
#include <stdio.h>
|
||||
|
||||
t_fdf *init_fdf(void);
|
||||
int print_keycode(int keycode);
|
||||
@@ -10,19 +11,36 @@ int **parse_map(t_fdf *fdf);
|
||||
|
||||
void draw_image(t_fdf *fdf)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int i;
|
||||
int j;
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int new_x;
|
||||
int new_y;
|
||||
|
||||
y = 0;
|
||||
while (y < fdf->img_size_y)
|
||||
// init image with 0
|
||||
i =-1;
|
||||
while (++i < fdf->img_size_y * fdf->img_sizel)
|
||||
*(unsigned int*)(fdf->img_addr + i) = 0;
|
||||
// draw image
|
||||
j = -1;
|
||||
while (++j < fdf->map_size_y)
|
||||
{
|
||||
x = 0;
|
||||
while ((x * fdf->img_bpp / 8) < fdf->img_sizel)
|
||||
i = -1;
|
||||
while (++i < fdf->map_size_x)
|
||||
{
|
||||
draw_pixel(fdf, x, y, 0xffffff);
|
||||
x += fdf->offset;
|
||||
|
||||
x = i * fdf->offset;
|
||||
y = j * fdf->offset;
|
||||
// z = fdf->map[j][i];
|
||||
z = 1;
|
||||
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;
|
||||
draw_pixel(fdf, new_x, new_y, 0xffffff);
|
||||
}
|
||||
y += fdf->offset;
|
||||
}
|
||||
// put image on screen
|
||||
mlx_put_image_to_window(fdf->mlx_ptr, fdf->win_ptr, fdf->img_ptr, 0, 0);
|
||||
@@ -61,6 +79,9 @@ int keypress(int keycode, t_fdf *fdf)
|
||||
(fdf->rot_y) -= 1;
|
||||
else
|
||||
print_keycode(keycode);
|
||||
// calculate radians
|
||||
fdf->rad_x = fdf->rot_x * M_PI / 180;
|
||||
fdf->rad_y = fdf->rot_y * M_PI / 180;
|
||||
// draw image
|
||||
draw_image(fdf);
|
||||
return (0);
|
||||
@@ -77,6 +98,8 @@ void draw_pixel(t_fdf *fdf, int x, int y, int color)
|
||||
{
|
||||
int position;
|
||||
|
||||
if (x < 0 || y < 0 || x > fdf->img_sizel || y > fdf->map_size_y)
|
||||
return ;
|
||||
position = y * fdf->img_sizel + x * fdf->img_bpp / 8;
|
||||
*(unsigned int*)(fdf->img_addr + position) = color;
|
||||
}
|
||||
@@ -89,7 +112,7 @@ void rotation_state(t_fdf *fdf)
|
||||
|
||||
x = fdf->img_size_x - 10;
|
||||
y = fdf->img_size_y - 10;
|
||||
position = ft_strjoin(ft_itoa(fdf->rot_x), " | ");
|
||||
position = ft_strjoin(ft_itoa(fdf->rot_x), ft_strdup(" | "));
|
||||
position = ft_strjoin(position, ft_itoa(fdf->rot_y));
|
||||
x -= ft_strlen(position) * 6;
|
||||
mlx_string_put(fdf->mlx_ptr, fdf->win_ptr, x, y, 0xffffff, position);
|
||||
|
||||
Reference in New Issue
Block a user