From 528b8a0ca9be8dfcbd16dc849c53066c6c14456f Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 17 Jun 2024 01:35:16 +0300 Subject: [PATCH] added 2 methods --- include/uml/Vector3.h | 4 ++++ source/Vector3.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/uml/Vector3.h b/include/uml/Vector3.h index ea4348a..947bbc8 100644 --- a/include/uml/Vector3.h +++ b/include/uml/Vector3.h @@ -57,9 +57,13 @@ namespace uml { return *reinterpret_cast(this); } + [[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 Normalized() const; }; } diff --git a/source/Vector3.cpp b/source/Vector3.cpp index 7fb27f7..8f0f842 100644 --- a/source/Vector3.cpp +++ b/source/Vector3.cpp @@ -210,4 +210,23 @@ namespace uml 0.f }; } + + 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 + { + float length = this->Length(); + if (length != 0) + { + return *this / length; + } + return *this; + } } \ No newline at end of file