-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtransform.h
49 lines (37 loc) · 969 Bytes
/
transform.h
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
#ifndef TRANSFORM_H
#define TRANSFORM_H
/* Tranforms.h -
* a basic class for trasnform
*/
#include <glm/vec3.hpp>
#include <glm/gtc/quaternion.hpp>
using namespace glm;
struct Transform{
vec3 pos; // aka "translation"
quat ori; // aka "rotation"
float scale; // note: Unity uses anisotropic scaling instead (a vec3 for scale)
// (which makes transofrms not closed to combination)
void setIde(){
pos = vec3(0,0,0);
ori = quat(1,0,0,0);
scale = 1;
}
vec3 forward() const {
//return
// quat::rotate(ori, vec3(0,0,1) );
quat tmp = (ori * quat(0, 0,1,0) * conjugate(ori));
return vec3( tmp.x, tmp.y, tmp.z );
}
void setModelMatrix() const;
/*TODO: very good exercises:
* methods for:
* cumulate, invert, transform points/vectors, interpolate (mix) */
Transform inverse() const {
Transform res;
res.scale = 1.0f/scale;
res.ori = glm::inverse( ori );
res.pos = res.ori * -pos;
return res;
}
};
#endif // TRANSFORM_H