mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
updated formulas
This commit is contained in:
@@ -430,4 +430,30 @@ namespace omath
|
|||||||
{
|
{
|
||||||
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
|
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||||
|
[[nodiscard]]
|
||||||
|
Mat<4, 4, Type, St> MatPerspectiveLeftHanded(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
|
const float far) noexcept
|
||||||
|
{
|
||||||
|
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f);
|
||||||
|
|
||||||
|
return {{1.f / (aspectRatio * fovHalfTan), 0.f, 0.f, 0.f},
|
||||||
|
{0.f, 1.f / fovHalfTan, 0.f, 0.f},
|
||||||
|
{0.f, 0.f, (far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
||||||
|
{0.f, 0.f, 1.f, 0.f}};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||||
|
[[nodiscard]]
|
||||||
|
Mat<4, 4, Type, St> MatPerspectiveRightHanded(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
|
const float far) noexcept
|
||||||
|
{
|
||||||
|
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f);
|
||||||
|
|
||||||
|
return {{1.f / (aspectRatio * fovHalfTan), 0.f, 0.f, 0.f},
|
||||||
|
{0.f, 1.f / fovHalfTan, 0.f, 0.f},
|
||||||
|
{0.f, 0.f, -(far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
||||||
|
{0.f, 0.f, -1.f, 0.f}};
|
||||||
|
}
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|||||||
@@ -26,22 +26,25 @@ namespace omath::iw_engine
|
|||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||||
{
|
{
|
||||||
return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
return MatCameraView(ForwardVector(angles), RightVector(angles), -UpVector(angles), cam_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
const float far)
|
const float far)
|
||||||
{
|
{
|
||||||
// NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation
|
// NOTE: Need magic number to fix fov calculation, since IW engine inherit Quake proj matrix calculation
|
||||||
constexpr auto kMultiplyFactor = 0.75f;
|
constexpr auto kMultiplyFactor = 0.75f;
|
||||||
|
|
||||||
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor;
|
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{1.f / (aspectRatio * fovHalfTan), 0, 0, 0},
|
{1.f / (aspectRatio * fovHalfTan), 0, 0, 0},
|
||||||
{0, 1.f / fovHalfTan, 0, 0},
|
{0, 1.f / (fovHalfTan), 0, 0},
|
||||||
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||||
{0, 0, 1, 0},
|
{0, 0, 1, 0},
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
} // namespace omath::iw_engine
|
} // namespace omath::iw_engine
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ namespace omath::source_engine
|
|||||||
|
|
||||||
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||||
{
|
{
|
||||||
return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
return MatCameraView(ForwardVector(angles), RightVector(angles), -UpVector(angles), cam_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
const float far)
|
const float far)
|
||||||
{
|
{
|
||||||
@@ -43,7 +44,6 @@ namespace omath::source_engine
|
|||||||
{0, 1.f / (fovHalfTan), 0, 0},
|
{0, 1.f / (fovHalfTan), 0, 0},
|
||||||
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||||
{0, 0, 1, 0},
|
{0, 0, 1, 0},
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} // namespace omath::source_engine
|
} // namespace omath::source_engine
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// Created by Vlad on 3/22/2025.
|
// Created by Vlad on 3/22/2025.
|
||||||
//
|
//
|
||||||
#include <omath/engines/unity_engine/camera.hpp>
|
#include <omath/engines/unity_engine/camera.hpp>
|
||||||
|
#include <omath/engines/unity_engine/formulas.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace omath::unity_engine
|
namespace omath::unity_engine
|
||||||
|
|||||||
Reference in New Issue
Block a user