Merge pull request #412 from Zylann/direction_to

Add missing Vector3::direction_to() and Vector2::direction_to()
pull/304/head
Bastiaan Olij 2020-06-09 17:24:04 +10:00 committed by GitHub
commit 2bb3a7e19c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -138,6 +138,12 @@ struct Vector2 {
return atan2(y - p_vector2.y, x - p_vector2.x); return atan2(y - p_vector2.y, x - p_vector2.x);
} }
inline Vector2 direction_to(const Vector2 &p_b) const {
Vector2 ret(p_b.x - x, p_b.y - y);
ret.normalize();
return ret;
}
inline real_t dot(const Vector2 &p_other) const { inline real_t dot(const Vector2 &p_other) const {
return x * p_other.x + y * p_other.y; return x * p_other.x + y * p_other.y;
} }

View File

@ -203,6 +203,12 @@ struct Vector3 {
return std::atan2(cross(b).length(), dot(b)); return std::atan2(cross(b).length(), dot(b));
} }
inline Vector3 direction_to(const Vector3 &p_b) const {
Vector3 ret(p_b.x - x, p_b.y - y, p_b.z - z);
ret.normalize();
return ret;
}
inline Vector3 floor() const { inline Vector3 floor() const {
return Vector3(::floor(x), ::floor(y), ::floor(z)); return Vector3(::floor(x), ::floor(y), ::floor(z));
} }