fixed some stuff added constexpr

This commit is contained in:
2024-10-20 00:25:03 +03:00
parent c45bca2e0b
commit ef24377049
8 changed files with 37 additions and 70 deletions

View File

@@ -8,18 +8,4 @@
namespace omath
{
Vector2 Vector2::Normalized() const
{
const float len = Length();
if (len > 0.f)
return {x / len, y / len};
return {0.f, 0.f};
}
float Vector2::Length() const
{
return std::sqrt(x * x + y * y);
}
}

View File

@@ -8,23 +8,6 @@
namespace omath
{
float Vector3::DistTo(const Vector3 &vOther) const
{
return (*this - vOther).Length();
}
float Vector3::Length() const
{
return std::sqrt(Vector2::LengthSqr() + z * z);
}
float Vector3::Length2D() const
{
return Vector2::Length();
}
Vector3 Vector3::ViewAngleTo(const Vector3 &other) const
{
const float distance = DistTo(other);
@@ -83,12 +66,4 @@ namespace omath
{
return RightVector(pitch, yaw, roll).Cross(ForwardVector(pitch, yaw));
}
Vector3 Vector3::Normalized() const
{
const float length = this->Length();
return length != 0 ? *this / length : *this;
}
}

View File

@@ -32,7 +32,7 @@ namespace omath::projection
return Mat<4, 4>::TranslationMat(-m_origin) * Mat<4, 4>::OrientationMat(forward, right, up);
}
std::expected<Vector2, Error> Camera::WorldToScreen(Vector3 worldPosition) const
std::expected<Vector3, Error> Camera::WorldToScreen(const Vector3& worldPosition) const
{
const auto posVecAsMatrix = Mat<1, 4>({{worldPosition.x, worldPosition.y, worldPosition.z, 1.f}});
@@ -54,6 +54,6 @@ namespace omath::projection
projected *= Mat<4, 4>::ToScreenMat(m_viewPort.m_width, m_viewPort.m_height);
return Vector2{projected.At(0, 0), projected.At(0, 1)};
return Vector3{projected.At(0, 0), projected.At(0, 1), projected.At(0, 2)};
}
}