Merge pull request #38064 from aaronfranke/rotated
Improve the Vector2 rotated code
This commit is contained in:
commit
e445be6944
2 changed files with 5 additions and 11 deletions
|
@ -119,11 +119,11 @@ Vector2 Vector2::round() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::rotated(real_t p_by) const {
|
Vector2 Vector2::rotated(real_t p_by) const {
|
||||||
|
real_t sine = Math::sin(p_by);
|
||||||
Vector2 v;
|
real_t cosi = Math::cos(p_by);
|
||||||
v.set_rotation(angle() + p_by);
|
return Vector2(
|
||||||
v *= length();
|
x * cosi - y * sine,
|
||||||
return v;
|
x * sine + y * cosi);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::posmod(const real_t p_mod) const {
|
Vector2 Vector2::posmod(const real_t p_mod) const {
|
||||||
|
|
|
@ -123,12 +123,6 @@ struct Vector2 {
|
||||||
|
|
||||||
real_t angle() const;
|
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 {
|
_FORCE_INLINE_ Vector2 abs() const {
|
||||||
|
|
||||||
return Vector2(Math::abs(x), Math::abs(y));
|
return Vector2(Math::abs(x), Math::abs(y));
|
||||||
|
|
Loading…
Add table
Reference in a new issue