-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate.c
65 lines (60 loc) · 2.18 KB
/
translate.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* translate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gphilips <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/22 16:06:47 by gphilips #+# #+# */
/* Updated: 2017/12/22 16:06:49 by gphilips ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtv1.h"
static void repere(t_env *e)
{
e->n = vec_sub(&e->cam.dir, &e->cam.pos);
normalize(&e->n);
e->right = vec_cross(&e->n, &(t_vec){0.0, 1.0, 0.0});
normalize(&e->right);
e->up = vec_cross(&e->right, &e->n);
normalize(&e->up);
}
static void translate_pos(int key, t_vec *pos, t_env *e)
{
t_vec tmp;
tmp = *pos;
if (key == KEY_LEFT)
*pos = (t_vec){tmp.x + e->right.x * 10.0,
tmp.y + e->right.y * 10.0, tmp.z + e->right.z * 10.0};
else if (key == KEY_RIGHT)
*pos = (t_vec){tmp.x - e->right.x * 10.0, tmp.y
- e->right.y * 10.0, tmp.z - e->right.z * 10.0};
else if (key == KEY_DOWN)
*pos = (t_vec){tmp.x + e->up.x * 10.0,
tmp.y + e->up.y * 10.0, tmp.z + e->up.z * 10.0};
else if (key == KEY_UP)
*pos = (t_vec){tmp.x - e->up.x * 10.0,
tmp.y - e->up.y * 10.0, tmp.z - e->up.z * 10.0};
else if (key == KEY_P)
*pos = (t_vec){tmp.x + e->n.x * 10.0,
tmp.y + e->n.y * 10.0, tmp.z + e->n.z * 10.0};
else if (key == KEY_L)
*pos = (t_vec){tmp.x - e->n.x * 10.0, tmp.y -
e->n.y * 10.0, tmp.z - e->n.z * 10.0};
}
void translate(int key, t_env *e)
{
repere(e);
if (e->is_obj_selected == 1)
translate_pos(key, &e->hit_obj->pos, e);
else
{
translate_pos(key, &e->cam.pos, e);
translate_pos(key, &e->cam.dir, e);
}
if (key == KEY_R)
{
e->is_obj_selected = 0;
e->hit_obj = NULL;
}
}