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
|
#ifndef MATH_TFORM_H
#define MATH_TFORM_H
#include "math/vector.h"
#include "math/mat4.h"
#include "math/quat.h"
namespace engine::math {
class Transform {
public:
Vector3 loc;
Quaternion rot;
Vector3 scale;
constexpr Transform(Vector3 loc, Quaternion rot, Vector3 scale) : loc{loc}, rot{rot}, scale{scale} {
}
constexpr Transform opposite() const & {
return {-loc, rot.conjugate(), 1.f / scale};
}
constexpr Matrix4 to_mat4() const & {
return {
scale.x * (2.f * (rot.w * rot.w + rot.x * rot.x) - 1.f), scale.y * (2.f * (rot.x * rot.y - rot.w * rot.z) ), scale.z * (2.f * (rot.x * rot.z + rot.w * rot.y) ), loc.x,
scale.x * (2.f * (rot.x * rot.y + rot.w * rot.z) ), scale.y * (2.f * (rot.w * rot.w + rot.y * rot.y) - 1.f), scale.z * (2.f * (rot.y * rot.z - rot.w * rot.x) ), loc.y,
scale.x * (2.f * (rot.x * rot.z - rot.w * rot.y) ), scale.y * (2.f * (rot.y * rot.z + rot.w * rot.x) ), scale.z * (2.f * (rot.w * rot.w + rot.z * rot.z) - 1.f), loc.z,
0.f, 0.f, 0.f, 1.f,
};
}
};
}
#endif // MATH_TFORM_H
|