Merge branch 'GoaLitiuM-large_worlds_camera_fix'
This commit is contained in:
@@ -93,6 +93,9 @@ public:
|
|||||||
// Calculates the inverse of the specified matrix.
|
// Calculates the inverse of the specified matrix.
|
||||||
static void Invert(const Double4x4& value, Double4x4& result);
|
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.
|
// Calculates the product of two matrices.
|
||||||
static void Multiply(const Double4x4& left, const Double4x4& right, Double4x4& result);
|
static void Multiply(const Double4x4& left, const Double4x4& right, Double4x4& result);
|
||||||
|
|
||||||
|
|||||||
@@ -1001,6 +1001,37 @@ void Double4x4::Invert(const Double4x4& value, Double4x4& result)
|
|||||||
result.M44 = +d44 * det;
|
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)
|
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;
|
result.M11 = left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "Engine/Level/SceneObjectsFactory.h"
|
#include "Engine/Level/SceneObjectsFactory.h"
|
||||||
#include "Engine/Core/Math/Matrix.h"
|
#include "Engine/Core/Math/Matrix.h"
|
||||||
|
#include "Engine/Core/Math/Double4x4.h"
|
||||||
#include "Engine/Core/Math/Viewport.h"
|
#include "Engine/Core/Math/Viewport.h"
|
||||||
#include "Engine/Content/Assets/Model.h"
|
#include "Engine/Content/Assets/Model.h"
|
||||||
#include "Engine/Content/Content.h"
|
#include "Engine/Content/Content.h"
|
||||||
@@ -302,12 +303,15 @@ void Camera::GetMatrices(Matrix& view, Matrix& projection, const Viewport& viewp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create view matrix
|
// Create view matrix
|
||||||
const Float3 direction = GetDirection();
|
const Vector3 direction = Vector3::Transform(Vector3::Forward, GetOrientation());
|
||||||
const Float3 position = _transform.Translation - origin;
|
const Vector3 position = _transform.Translation - origin;
|
||||||
const Float3 target = position + direction;
|
const Vector3 target = position + direction;
|
||||||
Float3 up;
|
|
||||||
Float3::Transform(Float3::Up, GetOrientation(), up);
|
Vector3 up;
|
||||||
Matrix::LookAt(position, target, up, view);
|
Vector3::Transform(Vector3::Up, GetOrientation(), up);
|
||||||
|
Real4x4 viewResult;
|
||||||
|
Real4x4::LookAt(position, target, up, viewResult);
|
||||||
|
view = Matrix(viewResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|||||||
Reference in New Issue
Block a user