From 4448ee150debed82598824f33182bd2daed0471f Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 25 Jan 2023 15:54:41 +0100 Subject: [PATCH] Fixed Vector2::Rotation --- include/Polar.h | 11 ++++------- src/Vector2.cpp | 17 ++++++++--------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/include/Polar.h b/include/Polar.h index 072d9e8..468b35a 100644 --- a/include/Polar.h +++ b/include/Polar.h @@ -8,8 +8,7 @@ /// /// A polar vector /// -/// This will use the polar coordinate system consisting of a angle from a -/// reference direction and a distance. +/// This will use the polar coordinate system consisting of a angle from a reference direction and a distance. struct Polar { public: /// @@ -44,7 +43,7 @@ struct Polar { /// /// This will rotate the vector by 180 degrees. Distance will stay the same. /// The negated vector - + Polar operator-(); /// /// Substract a polar vector from this coordinate @@ -65,8 +64,7 @@ struct Polar { /// /// The scaling factor /// The scaled vector - /// This operation will scale the distance of the vector. The angle will be - /// unaffected. + /// This operation will scale the distance of the vector. The angle will be unaffected. Polar operator*(float factor) const; /// @@ -74,8 +72,7 @@ struct Polar { /// /// The scaling factor /// The scaled vector - /// This operation will scale the distance of the vector. The angle will be - /// unaffected. + /// This operation will scale the distance of the vector. The angle will be unaffected. Polar operator/(const float& factor); /// diff --git a/src/Vector2.cpp b/src/Vector2.cpp index 63479c9..d47e44d 100644 --- a/src/Vector2.cpp +++ b/src/Vector2.cpp @@ -118,15 +118,15 @@ float Vector2::SignedAngle(Vector2 from, Vector2 to) { return (angleTo - angleFrom) * Angle::Rad2Deg; } -Vector2 Rotate(Vector2 v, float angle) { - float sin = (float)sinf(angle * Angle::Deg2Rad); - float cos = (float)cosf(angle * Angle::Deg2Rad); +Vector2 Vector2::Rotate(Vector2 v, float angle) { + float sin = (float)sinf(angle * Angle::Deg2Rad); + float cos = (float)cosf(angle * Angle::Deg2Rad); - float tx = v.x; - float ty = v.y; - v.x = (cos * tx) - (sin * ty); - v.y = (sin * tx) + (cos * ty); - return v; + float tx = v.x; + float ty = v.y; + v.x = (cos * tx) - (sin * ty); + v.y = (sin * tx) + (cos * ty); + return v; } Vector2 Vector2::Lerp(Vector2 from, Vector2 to, float f) { @@ -137,4 +137,3 @@ Vector2 Vector2::Lerp(Vector2 from, Vector2 to, float f) { float Vector2::ToFactor(Vector2 a, Vector2 b) { return (1 - Vector2::Dot(a, b)) / 2; } -