-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm_isometric.c
More file actions
118 lines (107 loc) · 3.52 KB
/
m_isometric.c
File metadata and controls
118 lines (107 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* m_isometric.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nkawaguc <nkawaguc@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/28 12:20:52 by nkawaguc #+# #+# */
/* Updated: 2024/10/28 12:30:36 by nkawaguc ### ########.fr */
/* */
/* ************************************************************************** */
#include "m_fdf.h"
static void calc_coordinate(t_data *data, t_map *map, int i, int j);
static void size_adjust(t_data *data, t_map *map);
static void update_zoom(t_data *data, t_map *map);
static void update_size(t_data *data, t_map *map);
void isometric(t_data *data, t_map *map)
{
int i;
int j;
isometric_init(data);
map->points = malloc_wrap(sizeof(t_point *) * map->height);
i = -1;
while (++i < map->height)
{
map->points[i] = malloc_wrap(sizeof(t_point) * map->width);
j = -1;
while (++j < map->width)
{
calc_coordinate(data, map, i, j);
if (map->color_flag)
map->points[i][j].color.num = map->color[i][j];
else
set_color(data, map, i, j);
}
}
size_adjust(data, map);
shift_center(data, map);
}
static void calc_coordinate(t_data *data, t_map *map, int i, int j)
{
double pos[3];
pos[0] = j;
pos[1] = i;
pos[2] = map->data[i][j];
rotate_z(pos, data->rotate_z);
rotate_y(pos, data->rotate_y);
rotate_x(pos, data->rotate_x);
map->points[i][j].x = pos[0] * data->zoom;
map->points[i][j].y = pos[1] * data->zoom;
}
static void size_adjust(t_data *data, t_map *map)
{
int i;
int j;
map->x_max = -INF;
map->x_min = INF;
map->y_max = -INF;
map->y_min = INF;
i = -1;
while (++i < map->height)
{
j = -1;
while (++j < map->width)
{
map->x_max = fdf_max_d(map->x_max, map->points[i][j].x);
map->x_min = fdf_min_d(map->x_min, map->points[i][j].x);
map->y_max = fdf_max_d(map->y_max, map->points[i][j].y);
map->y_min = fdf_min_d(map->y_min, map->points[i][j].y);
}
}
update_zoom(data, map);
update_size(data, map);
}
static void update_zoom(t_data *data, t_map *map)
{
if (map->x_max - map->x_min == 0 && map->y_max - map->y_min == 0)
data->zoom = 1;
else if (map->x_max - map->x_min == 0)
data->zoom = WIN_HEIGHT * 0.8 / (map->y_max - map->y_min);
else if (map->y_max - map->y_min == 0)
data->zoom = WIN_WIDTH * 0.8 / (map->x_max - map->x_min);
else
data->zoom = fdf_min_d(WIN_WIDTH * 0.8 / (map->x_max - map->x_min),
WIN_HEIGHT * 0.8 / (map->y_max - map->y_min));
}
static void update_size(t_data *data, t_map *map)
{
int i;
int j;
i = -1;
while (++i < map->height)
{
j = -1;
while (++j < map->width)
{
map->points[i][j].x = (map->points[i][j].x - data->shift_x)
* data->zoom + data->shift_x;
map->points[i][j].y = (map->points[i][j].y - data->shift_y)
* data->zoom + data->shift_y;
}
}
map->x_max = (map->x_max - data->shift_x) * data->zoom + data->shift_x;
map->x_min = (map->x_min - data->shift_x) * data->zoom + data->shift_x;
map->y_max = (map->y_max - data->shift_y) * data->zoom + data->shift_y;
map->y_min = (map->y_min - data->shift_y) * data->zoom + data->shift_y;
}