mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 15:03:27 +00:00
fixed projection matrix
This commit is contained in:
@@ -280,16 +280,18 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr static Mat<4, 4> ProjectionMat(const float fieldOfView, const float aspectRatio, const float near, const float far)
|
||||
constexpr static Mat<4, 4> ProjectionMat(const float fieldOfView, const float aspectRatio,
|
||||
const float near, const float far, const float lensZoom)
|
||||
{
|
||||
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f);
|
||||
const float frustumHeight = far - near;
|
||||
|
||||
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}
|
||||
{-1.f / (aspectRatio * fovHalfTan) * lensZoom, 0.f, 0.f, 0.f},
|
||||
{0.f, -1.f / fovHalfTan * lensZoom, 0.f, 0.f},
|
||||
{0.f, 0.f, -far / frustumHeight, -1},
|
||||
{0.f, 0.f, near * far / frustumHeight, 0.f}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -25,18 +25,20 @@ namespace omath::projection
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
Camera(const Vector3& position, const Vector3& viewAngles, const ViewPort& viewPort, float fov, float near, float far);
|
||||
Camera(const Vector3& position, const Vector3& viewAngles, const ViewPort& viewPort,
|
||||
float fov, float near, float far, float lensZoom);
|
||||
void SetViewAngles(const Vector3& viewAngles);
|
||||
|
||||
[[nodiscard]] Mat<4, 4> GetViewMatrix() const;
|
||||
|
||||
[[nodiscard]] std::expected<Vector2, Error> WorldToScreen(const Vector3& worldPosition) const;
|
||||
[[nodiscard]] std::expected<Vector2, Error> WorldToScreen(Vector3 worldPosition) const;
|
||||
|
||||
ViewPort m_viewPort{};
|
||||
float m_fieldOfView;
|
||||
|
||||
float m_farPlaneDistance;
|
||||
float m_nearPlaneDistance;
|
||||
float m_lensZoom;
|
||||
|
||||
private:
|
||||
Vector3 m_viewAngles;
|
||||
|
||||
@@ -10,7 +10,6 @@ namespace omath::projection
|
||||
{
|
||||
enum class Error : uint16_t
|
||||
{
|
||||
WORLD_POSITION_IS_BEHIND_CAMERA = 0,
|
||||
WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user