-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransform.cpp
81 lines (65 loc) · 2.53 KB
/
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
74
75
76
77
78
79
80
81
#include "Transform.h"
#include "MatrixFactory.h"
Transform & Transform::reset() {
this->matrix = Matrix4f::identity();
this->invMatrix = Matrix4f::identity();
return *this;
}
Transform & Transform::pushPre(const Transform & transform) {
this->matrix *= transform.getMatrix();
this->invMatrix = transform.getInvMatrix() * this->invMatrix;
return *this;
}
Transform & Transform::pushPost(const Transform & transform) {
this->matrix = transform.getMatrix() * this->matrix;
this->invMatrix *= transform.getInvMatrix();
return *this;
}
Transform & Transform::translatePost(const Vector3f & direction) {
this->matrix = MatrixFactory::translation(direction) * this->matrix;
this->invMatrix *= MatrixFactory::translation(Vector3f(-direction));
return *this;
}
Transform & Transform::rotatePost(const Rotation & rotation) {
this->matrix = rotation.getMatrix() * this->matrix;
this->invMatrix *= rotation.getInvMatrix();
return *this;
}
Transform & Transform::scalePost(const Vector3f & coefficient) {
this->matrix = MatrixFactory::scale(coefficient) * this->matrix;
this->invMatrix *= MatrixFactory::scale(Vector3f(1.0f / coefficient[0], 1.0f / coefficient[1], 1.0f / coefficient[2]));
return *this;
}
Transform & Transform::translatePre(const Vector3f & direction) {
this->matrix *= MatrixFactory::translation(direction);
this->invMatrix = MatrixFactory::translation(Vector3f(-direction)) * this->invMatrix;
return *this;
}
Transform & Transform::rotatePre(const Rotation & rotation) {
this->matrix *= rotation.getMatrix();
this->invMatrix = rotation.getInvMatrix() * this->invMatrix;
return *this;
}
Transform & Transform::scalePre(const Vector3f & coefficient) {
this->matrix *= MatrixFactory::scale(coefficient);
this->invMatrix = MatrixFactory::scale(Vector3f(1.0f / coefficient[0], 1.0f / coefficient[1], 1.0f / coefficient[2])) * this->invMatrix;
return *this;
}
const Matrix4f & Transform::getMatrix() const {
return this->matrix;
}
const Matrix4f & Transform::getInvMatrix() const {
return this->invMatrix;
}
const Vector3f Transform::transformPoint(const Vector3f & point) const {
return (this->matrix * Vector4f(point, 1)).xyz();
}
const Vector3f Transform::invTransformPoint(const Vector3f & point) const {
return (this->invMatrix * Vector4f(point, 1)).xyz();
}
const Vector3f Transform::transformDirection(const Vector3f & direction) const {
return (this->matrix * Vector4f(direction, 0)).xyz();
}
const Vector3f Transform::invTransformDirection(const Vector3f & direction) const {
return (this->invMatrix * Vector4f(direction, 0)).xyz();
}