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/tform.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/math/tform.h') diff --git a/src/math/tform.h b/src/math/tform.h index 2d61494..2a654b8 100644 --- a/src/math/tform.h +++ b/src/math/tform.h @@ -1,6 +1,7 @@ #ifndef MATH_TFORM_H #define MATH_TFORM_H +#include #include "math/vector.h" #include "math/mat4.h" #include "math/quat.h" @@ -28,6 +29,20 @@ class Transform { 0.f, 0.f, 0.f, 1.f, }; } + + constexpr Matrix4 to_inverse_mat4() const & { + std::array m{{ + (2.f * (rot.w * rot.w + rot.x * rot.x) - 1.f) / scale.x, (2.f * (rot.x * rot.y + rot.w * rot.z) ) / scale.x, (2.f * (rot.x * rot.z - rot.w * rot.y) ) / 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.y, (2.f * (rot.y * rot.z + rot.w * rot.x) ) / scale.y, + (2.f * (rot.x * rot.z + rot.w * rot.y) ) / scale.z, (2.f * (rot.y * rot.z - rot.w * rot.x) ) / scale.z, (2.f * (rot.w * rot.w + rot.z * rot.z) - 1.f) / scale.z, + }}; + return { + m[0], m[1], m[2], - (m[0] * loc.x + m[1] * loc.y + m[2] * loc.z), + m[3], m[4], m[5], - (m[3] * loc.x + m[4] * loc.y + m[5] * loc.z), + m[6], m[7], m[8], - (m[6] * loc.x + m[7] * loc.y + m[8] * loc.z), + 0.f, 0.f, 0.f, 1.0f, + }; + } }; } -- cgit v1.2.3