diff options
author | vimene <vincent.menegaux@gmail.com> | 2025-01-02 13:25:14 +0100 |
---|---|---|
committer | vimene <vincent.menegaux@gmail.com> | 2025-01-02 13:25:14 +0100 |
commit | 26b4b82a7be2c029491f3009b66b3cbf8db5d93c (patch) | |
tree | ddc247a0600b5933185677212f158ebea5a87530 /src/math/quat.h | |
parent | 9fdb5881d46f5d80626f961f9c9f133cc25dab70 (diff) | |
download | engine-26b4b82a7be2c029491f3009b66b3cbf8db5d93c.tar.gz |
various improvements
- cleaned up the computation of the camera's matrix
- changed VertexData to being a struct which transmit data between the "vertex shader" and the "fragment shader"
- started working on keyboard and mouse controls
- added fov (field of view)
- changed quaternion to euler angles conversion, from zyx to zxy
- fixed computations of z coordinates in triangle rendering
- improved naming in the triangle rasterizer
Diffstat (limited to 'src/math/quat.h')
-rw-r--r-- | src/math/quat.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/math/quat.h b/src/math/quat.h index 763253b..271070a 100644 --- a/src/math/quat.h +++ b/src/math/quat.h @@ -14,18 +14,22 @@ struct Quaternion { return {1.f, 0.f, 0.f, 0.f}; } - static constexpr Quaternion euler_zyx(float a, float b, float c) { - float ca = std::cos(a / 2.f), sa = std::sin(a / 2.f), - cb = std::cos(b / 2.f), sb = std::sin(b / 2.f), - cc = std::cos(c / 2.f), sc = std::sin(c / 2.f); + static constexpr Quaternion euler_zxy(float rx, float ry, float rz) { + float ca = std::cos(rx / 2.f), sa = std::sin(rx / 2.f), + cb = std::cos(ry / 2.f), sb = std::sin(ry / 2.f), + cc = std::cos(rz / 2.f), sc = std::sin(rz / 2.f); return { - ca * cb * cc - sa * sb * sc, + ca * cb * cc + sa * sb * sc, sa * cb * cc + ca * sb * sc, ca * sb * cc - sa * cb * sc, - ca * cb * sc + sa * sb * cc, + ca * cb * sc - sa * sb * cc, }; } + static constexpr Quaternion rot_y(float a) { + return {std::cos(a / 2.f), 0.f, std::sin(a / 2.f), 0.f}; + } + float w, x, y, z; constexpr Quaternion() {} |