-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_matrix_transform.c
95 lines (86 loc) · 2.44 KB
/
ft_matrix_transform.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_matrix_transform.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: istalevs <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/26 22:32:22 by istalevs #+# #+# */
/* Updated: 2018/04/27 22:00:15 by istalevs ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
#include <math.h>
void restore(t_mlx *mlx)
{
int x;
int y;
t_vector *p1;
t_vector *p2;
y = 0;
while (y < mlx->info->y_max)
{
x = 0;
while (x < mlx->info->x_max)
{
p1 = mlx->vect[x + y * mlx->info->x_max];
p2 = mlx->vect[x + y * mlx->info->x_max]->save;
p1->x = p2->x;
p1->y = p2->y;
p1->z = p2->z;
x++;
}
y++;
}
}
void move(t_mlx *mlx, t_vector *vector)
{
if (!mlx || !vector)
return ;
vector->x += mlx->map->matrix->tx;
vector->y += mlx->map->matrix->ty;
vector->z += mlx->map->matrix->tz;
}
void scale(t_mlx *mlx, t_vector *vector)
{
if (!mlx || !vector)
return ;
vector->x *= mlx->map->scale;
vector->y *= mlx->map->scale;
vector->z *= mlx->map->scale * mlx->map->matrix->dz;
}
void rotation(t_mlx *mlx, t_vector *v)
{
t_vector t;
if (!mlx || !v)
return ;
t.x = v->x;
t.y = v->y;
t.z = v->z;
t.x = cos(mlx->map->matrix->ry) * v->x + sin(mlx->map->matrix->ry) * v->z;
t.z = -sin(mlx->map->matrix->ry) * v->x + cos(mlx->map->matrix->ry) * v->z;
t.y = cos(mlx->map->matrix->rx) * v->y - sin(mlx->map->matrix->rx) * t.z;
t.z = sin(mlx->map->matrix->rx) * v->y + cos(mlx->map->matrix->rx) * t.z;
v->x = t.x;
v->y = t.y;
v->z = t.z;
}
void sf_matrix(t_mlx *mlx)
{
int x;
int y;
y = 0;
bzero(mlx->img_ptr->ptr, mlx->img_ptr->size_line * mlx->map->height);
while (y < mlx->info->y_max)
{
x = 0;
while (x < mlx->info->x_max)
{
scale(mlx, mlx->vect[x + y * mlx->info->x_max]);
rotation(mlx, mlx->vect[x + y * mlx->info->x_max]);
move(mlx, mlx->vect[x + y * mlx->info->x_max]);
x++;
}
y++;
}
}