-
Notifications
You must be signed in to change notification settings - Fork 1
/
transform.cpp
73 lines (60 loc) · 804 Bytes
/
transform.cpp
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
#include "transform.h"
Transform::
Transform(vec3 t, quat r, vec3 s)
: _t(t), _r(r), _s(s)
{
recalculate_world();
}
Transform::
~Transform()
{
}
mat4 Transform::
world()
{
if (_dirty) recalculate_world();
return _world;
}
vec3 Transform::
get_translation()
{
return _t;
}
void Transform::
set_translation(vec3 t)
{
_t = t;
_dirty = true;
}
quat Transform::
get_rotation()
{
return _r;
}
void Transform::
set_rotation(quat r)
{
_r = r;
_dirty = true;
}
vec3 Transform::
get_scale()
{
return _s;
}
void Transform::
set_scale(vec3 s)
{
_s = s;
_dirty = true;
}
// private
void Transform::
recalculate_world()
{
_world = mat4(1);
_world = translate(_world, _t);
_world = mat4_cast(_r) * _world;
_world = scale(_world, _s);
_dirty = false;
}