-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transform.h
38 lines (32 loc) · 911 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
#pragma once
#include <vector>
#include "Vec3.h"
#include "Orientation.h"
#include "Mesh.h"
using namespace std;
class Transform {
public:
Transform(Vec3f translation={0, 0, 0}, Orientation rotation={0, 0, 0}, float scale=1) {
m_translation = translation;
m_rotation = rotation;
m_scale = scale;
}
/*
* Resolves transforms in order : translation, orientation, scale
*/
void apply_transform(Vec3f &v) {
v += m_translation;
m_rotation.apply_rotations(v);
v = m_scale * v;
}
void apply_transform(Mesh &m) {
for (Vertex &v : m.m_vertices) {
this->apply_transform(v.m_point);
}
m.compute_aabb();
}
protected:
Vec3f m_translation;
Orientation m_rotation;
float m_scale;
};