-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotations.c
82 lines (73 loc) · 2.2 KB
/
rotations.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotations.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jesuserr <jesuserr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/07 15:22:46 by jesuserr #+# #+# */
/* Updated: 2023/11/15 09:13:56 by jesuserr ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
/* All rotations are clockwise */
void rotate(t_fdf *fdf)
{
rotate_x(fdf, fdf->angle_x);
rotate_y(fdf, fdf->angle_y);
rotate_z(fdf, fdf->angle_z);
}
void unrotate(t_fdf *fdf)
{
rotate_z(fdf, -fdf->angle_z);
rotate_y(fdf, -fdf->angle_y);
rotate_x(fdf, -fdf->angle_x);
}
void rotate_x(t_fdf *fdf, float angle)
{
int i;
float copy_y;
float copy_z;
i = 0;
angle = angle * PI / 180;
while (i < (fdf->x_elem * fdf->y_elem))
{
copy_y = fdf->map[i].y;
copy_z = fdf->map[i].z;
fdf->map[i].y = (copy_y * cos(angle)) - (copy_z * sin(angle));
fdf->map[i].z = (copy_y * sin(angle)) + (copy_z * cos(angle));
i++;
}
}
void rotate_y(t_fdf *fdf, float angle)
{
int i;
float copy_x;
float copy_z;
i = 0;
angle = angle * PI / 180;
while (i < (fdf->x_elem * fdf->y_elem))
{
copy_x = fdf->map[i].x;
copy_z = fdf->map[i].z;
fdf->map[i].x = (copy_x * cos(angle)) - (copy_z * sin(angle));
fdf->map[i].z = (copy_z * cos(angle)) + (copy_x * sin(angle));
i++;
}
}
void rotate_z(t_fdf *fdf, float angle)
{
int i;
float copy_x;
float copy_y;
i = 0;
angle = angle * PI / 180;
while (i < (fdf->x_elem * fdf->y_elem))
{
copy_x = fdf->map[i].x;
copy_y = fdf->map[i].y;
fdf->map[i].x = (copy_x * cos(angle)) - (copy_y * sin(angle));
fdf->map[i].y = (copy_x * sin(angle)) + (copy_y * cos(angle));
i++;
}
}