-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathEigen.cpp
More file actions
35 lines (28 loc) · 832 Bytes
/
MathEigen.cpp
File metadata and controls
35 lines (28 loc) · 832 Bytes
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
#include "MathEigen.h"
Eigen::Quaternionf MathEigen::EulerToQuaternion(const Vector3f& eulerAngles)
{
return AngleAxisf(eulerAngles.z(), Vector3f::UnitZ()) *
AngleAxisf(eulerAngles.y(), Vector3f::UnitY()) *
AngleAxisf(eulerAngles.x(), Vector3f::UnitX());
}
Eigen::Matrix4f MathEigen::QuaternionToMatrix4f(const Quaternionf& q)
{
Eigen::Matrix3f rot3 = q.toRotationMatrix();
Matrix4f rot4 = Matrix4f::Identity();
for (size_t x = 0; x < 3; x++)
{
for (size_t y = 0; y < 3; y++)
{
rot4.coeffRef(x, y) = rot3.coeffRef(x, y);
}
}
return rot4;
}
Eigen::Matrix4f MathEigen::TranslationMatrix4f(const Vector3f& translation)
{
Matrix4f result = Matrix4f::Identity();
result.coeffRef(0, 3) = translation.x();
result.coeffRef(1, 3) = translation.y();
result.coeffRef(2, 3) = translation.z();
return result;
}