-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.c
executable file
·104 lines (98 loc) · 4.15 KB
/
camera.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
102
103
104
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* camera.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/28 15:12:58 by roduquen #+# #+# */
/* Updated: 2019/07/15 21:14:33 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf.h"
#include "libft.h"
static void camera_carry_event_2(t_wolf *data, t_vec2d tmp)
{
tmp = vec2d_rotate(data->camera.direction, to_radian(90.0));
if (data->camera.key & CAMERA_RIGHT)
{
if (!ft_memchr(WALLS, data->board[(int)(data->camera.position.x - tmp.x
* data->camera.move_speed)][(int)data->camera.position.y]
, sizeof(WALLS)))
data->camera.position.x -= tmp.x * data->camera.move_speed;
if (!ft_memchr(WALLS, data->board[(int)(data->camera.position.x)]
[(int)(data->camera.position.y - tmp.y * data->camera.move_speed)]
, sizeof(WALLS)))
data->camera.position.y -= tmp.y * data->camera.move_speed;
}
if (data->camera.key & CAMERA_LEFT)
{
if (!ft_memchr(WALLS, data->board[(int)(data->camera.position.x + tmp.x
* data->camera.move_speed)][(int)data->camera.position.y]
, sizeof(WALLS)))
data->camera.position.x += tmp.x * data->camera.move_speed;
if (!ft_memchr(WALLS, data->board[(int)(data->camera.position.x)]
[(int)(data->camera.position.y + tmp.y * data->camera.move_speed)]
, sizeof(WALLS)))
data->camera.position.y += tmp.y * data->camera.move_speed;
}
}
void camera_carry_event(t_wolf *data, t_vec2d tmp)
{
if (data->camera.key & CAMERA_FRONT)
{
if (!ft_memchr(WALLS, data->board[(int)(data->camera.position.x
+ data->camera.direction.x
* data->camera.move_speed)][(int)data->camera.position.y]
, sizeof(WALLS)))
data->camera.position.x += tmp.x * data->camera.move_speed;
if (!ft_memchr(WALLS, data->board[(int)(data->camera.position.x)]
[(int)(data->camera.position.y + data->camera.direction.y
* data->camera.move_speed)], sizeof(WALLS)))
data->camera.position.y += tmp.y * data->camera.move_speed;
}
if (data->camera.key & CAMERA_BACK)
{
if (!ft_memchr(WALLS, data->board[(int)(data->camera.position.x
- data->camera.direction.x
* data->camera.move_speed)][(int)data->camera.position.y]
, sizeof(WALLS)))
data->camera.position.x -= tmp.x * data->camera.move_speed;
if (!ft_memchr(WALLS, data->board[(int)(data->camera.position.x)]
[(int)(data->camera.position.y - data->camera.direction.y
* data->camera.move_speed)], sizeof(WALLS)))
data->camera.position.y -= tmp.y * data->camera.move_speed;
}
camera_carry_event_2(data, tmp);
}
void camera_downkey_event(t_wolf *data)
{
if (data->event.key.keysym.sym == SDLK_d)
data->camera.key |= CAMERA_RIGHT;
else if (data->event.key.keysym.sym == SDLK_a)
data->camera.key |= CAMERA_LEFT;
else if (data->event.key.keysym.sym == SDLK_w)
data->camera.key |= CAMERA_FRONT;
else if (data->event.key.keysym.sym == SDLK_s)
data->camera.key |= CAMERA_BACK;
}
void camera_upkey_event(t_wolf *data)
{
if (data->event.key.keysym.sym == SDLK_d)
data->camera.key &= ~CAMERA_RIGHT;
else if (data->event.key.keysym.sym == SDLK_a)
data->camera.key &= ~CAMERA_LEFT;
else if (data->event.key.keysym.sym == SDLK_w)
data->camera.key &= ~CAMERA_FRONT;
else if (data->event.key.keysym.sym == SDLK_s)
data->camera.key &= ~CAMERA_BACK;
}
void camera_mouse_event(t_wolf *data)
{
data->camera.direction = vec2d_rotate(data->camera.direction
, to_radian(360 - data->camera.angle_speed
* data->event.motion.xrel));
data->camera.plane = vec2d_rotate(data->camera.plane
, to_radian(360 - data->camera.angle_speed
* data->event.motion.xrel));
}