-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangles.c
More file actions
63 lines (54 loc) · 2.13 KB
/
angles.c
File metadata and controls
63 lines (54 loc) · 2.13 KB
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
/* ************************************************************************** */
/* */
/* :::::::: */
/* angles.c :+: :+: */
/* +:+ */
/* By: fhignett <fhignett@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/03/12 18:36:24 by fhignett #+# #+# */
/* Updated: 2019/05/10 17:05:38 by fhignett ######## odam.nl */
/* */
/* ************************************************************************** */
#include "fdf.h"
#include <math.h>
static void x_rot(t_point *point, double angle)
{
int y;
y = point->y;
point->y = y * cos(angle) + point->z * sin(angle);
point->z = -y * sin(angle) + point->z * cos(angle);
}
static void y_rot(t_point *point, double angle)
{
int x;
x = point->x;
point->x = x * cos(angle) + point->z * sin(angle);
point->z = -x * sin(angle) + point->z * cos(angle);
}
static void z_rot(t_point *point, double angle)
{
int x;
x = point->x;
point->x = x * cos(angle) - point->y * sin(angle);
point->y = x * sin(angle) + point->y * cos(angle);
}
/*
** first: make sure that the amount of pixels inbetween is correct
** second: takes the centre of the image
** third: calculates the rotation
** fourth: puts the image in the centre of the window
*/
t_point rot_matrix(t_point pixel, t_fdf *fdf)
{
pixel.x *= fdf->cam->zoom;
pixel.y *= fdf->cam->zoom;
pixel.z *= fdf->cam->zoom + (fdf->conf->z * fdf->cam->zoom);
pixel.x -= (fdf->map->width / 2) * fdf->cam->zoom;
pixel.y -= (fdf->map->height / 2) * fdf->cam->zoom;
x_rot(&pixel, fdf->cam->xrot);
y_rot(&pixel, fdf->cam->yrot);
z_rot(&pixel, fdf->cam->zrot);
pixel.x += (WIDTH / 2) + fdf->conf->x * fdf->cam->zoom;
pixel.y += (HEIGHT / 2) + fdf->conf->y * fdf->cam->zoom;
return (pixel);
}