maded vec3 constexprable, addded lvl waring option

This commit is contained in:
2024-09-03 01:54:23 +03:00
parent c0d505b5e2
commit 9e32b043d0
6 changed files with 198 additions and 231 deletions

View File

@@ -9,178 +9,22 @@
namespace omath
{
Vector3::Vector3(const float x, const float y, const float z) : Vector2(x, y), z(z)
{
}
bool Vector3::operator==(const Vector3 &src) const
{
return Vector2::operator==(src) && (src.z == z);
}
bool Vector3::operator!=(const Vector3 &src) const
{
return !(*this == src);
}
Vector3 &Vector3::operator+=(const Vector3 &v)
{
Vector2::operator+=(v);
z += v.z;
return *this;
}
Vector3 &Vector3::operator-=(const Vector3 &v)
{
Vector2::operator-=(v);
z -= v.z;
return *this;
}
Vector3 &Vector3::operator*=(const float fl)
{
Vector2::operator*=(fl);
z *= fl;
return *this;
}
Vector3 &Vector3::operator*=(const Vector3 &v)
{
Vector2::operator*=(v);
z *= v.z;
return *this;
}
Vector3 &Vector3::operator/=(const Vector3 &v)
{
Vector2::operator/=(v);
z /= v.z;
return *this;
}
Vector3 &Vector3::operator+=(const float fl)
{
Vector2::operator+=(fl);
z += fl;
return *this;
}
Vector3 &Vector3::operator/=(const float fl)
{
Vector2::operator/=(fl);
z /= fl;
return *this;
}
Vector3 &Vector3::operator-=(const float fl)
{
Vector2::operator-=(fl);
z -= fl;
return *this;
}
float Vector3::DistTo(const Vector3 &vOther) const
{
return (*this - vOther).Length();
}
Vector3 &Vector3::Abs()
{
Vector2::Abs();
z = std::abs(z);
return *this;
}
float Vector3::DistToSqr(const Vector3 &vOther) const
{
return (*this - vOther).LengthSqr();
}
float Vector3::Dot(const Vector3 &vOther) const
{
return Vector2::Dot(vOther) + z * vOther.z;
}
float Vector3::Length() const
{
return std::sqrt(Vector2::LengthSqr() + z * z);
}
float Vector3::LengthSqr() const
{
return Vector2::LengthSqr() + z * z;
}
float Vector3::Length2D() const
{
return Vector2::Length();
}
Vector3 Vector3::operator-() const
{
return {-x, -y, -z};
}
Vector3 Vector3::operator+(const Vector3 &v) const
{
return {x + v.x, y + v.y, z + v.z};
}
Vector3 Vector3::operator-(const Vector3 &v) const
{
return {x - v.x, y - v.y, z - v.z};
}
Vector3 Vector3::operator*(float fl) const
{
return {x * fl, y * fl, z * fl};
}
Vector3 Vector3::operator*(const Vector3 &v) const
{
return {x * v.x, y * v.y, z * v.z};
}
Vector3 Vector3::operator/(const float fl) const
{
return {x / fl, y / fl, z / fl};
}
Vector3 Vector3::operator/(const Vector3 &v) const
{
return {x / v.x, y / v.y, z / v.z};
}
Vector3 Vector3::CreateVelocity(const float pitch, const float yaw, const float speed)
{
return
{
std::cos(angles::DegreesToRadians(pitch)) * std::cos(angles::DegreesToRadians(yaw)) * speed,
std::cos(angles::DegreesToRadians(pitch)) * std::sin(angles::DegreesToRadians(yaw)) * speed,
std::sin(angles::DegreesToRadians(pitch)) * speed,
};
}
float Vector3::Sum() const
{
return Vector3::Sum2D() + z;
}
float Vector3::Sum2D() const
{
return Vector2::Sum();
}
Vector3 Vector3::ViewAngleTo(const Vector3 &other) const
{
const float distance = DistTo(other);
@@ -233,15 +77,6 @@ namespace omath
return RightVector(pitch, yaw, roll).Cross(ForwardVector(pitch, yaw));
}
Vector3 Vector3::Cross(const Vector3 &v) const
{
return
{
y * v.z - z * v.y,
z * v.x - x * v.z,
x * v.y - y * v.x
};
}
Vector3 Vector3::Normalized() const
{
@@ -249,9 +84,4 @@ namespace omath
return length != 0 ? *this / length : *this;
}
std::tuple<float, float, float> Vector3::AsTuple() const
{
return std::make_tuple(x, y, z);
}
}