-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojection.c
108 lines (100 loc) · 3.6 KB
/
projection.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* projection.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jjacobso <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/20 18:40:04 by jjacobso #+# #+# */
/* Updated: 2019/05/20 20:55:41 by jjacobso ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static void lamp_project(t_view *view)
{
LAMP.projection.x = LAMP.dot.x * PROPS.fscale;
LAMP.projection.y = LAMP.dot.y * PROPS.fscale;
LAMP.projection.z = LAMP.dot.z * ((double)PROPS.z_modifier / 100)
* PROPS.fscale;
}
static void conic_project(t_view *view)
{
int i;
int j;
double r;
double y;
MAP.center = dot_center_coord(view);
y = -((MAP.max_y * K + MAP.center.y) * PROPS.fscale
* (1 + (double)(PROPS.perspective_modifier) / 100));
(IO.print_loading) ? ft_printf(GRN"\nMap projecting:\n"RESET) : 0;
i = -1;
while (++i < MAP.max_y)
{
j = -1;
while (++j < MAP.max_x)
{
PROJECTION(i, j).x = (DOT(i, j).x - MAP.center.x) * PROPS.fscale;
PROJECTION(i, j).y = (DOT(i, j).y - MAP.center.y) * PROPS.fscale;
PROJECTION(i, j).z = DOT(i, j).z * ((double)PROPS.z_modifier / 100)
* PROPS.fscale;
(j == 0) ? r = dist3d(PROJECTION(i, 0), C(0, y, 0)) : 0;
PROJECTION(i, j).w = DOT(i, j).w;
apply_conic(&PROJECTION(i, j), PROJECTION(i, j), r, y);
}
print_loading(MAP.max_y, i + 1, IO.print_loading);
}
}
static void iso_project(t_view *view)
{
int i;
int j;
double y;
double z_mod;
z_mod = (double)PROPS.z_modifier / 100;
MAP.center = dot_center_coord(view);
y = -(MAP.max_y * K * PROPS.fscale)
* (1 + (double)(PROPS.perspective_modifier) / 100);
i = -1;
(IO.print_loading) ? ft_printf(GRN"\nMap projecting:\n"RESET) : 0;
while (++i < MAP.max_y)
{
j = -1;
while (++j < MAP.max_x)
{
PROJECTION(i, j).x = (DOT(i, j).x - MAP.center.x) * PROPS.fscale;
PROJECTION(i, j).y = (DOT(i, j).y - MAP.center.y) * PROPS.fscale;
PROJECTION(i, j).z = DOT(i, j).z * z_mod * PROPS.fscale;
PROJECTION(i, j).w = DOT(i, j).w;
if (OPTIONS.perspective)
PROJECTION(i, j).x *= ABS(ft_frange(PROJECTION(i, j).y, y) / y);
}
print_loading(MAP.max_y, i + 1, IO.print_loading);
}
}
void project(t_view *view)
{
int i;
int j;
double h;
PROPS.projection_type == CONIC ? conic_project(view) : iso_project(view);
lamp_project(view);
h = get_distance_to_cam(view);
coord_reset(&MAP.center);
(IO.print_loading) ? ft_printf(GRN"\nMap rendering:\n"RESET) : 0;
i = -1;
while (++i < MAP.max_y)
{
j = -1;
while (++j < MAP.max_x)
{
rotate_around(&PROJECTION(i, j), PROPS.beta, (double[3]){1, 0, 0});
rotate_around(&PROJECTION(i, j), PROPS.alpha, (double[3]){0, 1, 0});
z_perspective(&PROJECTION(i, j), h);
MAP.center.x += PROJECTION(i, j).x / (MAP.max_y * MAP.max_x);
MAP.center.y += PROJECTION(i, j).y / (MAP.max_y * MAP.max_x);
}
print_loading(MAP.max_y, i + 1, IO.print_loading);
}
rotate_around(&LAMP.projection, PROPS.beta, (double[3]){1, 0, 0});
rotate_around(&LAMP.projection, PROPS.alpha, (double[3]){0, 1, 0});
}