-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_tranform.c
executable file
·101 lines (94 loc) · 3.48 KB
/
ft_tranform.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tranform.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: shillebr <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/20 09:02:17 by shillebr #+# #+# */
/* Updated: 2018/07/20 09:02:50 by shillebr ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int ft_limmult(double n)
{
if (n < 0)
return (-1);
else if (n > 0)
return (1);
else
return (0);
}
void ft_vect_calc(t_info *s, t_verts *v, int *x, int *y)
{
int l;
int m;
int n;
l = ((v->v2)->w).x - ((v->v1)->w).x;
m = ((v->v2)->w).y - ((v->v1)->w).y;
n = -((v->v2)->w).z + ((v->v1)->w).z;
*x = (s->size_x / 2) - ((-((v->v1)->w).z / n) * l - ((v->v1)->w).x);
*y = (s->size_y / 2) - ((-((v->v1)->w).z / n) * m - ((v->v1)->w).y);
}
void ft_limit(t_info *s, t_verts *v, int *x, int *y)
{
ft_vect_calc(s, v, x, y);
if (ft_limmult(((v->v1)->w).x) == 0 && ft_limmult(((v->v1)->w).y) != 0)
{
*x = (s->size_x / 2);
*y = ft_limmult(((v->v1)->w).y) * (s->size_y / 2);
*y = *y + (((((v->v1)->w).y / -((v->v1)->w).z) + *y) / 2);
}
else if (ft_limmult(((v->v1)->w).y) == 0 && ft_limmult(((v->v1)->w).x) != 0)
{
*x = ft_limmult(((v->v1)->w).x) * (s->size_x / 2);
*x = *x + (((((v->v1)->w).x / -((v->v1)->w).z) + *x) / 2);
*y = (s->size_y / 2);
}
else if (ft_limmult(((v->v1)->w).y) != 0 && ft_limmult(((v->v1)->w).x) != 0)
{
*x = ft_limmult(((v->v1)->w).x) * (s->size_x / 2);
*x = *x + ((((v->v1)->w).x / -((v->v1)->w).z + s->size_x / 2) + *x) / 2;
*y = ft_limmult(((v->v1)->w).y) * (s->size_y / 2);
*y = *y + ((((v->v1)->w).y / -((v->v1)->w).z + s->size_y / 2) + *y) / 2;
}
}
void ft_draw_limit(t_info *shp, t_verts *v)
{
if (((v->v1)->w).z < 0 && ((v->v2)->w).z >= 0)
{
(shp->pnt)->x1 = ((v->v1)->scrn).x + (shp->size_x / 2);
(shp->pnt)->y1 = ((v->v1)->scrn).y + (shp->size_y / 2);
ft_limit(shp, v, &((shp->pnt)->x2), &((shp->pnt)->y2));
}
else if (((v->v1)->w).z >= 0 && ((v->v2)->w).z < 0)
{
(shp->pnt)->x2 = ((v->v2)->scrn).x + (shp->size_x / 2);
(shp->pnt)->y2 = ((v->v2)->scrn).y + (shp->size_y / 2);
ft_limit(shp, v, &((shp->pnt)->x1), &((shp->pnt)->y1));
}
else if (((v->v1)->w).z >= 0 && ((v->v2)->w).z >= 0)
return ;
else
{
(shp->pnt)->x1 = ((v->v1)->scrn).x + (shp->size_x / 2);
(shp->pnt)->y1 = ((v->v1)->scrn).y + (shp->size_y / 2);
(shp->pnt)->x2 = ((v->v2)->scrn).x + (shp->size_x / 2);
(shp->pnt)->y2 = ((v->v2)->scrn).y + (shp->size_y / 2);
}
ft_drawline(shp, shp->size_x, shp->size_x);
}
void ft_transform(t_info *shp, t_verts *v)
{
ft_worldcoords(v->v1, shp);
ft_worldcoords(v->v2, shp);
if (ft_project(v->v2) == 0 && 0 == ft_project(v->v1))
{
(shp->pnt)->x1 = ((v->v1)->scrn).x + (shp->size_x / 2);
(shp->pnt)->y1 = ((v->v1)->scrn).y + (shp->size_y / 2);
(shp->pnt)->x2 = ((v->v2)->scrn).x + (shp->size_x / 2);
(shp->pnt)->y2 = ((v->v2)->scrn).y + (shp->size_y / 2);
ft_draw_limit(shp, v);
ft_drawline(shp, shp->size_x, shp->size_x);
}
}