mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
improved mat & camera interface
This commit is contained in:
@@ -34,11 +34,13 @@ namespace omath
|
|||||||
class Mat final
|
class Mat final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr Mat()
|
constexpr Mat() noexcept
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
constexpr static MatStoreType GetStoreOrdering()
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr static MatStoreType GetStoreOrdering() noexcept
|
||||||
{
|
{
|
||||||
return StoreType;
|
return StoreType;
|
||||||
}
|
}
|
||||||
@@ -72,6 +74,7 @@ namespace omath
|
|||||||
m_data = other.m_data;
|
m_data = other.m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr Type& operator[](const size_t row, const size_t col)
|
constexpr Type& operator[](const size_t row, const size_t col)
|
||||||
{
|
{
|
||||||
return At(row, col);
|
return At(row, col);
|
||||||
@@ -100,7 +103,8 @@ namespace omath
|
|||||||
return {Rows, Columns};
|
return {Rows, Columns};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const
|
[[nodiscard]]
|
||||||
|
constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const
|
||||||
{
|
{
|
||||||
if (rowIndex >= Rows || columnIndex >= Columns)
|
if (rowIndex >= Rows || columnIndex >= Columns)
|
||||||
throw std::out_of_range("Index out of range");
|
throw std::out_of_range("Index out of range");
|
||||||
@@ -177,6 +181,7 @@ namespace omath
|
|||||||
return *this = *this * other;
|
return *this = *this * other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr Mat operator*(const Type& f) const noexcept
|
constexpr Mat operator*(const Type& f) const noexcept
|
||||||
{
|
{
|
||||||
Mat result(*this);
|
Mat result(*this);
|
||||||
@@ -192,6 +197,7 @@ namespace omath
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr Mat operator/(const Type& f) const noexcept
|
constexpr Mat operator/(const Type& f) const noexcept
|
||||||
{
|
{
|
||||||
Mat result(*this);
|
Mat result(*this);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace omath::projection
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
protected:
|
||||||
virtual void LookAt(const Vector3<float>& target) = 0;
|
virtual void LookAt(const Vector3<float>& target) = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual Mat4x4Type CalcViewMatrix() const = 0;
|
[[nodiscard]] virtual Mat4x4Type CalcViewMatrix() const = 0;
|
||||||
@@ -49,41 +49,44 @@ namespace omath::projection
|
|||||||
{
|
{
|
||||||
return CalcProjectionMatrix() * CalcViewMatrix();
|
return CalcProjectionMatrix() * CalcViewMatrix();
|
||||||
}
|
}
|
||||||
|
public:
|
||||||
|
|
||||||
|
[[nodiscard]] const Mat4x4Type& GetViewProjectionMatrix() const
|
||||||
|
{
|
||||||
|
if (!m_viewProjectionMatrix.has_value())
|
||||||
|
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||||
|
|
||||||
|
return m_viewProjectionMatrix.value();
|
||||||
|
}
|
||||||
|
|
||||||
void SetFieldOfView(const FieldOfView& fov)
|
void SetFieldOfView(const FieldOfView& fov)
|
||||||
{
|
{
|
||||||
m_fieldOfView = fov;
|
m_fieldOfView = fov;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNearPlane(const float near)
|
void SetNearPlane(const float near)
|
||||||
{
|
{
|
||||||
m_nearPlaneDistance = near;
|
m_nearPlaneDistance = near;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFarPlane(const float far)
|
void SetFarPlane(const float far)
|
||||||
{
|
{
|
||||||
m_farPlaneDistance = far;
|
m_farPlaneDistance = far;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetViewAngles(const ViewAnglesType& viewAngles)
|
void SetViewAngles(const ViewAnglesType& viewAngles)
|
||||||
{
|
{
|
||||||
m_viewAngles = viewAngles;
|
m_viewAngles = viewAngles;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetOrigin(const Vector3<float>& origin)
|
void SetOrigin(const Vector3<float>& origin)
|
||||||
{
|
{
|
||||||
m_origin = origin;
|
m_origin = origin;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetViewPort(const ViewPort& viewPort)
|
void SetViewPort(const ViewPort& viewPort)
|
||||||
{
|
{
|
||||||
m_viewPort = viewPort;
|
m_viewPort = viewPort;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const FieldOfView& GetFieldOfView() const
|
[[nodiscard]] const FieldOfView& GetFieldOfView() const
|
||||||
@@ -113,10 +116,9 @@ namespace omath::projection
|
|||||||
|
|
||||||
[[nodiscard]] std::expected<Vector3<float>, Error> WorldToScreen(const Vector3<float>& worldPosition) const
|
[[nodiscard]] std::expected<Vector3<float>, Error> WorldToScreen(const Vector3<float>& worldPosition) const
|
||||||
{
|
{
|
||||||
if (!m_viewProjectionMatrix.has_value())
|
const auto& viewProjMatrix = GetViewProjectionMatrix();
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
|
|
||||||
auto projected = m_viewProjectionMatrix.value() * MatColumnFromVector<float, Mat4x4Type::GetStoreOrdering()>(worldPosition);
|
auto projected = viewProjMatrix * MatColumnFromVector<float, Mat4x4Type::GetStoreOrdering()>(worldPosition);
|
||||||
|
|
||||||
if (projected.At(3, 0) == 0.0f)
|
if (projected.At(3, 0) == 0.0f)
|
||||||
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
||||||
|
|||||||
Reference in New Issue
Block a user