Use double vector types in camera view matrix calculations

This commit is contained in:
2025-04-19 02:38:29 +03:00
parent d30ff65800
commit 02c333c720
3 changed files with 44 additions and 6 deletions

View File

@@ -93,6 +93,9 @@ public:
// Calculates the inverse of the specified matrix.
static void Invert(const Double4x4& value, Double4x4& result);
// Creates a left-handed, look-at matrix.
static void LookAt(const Double3& eye, const Double3& target, const Double3& up, Double4x4& result);
// Calculates the product of two matrices.
static void Multiply(const Double4x4& left, const Double4x4& right, Double4x4& result);

View File

@@ -1001,6 +1001,37 @@ void Double4x4::Invert(const Double4x4& value, Double4x4& result)
result.M44 = +d44 * det;
}
void Double4x4::LookAt(const Double3& eye, const Double3& target, const Double3& up, Double4x4& result)
{
Double3 xaxis, yaxis, zaxis;
Double3::Subtract(target, eye, zaxis);
zaxis.Normalize();
Double3::Cross(up, zaxis, xaxis);
xaxis.Normalize();
Double3::Cross(zaxis, xaxis, yaxis);
result.M11 = xaxis.X;
result.M21 = xaxis.Y;
result.M31 = xaxis.Z;
result.M12 = yaxis.X;
result.M22 = yaxis.Y;
result.M32 = yaxis.Z;
result.M13 = zaxis.X;
result.M23 = zaxis.Y;
result.M33 = zaxis.Z;
result.M14 = 0.0f;
result.M24 = 0.0f;
result.M34 = 0.0f;
result.M41 = -Double3::Dot(xaxis, eye);
result.M42 = -Double3::Dot(yaxis, eye);
result.M43 = -Double3::Dot(zaxis, eye);
result.M44 = 1.0f;
}
void Double4x4::Multiply(const Double4x4& left, const Double4x4& right, Double4x4& result)
{
result.M11 = left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41;

View File

@@ -3,6 +3,7 @@
#include "Camera.h"
#include "Engine/Level/SceneObjectsFactory.h"
#include "Engine/Core/Math/Matrix.h"
#include "Engine/Core/Math/Double4x4.h"
#include "Engine/Core/Math/Viewport.h"
#include "Engine/Content/Assets/Model.h"
#include "Engine/Content/Content.h"
@@ -302,12 +303,15 @@ void Camera::GetMatrices(Matrix& view, Matrix& projection, const Viewport& viewp
}
// Create view matrix
const Float3 direction = GetDirection();
const Float3 position = _transform.Translation - origin;
const Float3 target = position + direction;
Float3 up;
Float3::Transform(Float3::Up, GetOrientation(), up);
Matrix::LookAt(position, target, up, view);
const Vector3 direction = Vector3::Transform(Vector3::Forward, GetOrientation());
const Vector3 position = _transform.Translation - origin;
const Vector3 target = position + direction;
Vector3 up;
Vector3::Transform(Vector3::Up, GetOrientation(), up);
Real4x4 viewResult;
Real4x4::LookAt(position, target, up, viewResult);
view = Matrix(viewResult);
}
#if USE_EDITOR