diff options
author | vimene <vincent.menegaux@gmail.com> | 2024-12-31 03:40:14 +0100 |
---|---|---|
committer | vimene <vincent.menegaux@gmail.com> | 2024-12-31 03:40:14 +0100 |
commit | cc6fb8c33637566a7b116d46440e6063f016deea (patch) | |
tree | 5cc83f84525507994add57df7dd974e6611d675a /src/math/tform.h | |
parent | 6b765a85cf81bf4b7162e4c9280dd4054581c611 (diff) | |
download | engine-cc6fb8c33637566a7b116d46440e6063f016deea.tar.gz |
various improvements
- added quaternions and rewrote all rotations to use them
- added transforms to put all object transforms in a single place
- added Wavefront .obj file parser
- removed frame buffer's abstract class
- improved vectors, matrices, triangles, vertices and vertices data by putting all code in header file
- added vector's operations
- changed from NULL to nullptr
- miscellaneous improvements
Diffstat (limited to 'src/math/tform.h')
-rw-r--r-- | src/math/tform.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/math/tform.h b/src/math/tform.h new file mode 100644 index 0000000..2d61494 --- /dev/null +++ b/src/math/tform.h @@ -0,0 +1,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 |