From 26b4b82a7be2c029491f3009b66b3cbf8db5d93c Mon Sep 17 00:00:00 2001 From: vimene Date: Thu, 2 Jan 2025 13:25:14 +0100 Subject: 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 --- src/math/quat.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/math/quat.h') 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() {} -- cgit v1.2.3