mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
maded vec3 constexprable, addded lvl waring option
This commit is contained in:
@@ -6,7 +6,7 @@ project(omath)
|
|||||||
set(CMAKE_CXX_STANDARD 26)
|
set(CMAKE_CXX_STANDARD 26)
|
||||||
|
|
||||||
option(BUILD_TESTS "Build unit tests" ON)
|
option(BUILD_TESTS "Build unit tests" ON)
|
||||||
|
option(THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to threat them as errors" ON)
|
||||||
add_library(omath STATIC source/Vector3.cpp)
|
add_library(omath STATIC source/Vector3.cpp)
|
||||||
|
|
||||||
add_subdirectory(source)
|
add_subdirectory(source)
|
||||||
@@ -16,4 +16,10 @@ if(BUILD_TESTS)
|
|||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (WIN32 AND THREAT_WARNING_AS_ERROR)
|
||||||
|
target_compile_definitions(omath PRIVATE /W4 /WX)
|
||||||
|
elseif(UNIX AND THREAT_WARNING_AS_ERROR)
|
||||||
|
target_compile_definitions(omath PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(omath PUBLIC include)
|
target_include_directories(omath PUBLIC include)
|
||||||
@@ -21,32 +21,36 @@ namespace omath
|
|||||||
constexpr Vector2(float x, float y) : x(x), y(y) {}
|
constexpr Vector2(float x, float y) : x(x), y(y) {}
|
||||||
|
|
||||||
// Equality operators
|
// Equality operators
|
||||||
|
[[nodiscard]]
|
||||||
constexpr bool operator==(const Vector2& src) const
|
constexpr bool operator==(const Vector2& src) const
|
||||||
{
|
{
|
||||||
return x == src.x && y == src.y;
|
return x == src.x && y == src.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr bool operator!=(const Vector2& src) const
|
constexpr bool operator!=(const Vector2& src) const
|
||||||
{
|
{
|
||||||
return !(*this == src);
|
return !(*this == src);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compound assignment operators
|
// Compound assignment operators
|
||||||
Vector2& operator+=(const Vector2& v)
|
constexpr Vector2& operator+=(const Vector2& v)
|
||||||
{
|
{
|
||||||
x += v.x;
|
x += v.x;
|
||||||
y += v.y;
|
y += v.y;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2& operator-=(const Vector2& v)
|
constexpr Vector2& operator-=(const Vector2& v)
|
||||||
{
|
{
|
||||||
x -= v.x;
|
x -= v.x;
|
||||||
y -= v.y;
|
y -= v.y;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2& operator*=(const Vector2& v)
|
constexpr Vector2& operator*=(const Vector2& v)
|
||||||
{
|
{
|
||||||
x *= v.x;
|
x *= v.x;
|
||||||
y *= v.y;
|
y *= v.y;
|
||||||
@@ -54,7 +58,7 @@ namespace omath
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2& operator/=(const Vector2& v)
|
constexpr Vector2& operator/=(const Vector2& v)
|
||||||
{
|
{
|
||||||
x /= v.x;
|
x /= v.x;
|
||||||
y /= v.y;
|
y /= v.y;
|
||||||
@@ -62,30 +66,35 @@ namespace omath
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2& operator*=(float fl)
|
constexpr Vector2& operator*=(float fl)
|
||||||
{
|
{
|
||||||
x *= fl;
|
x *= fl;
|
||||||
y *= fl;
|
y *= fl;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2& operator/=(float fl)
|
constexpr Vector2& operator/=(float fl)
|
||||||
{
|
{
|
||||||
x /= fl;
|
x /= fl;
|
||||||
y /= fl;
|
y /= fl;
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
Vector2& operator+=(float fl)
|
|
||||||
{
|
|
||||||
x += fl;
|
|
||||||
y += fl;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2& operator-=(float fl)
|
constexpr Vector2& operator+=(float fl)
|
||||||
|
{
|
||||||
|
x += fl;
|
||||||
|
y += fl;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector2& operator-=(float fl)
|
||||||
{
|
{
|
||||||
x -= fl;
|
x -= fl;
|
||||||
y -= fl;
|
y -= fl;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,45 +120,48 @@ namespace omath
|
|||||||
{
|
{
|
||||||
return x * x + y * y;
|
return x * x + y * y;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Vector2& Abs()
|
constexpr Vector2& Abs()
|
||||||
{
|
{
|
||||||
|
//FIXME: Replace with std::abs, if it will become constexprable
|
||||||
x = x < 0 ? -x : x;
|
x = x < 0 ? -x : x;
|
||||||
y = y < 0 ? -y : y;
|
y = y < 0 ? -y : y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class type>
|
template<class type>
|
||||||
constexpr const type& As() const
|
[[nodiscard]] constexpr const type& As() const
|
||||||
{
|
{
|
||||||
return *reinterpret_cast<const type*>(this);
|
return *reinterpret_cast<const type*>(this);
|
||||||
}
|
}
|
||||||
template<class type>
|
template<class type>
|
||||||
constexpr type& As()
|
[[nodiscard]] constexpr type& As()
|
||||||
{
|
{
|
||||||
return *reinterpret_cast<type*>(this);
|
return *reinterpret_cast<type*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unary negation operator
|
[[nodiscard]] constexpr Vector2 operator-() const
|
||||||
constexpr Vector2 operator-() const
|
|
||||||
{
|
{
|
||||||
return {-x, -y};
|
return {-x, -y};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary arithmetic operators
|
// Binary arithmetic operators
|
||||||
constexpr Vector2 operator+(const Vector2& v) const
|
[[nodiscard]] constexpr Vector2 operator+(const Vector2& v) const
|
||||||
{
|
{
|
||||||
return {x + v.x, y + v.y};
|
return {x + v.x, y + v.y};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Vector2 operator-(const Vector2& v) const
|
[[nodiscard]] constexpr Vector2 operator-(const Vector2& v) const
|
||||||
{
|
{
|
||||||
return {x - v.x, y - v.y};
|
return {x - v.x, y - v.y};
|
||||||
}
|
}
|
||||||
constexpr Vector2 operator*(float fl) const
|
|
||||||
|
[[nodiscard]] constexpr Vector2 operator*(float fl) const
|
||||||
{
|
{
|
||||||
return {x * fl, y * fl};
|
return {x * fl, y * fl};
|
||||||
}
|
}
|
||||||
constexpr Vector2 operator/(float fl) const
|
|
||||||
|
[[nodiscard]] constexpr Vector2 operator/(float fl) const
|
||||||
{
|
{
|
||||||
return {x / fl, y / fl};
|
return {x / fl, y / fl};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,42 +15,166 @@ namespace omath
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float z = 0.f;
|
float z = 0.f;
|
||||||
Vector3(float x, float y, float z);
|
constexpr Vector3(float x, float y, float z) : Vector2(x, y), z(z) { }
|
||||||
Vector3() = default;
|
constexpr Vector3() : Vector2(), z(0.f) {};
|
||||||
|
|
||||||
bool operator==(const Vector3& src) const;
|
[[nodiscard]] constexpr bool operator==(const Vector3& src) const
|
||||||
bool operator!=(const Vector3& src) const;
|
{
|
||||||
|
return Vector2::operator==(src) && (src.z == z);
|
||||||
|
}
|
||||||
|
|
||||||
Vector3& operator+=(const Vector3& v);
|
[[nodiscard]] constexpr bool operator!=(const Vector3& src) const
|
||||||
Vector3& operator-=(const Vector3& v);
|
{
|
||||||
Vector3& operator*=(float fl);
|
return !(*this == src);
|
||||||
Vector3& operator*=(const Vector3& v);
|
}
|
||||||
Vector3& operator/=(const Vector3& v);
|
|
||||||
Vector3& operator+=(float fl);
|
|
||||||
Vector3& operator/=(float fl);
|
|
||||||
Vector3& operator-=(float fl);
|
|
||||||
|
|
||||||
[[nodiscard]] float DistTo(const Vector3& vOther) const;
|
constexpr Vector3& operator+=(const Vector3& v)
|
||||||
Vector3& Abs();
|
{
|
||||||
[[nodiscard]] float DistToSqr(const Vector3& vOther) const;
|
Vector2::operator+=(v);
|
||||||
[[nodiscard]] float Dot(const Vector3& vOther) const;
|
z += v.z;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector3& operator-=(const Vector3& v)
|
||||||
|
{
|
||||||
|
Vector2::operator-=(v);
|
||||||
|
z -= v.z;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector3& operator*=(float fl)
|
||||||
|
{
|
||||||
|
Vector2::operator*=(fl);
|
||||||
|
z *= fl;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector3& operator*=(const Vector3& v)
|
||||||
|
{
|
||||||
|
Vector2::operator*=(v);
|
||||||
|
z *= v.z;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector3& operator/=(const Vector3& v)
|
||||||
|
{
|
||||||
|
Vector2::operator/=(v);
|
||||||
|
z /= v.z;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector3& operator+=(float fl)
|
||||||
|
{
|
||||||
|
Vector2::operator+=(fl);
|
||||||
|
z += fl;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector3& operator/=(float fl)
|
||||||
|
{
|
||||||
|
Vector2::operator/=(fl);
|
||||||
|
z /= fl;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector3& operator-=(float fl)
|
||||||
|
{
|
||||||
|
Vector2::operator-=(fl);
|
||||||
|
z -= fl;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
float DistTo(const Vector3& vOther) const;
|
||||||
|
|
||||||
|
constexpr Vector3& Abs()
|
||||||
|
{
|
||||||
|
Vector2::Abs();
|
||||||
|
z = z < 0.f ? -z : z;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr float DistToSqr(const Vector3& vOther) const
|
||||||
|
{
|
||||||
|
return (*this - vOther).LengthSqr();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr float Dot(const Vector3& vOther) const
|
||||||
|
{
|
||||||
|
return Vector2::Dot(vOther) + z * vOther.z;
|
||||||
|
}
|
||||||
[[nodiscard]] float Length() const;
|
[[nodiscard]] float Length() const;
|
||||||
[[nodiscard]] float LengthSqr() const;
|
|
||||||
|
[[nodiscard]] constexpr float LengthSqr() const
|
||||||
|
{
|
||||||
|
return Vector2::LengthSqr() + z * z;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] float Length2D() const;
|
[[nodiscard]] float Length2D() const;
|
||||||
|
|
||||||
Vector3 operator-() const;
|
[[nodiscard]] constexpr Vector3 operator-() const
|
||||||
Vector3 operator+(const Vector3& v) const;
|
{
|
||||||
Vector3 operator-(const Vector3& v) const;
|
return {-x, -y, -z};
|
||||||
Vector3 operator*(float fl) const;
|
}
|
||||||
Vector3 operator*(const Vector3& v) const;
|
|
||||||
Vector3 operator/(float fl) const;
|
|
||||||
Vector3 operator/(const Vector3& v) const;
|
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vector3 operator+(const Vector3& v) const
|
||||||
|
{
|
||||||
|
return {x + v.x, y + v.y, z + v.z};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vector3 operator-(const Vector3& v) const
|
||||||
|
{
|
||||||
|
return {x - v.x, y - v.y, z - v.z};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vector3 operator*(float fl) const
|
||||||
|
{
|
||||||
|
return {x * fl, y * fl, z * fl};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vector3 operator*(const Vector3& v) const
|
||||||
|
{
|
||||||
|
return {x * v.x, y * v.y, z * v.z};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vector3 operator/(float fl) const
|
||||||
|
{
|
||||||
|
return {x / fl, y / fl, z / fl};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vector3 operator/(const Vector3& v) const
|
||||||
|
{
|
||||||
|
return {x / v.x, y / v.y, z / v.z};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr 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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr float Sum() const
|
||||||
|
{
|
||||||
|
return Vector3::Sum2D() + z;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr float Sum2D() const
|
||||||
|
{
|
||||||
|
return Vector2::Sum();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] Vector3 Cross(const Vector3 &v) const;
|
|
||||||
[[nodiscard]] static Vector3 CreateVelocity(float pitch, float yaw, float speed);
|
|
||||||
[[nodiscard]] float Sum() const;
|
|
||||||
[[nodiscard]] float Sum2D() const;
|
|
||||||
[[nodiscard]] Vector3 ViewAngleTo(const Vector3& other) const;
|
[[nodiscard]] Vector3 ViewAngleTo(const Vector3& other) const;
|
||||||
|
|
||||||
[[nodiscard]] static Vector3 ForwardVector(float pitch, float yaw);
|
[[nodiscard]] static Vector3 ForwardVector(float pitch, float yaw);
|
||||||
@@ -61,7 +185,10 @@ namespace omath
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3 Normalized() const;
|
Vector3 Normalized() const;
|
||||||
|
|
||||||
[[nodiscard]] std::tuple<float, float, float> AsTuple() const;
|
[[nodiscard]] std::tuple<float, float, float> AsTuple() const
|
||||||
|
{
|
||||||
|
return std::make_tuple(x, y, z);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// ReSharper disable once CppRedundantNamespaceDefinition
|
// ReSharper disable once CppRedundantNamespaceDefinition
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ namespace omath::prediction
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
Vector3 CalculateVelocity(float pitch, float yaw) const;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3 PredictPosition(float pitch, float yaw, float time, float gravity) const;
|
Vector3 PredictPosition(float pitch, float yaw, float time, float gravity) const;
|
||||||
|
|
||||||
|
|||||||
@@ -9,178 +9,22 @@
|
|||||||
namespace omath
|
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
|
float Vector3::DistTo(const Vector3 &vOther) const
|
||||||
{
|
{
|
||||||
return (*this - vOther).Length();
|
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
|
float Vector3::Length() const
|
||||||
{
|
{
|
||||||
return std::sqrt(Vector2::LengthSqr() + z * z);
|
return std::sqrt(Vector2::LengthSqr() + z * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector3::LengthSqr() const
|
|
||||||
{
|
|
||||||
return Vector2::LengthSqr() + z * z;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Vector3::Length2D() const
|
float Vector3::Length2D() const
|
||||||
{
|
{
|
||||||
return Vector2::Length();
|
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
|
Vector3 Vector3::ViewAngleTo(const Vector3 &other) const
|
||||||
{
|
{
|
||||||
const float distance = DistTo(other);
|
const float distance = DistTo(other);
|
||||||
@@ -233,15 +77,6 @@ namespace omath
|
|||||||
return RightVector(pitch, yaw, roll).Cross(ForwardVector(pitch, yaw));
|
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
|
Vector3 Vector3::Normalized() const
|
||||||
{
|
{
|
||||||
@@ -249,9 +84,4 @@ namespace omath
|
|||||||
|
|
||||||
return length != 0 ? *this / length : *this;
|
return length != 0 ? *this / length : *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<float, float, float> Vector3::AsTuple() const
|
|
||||||
{
|
|
||||||
return std::make_tuple(x, y, z);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,9 @@
|
|||||||
|
|
||||||
namespace omath::prediction
|
namespace omath::prediction
|
||||||
{
|
{
|
||||||
Vector3 Projectile::CalculateVelocity(const float pitch, const float yaw) const
|
|
||||||
{
|
|
||||||
return Vector3::CreateVelocity(pitch, yaw, m_launchSpeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 Projectile::PredictPosition(const float pitch, const float yaw, const float time, const float gravity) const
|
Vector3 Projectile::PredictPosition(const float pitch, const float yaw, const float time, const float gravity) const
|
||||||
{
|
{
|
||||||
auto currentPos = m_origin + Vector3::CreateVelocity(pitch, yaw, m_launchSpeed) * time;
|
auto currentPos = m_origin + Vector3::ForwardVector(pitch, yaw) * m_launchSpeed * time;
|
||||||
currentPos.z -= (gravity * m_gravityScale) * std::pow(time, 2.f) * 0.5f;
|
currentPos.z -= (gravity * m_gravityScale) * std::pow(time, 2.f) * 0.5f;
|
||||||
|
|
||||||
return currentPos;
|
return currentPos;
|
||||||
|
|||||||
Reference in New Issue
Block a user