-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.c
95 lines (87 loc) · 2.75 KB
/
draw.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlechapt <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/01/11 15:38:24 by rlechapt #+# #+# */
/* Updated: 2015/01/19 22:50:26 by rlechapt ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void draw_vertical(t_env *e, int i)
{
e->cumul = e->dy / 2;
i = 1;
while (i <= e->dy)
{
e->y += e->yinc;
e->cumul += e->dx;
if (e->cumul >= e->dy)
{
e->cumul -= e->dy;
e->x += e->xinc;
}
// mlx_pixel_put(e->mlx, e->win, e->x, e->y, 0xFFFFFF);
draw_image(e, e->x, e->y);
i++;
}
}
void draw_horizontal(t_env *e, int i)
{
e->cumul = e->dx / 2;
i = 1;
while (i <= e->dx)
{
e->x += e->xinc;
e->cumul += e->dy;
if (e->cumul >= e->dx)
{
e->cumul -= e->dx;
e->y += e->yinc;
}
// mlx_pixel_put(e->mlx, e->win, e->x, e->y, 0xFFFFFF);
draw_image(e, e->x, e->y);
i++;
}
}
void draw_line(t_env *e, int xi,int yi,int xf,int yf)
{
int i;
e->x = xi;
e->y = yi;
e->dx = xf - xi;
e->dy = yf - yi;
e->xinc = (e->dx > 0) ? 1 : -1;
e->yinc = (e->dy > 0) ? 1 : -1;
if (e->dx < 0)
e->dx = -e->dx;
if (e->dy < 0)
e->dy = -e->dy;
mlx_pixel_put(e->mlx, e->win, e->x, e->y, 0xFFFFFF);
if (e->dx > e->dy)
draw_horizontal(e, i);
else
draw_vertical(e, i);
}
void vertical_projection(t_env *e, int i, int j)
{
e->x1 = ((e->cste * e->mp[i]->x) - (e->cste * e->mp[i]->y)) + e->moveX;
e->y1 = ((-e->mp[i]->z + ((e->cste/2) * e->mp[i]->x) +
((e->cste/2) * e->mp[i]->y))) + e->moveY;
e->x2 = ((e->cste * e->mp[i]->x) - (e->cste * e->mp[j]->y)) + e->moveX;
e->y2 = ((-e->mp[j]->z + ((e->cste/2) * e->mp[i]->x) +
((e->cste/2) * e->mp[j]->y))) + e->moveY;
draw_line(e, e->x1, e->y1, e->x2, e->y2);
}
void horizontal_projection(t_env *e, int i, int j)
{
e->x1 = ((e->cste * e->mp[i]->x) - (e->cste * e->mp[i]->y)) + e->moveX;
e->y1 = ((-e->mp[i]->z + ((e->cste/2) * e->mp[i]->x) +
((e->cste/2) * e->mp[i]->y))) + e->moveY;
e->x2 = ((e->cste * e->mp[j]->x) - (e->cste * e->mp[i]->y)) + e->moveX;
e->y2 = ((-e->mp[j]->z + ((e->cste/2) * e->mp[j]->x) +
((e->cste/2) * e->mp[i]->y))) + e->moveY;
draw_line(e, e->x1, e->y1, e->x2, e->y2);
}