-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotation.cpp
32 lines (26 loc) · 970 Bytes
/
Rotation.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
#define _USE_MATH_DEFINES
#include "Rotation.h"
#include "MatrixFactory.h"
#include <cmath>
Rotation & Rotation::rotateByEuler(const Vector3f & euler) {
this->matrix = MatrixFactory::rotation(euler[2], MatrixFactory::Z)
* MatrixFactory::rotation(euler[1], MatrixFactory::Y)
* MatrixFactory::rotation(euler[0], MatrixFactory::X)
* this->matrix;
this->invMatrix *= MatrixFactory::rotation(-euler[0], MatrixFactory::X)
* MatrixFactory::rotation(-euler[1], MatrixFactory::Y)
* MatrixFactory::rotation(-euler[2], MatrixFactory::Z);
return *this;
}
const Matrix4f & Rotation::getMatrix() const {
return this->matrix;
}
const Matrix4f & Rotation::getInvMatrix() const {
return this->invMatrix;
}
const Vector3f Rotation::transform(const Vector3f & vector) const {
return (this->getMatrix() * Vector4f(vector, 1)).xyz();
}
const Vector3f Rotation::invTransform(const Vector3f & vector) const {
return (this->getInvMatrix() * Vector4f(vector, 1)).xyz();
}