diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-04-28 20:49:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-28 20:49:22 +0200 |
commit | e445be694401c9c75b587f5113280ce36cf1666b (patch) | |
tree | d07d2244250bb293a5184622e2938f1005c61bb8 | |
parent | 2497740a4eb70683639f9225e9ac9ecb5e7da52a (diff) | |
parent | 23a349c427225060928b27f531a1e832a26c92e5 (diff) |
Merge pull request #38064 from aaronfranke/rotated
Improve the Vector2 rotated code
-rw-r--r-- | core/math/vector2.cpp | 10 | ||||
-rw-r--r-- | core/math/vector2.h | 6 |
2 files changed, 5 insertions, 11 deletions
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index f4259e388b..f46badd19e 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -119,11 +119,11 @@ Vector2 Vector2::round() const { } Vector2 Vector2::rotated(real_t p_by) const { - - Vector2 v; - v.set_rotation(angle() + p_by); - v *= length(); - return v; + real_t sine = Math::sin(p_by); + real_t cosi = Math::cos(p_by); + return Vector2( + x * cosi - y * sine, + x * sine + y * cosi); } Vector2 Vector2::posmod(const real_t p_mod) const { diff --git a/core/math/vector2.h b/core/math/vector2.h index ba5558102f..95d2474838 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -123,12 +123,6 @@ struct Vector2 { real_t angle() const; - void set_rotation(real_t p_radians) { - - x = Math::cos(p_radians); - y = Math::sin(p_radians); - } - _FORCE_INLINE_ Vector2 abs() const { return Vector2(Math::abs(x), Math::abs(y)); |