|
3 | 3 | /* ::: :::::::: */ |
4 | 4 | /* Parse_camera.c :+: :+: :+: */ |
5 | 5 | /* +:+ +:+ +:+ */ |
6 | | -/* By: cnatanae <cnatanae@student.42sp.org.br> +#+ +:+ +#+ */ |
| 6 | +/* By: tmalheir <tmalheir@student.42.fr> +#+ +:+ +#+ */ |
7 | 7 | /* +#+#+#+#+#+ +#+ */ |
8 | 8 | /* Created: 2025/01/31 10:06:00 by tmalheir #+# #+# */ |
9 | | -/* Updated: 2025/02/03 12:00:19 by cnatanae ### ########.fr */ |
| 9 | +/* Updated: 2025/02/04 15:19:24 by tmalheir ### ########.fr */ |
10 | 10 | /* */ |
11 | 11 | /* ************************************************************************** */ |
12 | 12 |
|
13 | 13 | #include "Parser.h" |
| 14 | +#include "Canvas.h" |
| 15 | +#include "Scenes.h" |
| 16 | +#include "math.h" |
14 | 17 |
|
15 | | -// static bool dir_is_norm(double *dir) |
16 | | -// { |
17 | | -// if (equal(mag(dir))) |
18 | | - |
19 | | -// } |
| 18 | +static bool check_fov(char *str) |
| 19 | +{ |
| 20 | + if (!is_double(str) || (ft_atod(str) < 0 || ft_atod(str) > 180)) |
| 21 | + return (false); |
| 22 | + return (true); |
| 23 | +} |
20 | 24 |
|
21 | 25 | static bool dir_in_range(char *str) |
22 | 26 | { |
@@ -48,24 +52,24 @@ static bool parse_dir(char *str) |
48 | 52 |
|
49 | 53 | bool parse_camera(char *line, t_world *world) |
50 | 54 | { |
51 | | - double *view_pt; |
52 | | - double *dir; |
53 | | - char **info; |
| 55 | + double *from; |
| 56 | + double *to; |
| 57 | + char **info; |
54 | 58 |
|
55 | | - info = ft_split(line, ' '); |
56 | | - if (!check_count(info, 4) || !parse_pos(info[1]) || !parse_dir(info[2])); |
57 | | - return (true_or_false(info, false)); |
58 | | - view_pt = allocate(sizeof(double) * 3); |
59 | | - view_pt = pos_to_double(info[1]); |
60 | | - world->scene.camera_pos = point(view_pt[X], view_pt[Y], view_pt[Z]); |
61 | | - world->scene.has_camera += world->scene.has_camera + 1; |
| 59 | + world->scene.has_camera += 1; |
62 | 60 | if (world->scene.has_camera > 1) |
63 | | - { |
64 | | - warning("Error\n", "Only one camera allowed", ""); |
| 61 | + error("Error\n", "Only one camera allowed", "", 1); |
| 62 | + info = ft_split(line, ' '); |
| 63 | + if (!check_count(info, 4) || !parse_pos(info[1]) || !parse_dir(info[2]) |
| 64 | + || !check_fov(info[3])) |
65 | 65 | return (true_or_false(info, false)); |
66 | | - } |
67 | | - dir = allocate(sizeof(double) * 3); |
68 | | - dir = pos_to_double(info[2]); |
69 | | - world->scene.camera_dir = vector(dir[X], dir[Y], dir[Z]); |
| 66 | + from = allocate(sizeof(double) * 3); |
| 67 | + from = pos_to_double(info[1]); |
| 68 | + world->scene.camera_from = point(from[X], from[Y], from[Z]); |
| 69 | + to = allocate(sizeof(double) * 3); |
| 70 | + to = pos_to_double(info[2]); |
| 71 | + world->scene.camera_to = vector(to[X], to[Y], to[Z]); |
| 72 | + world->camera = camera(WIDHT, HEIGHT, (ft_atod(info[3])) * PI / 180); |
| 73 | + world->camera.transform = view_transform(from, to, world->camera.up); |
70 | 74 | return (true_or_false(info, true)); |
71 | 75 | } |
0 commit comments