ajout deux ressources readme et calcul points coordonnees
This commit is contained in:
@@ -26,4 +26,8 @@ This README would normally document whatever steps are necessary to get your app
|
|||||||
### Who do I talk to? ###
|
### Who do I talk to? ###
|
||||||
|
|
||||||
* Repo owner or admin
|
* Repo owner or admin
|
||||||
* Other community or team contact
|
* Other community or team contact
|
||||||
|
|
||||||
|
### ressources
|
||||||
|
https://harm-smits.github.io/42docs/libs/minilibx
|
||||||
|
https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
|
||||||
|
|||||||
BIN
builds/fdf.o
BIN
builds/fdf.o
Binary file not shown.
78
srcs/fdf.c
78
srcs/fdf.c
@@ -4,35 +4,50 @@
|
|||||||
t_fdf *init_fdf(void);
|
t_fdf *init_fdf(void);
|
||||||
int print_keycode(int keycode);
|
int print_keycode(int keycode);
|
||||||
int shut_down(t_fdf *fdf);
|
int shut_down(t_fdf *fdf);
|
||||||
|
void draw_image(t_fdf *fdf);
|
||||||
void draw_pixel(t_fdf *fdf, int x, int y, int color);
|
void draw_pixel(t_fdf *fdf, int x, int y, int color);
|
||||||
|
void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int z);
|
||||||
int keypress(int keycode, t_fdf *fdf);
|
int keypress(int keycode, t_fdf *fdf);
|
||||||
void rotation_state(t_fdf *fdf);
|
void rotation_state(t_fdf *fdf);
|
||||||
int **parse_map(t_fdf *fdf);
|
int **parse_map(t_fdf *fdf);
|
||||||
|
int *new_coordinates(t_fdf *fdf, int i, int j);
|
||||||
|
|
||||||
void color_altitude_pixel(t_fdf *fdf, int new_x, int new_y, int z)
|
// return an int[3] : int[0] = x, int[1] = y, int[2] = z
|
||||||
|
int *new_coordinates(t_fdf *fdf, int i, int j)
|
||||||
{
|
{
|
||||||
int color;
|
int x;
|
||||||
|
int y;
|
||||||
|
int z;
|
||||||
|
int *point;
|
||||||
|
|
||||||
color = 0xffffff;
|
point = ft_calloc(3, sizeof(int));
|
||||||
z = z / fdf->altitude;
|
x = i * fdf->offset - (fdf->map_size_x / 2);
|
||||||
if (z)
|
y = j * fdf->offset - (fdf->map_size_y / 2);
|
||||||
{
|
z = fdf->map[j][i] * fdf->altitude;
|
||||||
color = color ^ (((0xff / fdf->max_z) * z) << 8 );
|
point[0] = x * cos(fdf->rad_x) + y * sin(fdf->rad_x);
|
||||||
color = color ^ ((0xff / fdf->max_z) * z);
|
point[1] = y * cos(fdf->rad_x) - x * sin(fdf->rad_x);
|
||||||
ft_printf("0xff:%i z:%i (0xff / max_z):%i ((0xff / max_z) * z):%i\n", 0xff, z, (0xff / fdf->max_z), ((0xff / fdf->max_z) * z));
|
point[1] = point[1] * cos(fdf->rad_y) - -z * sin(fdf->rad_y);
|
||||||
}
|
point[0] += fdf->margin + fdf->mov_x + (fdf->map_size_x / 2);
|
||||||
draw_pixel(fdf, new_x, new_y, color);
|
point[1] += fdf->margin + fdf->mov_y + (fdf->map_size_y / 2);
|
||||||
|
point[2] = z;
|
||||||
|
return (point);
|
||||||
|
}
|
||||||
|
|
||||||
|
// point[0], point[1], point[2] -> new x, new y, new z
|
||||||
|
void draw_lines(t_fdf *fdf, int i, int j)
|
||||||
|
{
|
||||||
|
int *point_start;
|
||||||
|
int *point_end;
|
||||||
|
|
||||||
|
point_start = new_coordinates(fdf, i, j);
|
||||||
|
point_end = new_coordinates(fdf, i, j);
|
||||||
|
draw_color_pixel(fdf, point_start[0], point_start[1], point_start[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_image(t_fdf *fdf)
|
void draw_image(t_fdf *fdf)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int z;
|
|
||||||
int new_x;
|
|
||||||
int new_y;
|
|
||||||
|
|
||||||
// init image with 0
|
// init image with 0
|
||||||
i =-1;
|
i =-1;
|
||||||
@@ -44,18 +59,7 @@ void draw_image(t_fdf *fdf)
|
|||||||
{
|
{
|
||||||
i = -1;
|
i = -1;
|
||||||
while (++i < fdf->map_width)
|
while (++i < fdf->map_width)
|
||||||
{
|
draw_lines(fdf, i, j);
|
||||||
|
|
||||||
x = i * fdf->offset - (fdf->map_size_x / 2);
|
|
||||||
y = j * fdf->offset - (fdf->map_size_y / 2);
|
|
||||||
z = fdf->map[j][i] * fdf->altitude;
|
|
||||||
new_x = x * cos(fdf->rad_x) + y * sin(fdf->rad_x);
|
|
||||||
new_y = y * cos(fdf->rad_x) - x * sin(fdf->rad_x);
|
|
||||||
new_y = new_y * cos(fdf->rad_y) - -z * sin(fdf->rad_y);
|
|
||||||
new_x += fdf->margin + fdf->mov_x + (fdf->map_size_x / 2);
|
|
||||||
new_y += fdf->margin + fdf->mov_y + (fdf->map_size_y / 2);
|
|
||||||
color_altitude_pixel(fdf, new_x, new_y, z);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// put image on screen
|
// put image on screen
|
||||||
mlx_put_image_to_window(fdf->mlx_ptr, fdf->win_ptr, fdf->img_ptr, 0, 0);
|
mlx_put_image_to_window(fdf->mlx_ptr, fdf->win_ptr, fdf->img_ptr, 0, 0);
|
||||||
@@ -85,9 +89,9 @@ int keypress(int keycode, t_fdf *fdf)
|
|||||||
if (keycode == ESCAPE)
|
if (keycode == ESCAPE)
|
||||||
shut_down(fdf);
|
shut_down(fdf);
|
||||||
else if (keycode == LEFT)
|
else if (keycode == LEFT)
|
||||||
(fdf->rot_x) -= 1;
|
|
||||||
else if (keycode == RIGHT)
|
|
||||||
(fdf->rot_x) += 1;
|
(fdf->rot_x) += 1;
|
||||||
|
else if (keycode == RIGHT)
|
||||||
|
(fdf->rot_x) -= 1;
|
||||||
else if (keycode == UP)
|
else if (keycode == UP)
|
||||||
(fdf->rot_y) += 1;
|
(fdf->rot_y) += 1;
|
||||||
else if (keycode == DOWN)
|
else if (keycode == DOWN)
|
||||||
@@ -131,6 +135,20 @@ void draw_pixel(t_fdf *fdf, int x, int y, int color)
|
|||||||
*(unsigned int*)(fdf->img_addr + position) = color;
|
*(unsigned int*)(fdf->img_addr + position) = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int z)
|
||||||
|
{
|
||||||
|
int color;
|
||||||
|
|
||||||
|
color = 0xffffff;
|
||||||
|
z = z / fdf->altitude;
|
||||||
|
if (z)
|
||||||
|
{
|
||||||
|
color = color ^ (((0xff / fdf->max_z) * z) << 8 );
|
||||||
|
color = color ^ ((0xff / fdf->max_z) * z);
|
||||||
|
}
|
||||||
|
draw_pixel(fdf, new_x, new_y, color);
|
||||||
|
}
|
||||||
|
|
||||||
void rotation_state(t_fdf *fdf)
|
void rotation_state(t_fdf *fdf)
|
||||||
{
|
{
|
||||||
char *position;
|
char *position;
|
||||||
|
|||||||
Reference in New Issue
Block a user