Bläddra i källkod

Wrote Angle() member function for Vector2 class

TheComet 10 år sedan
förälder
incheckning
d38c24d4f2
1 ändrade filer med 3 tillägg och 0 borttagningar
  1. 3 0
      Source/Urho3D/Math/Vector2.h

+ 3 - 0
Source/Urho3D/Math/Vector2.h

@@ -168,6 +168,9 @@ public:
     /// Calculate absolute dot product.
     /// Calculate absolute dot product.
     float AbsDotProduct(const Vector2& rhs) const { return Urho3D::Abs(x_ * rhs.x_) + Urho3D::Abs(y_ * rhs.y_); }
     float AbsDotProduct(const Vector2& rhs) const { return Urho3D::Abs(x_ * rhs.x_) + Urho3D::Abs(y_ * rhs.y_); }
 
 
+    /// Returns the angle between this vector and another vector in degrees.
+    float Angle(const Vector2& rhs) const { return Urho3D::Acos(DotProduct(rhs) / (Length() * rhs.Length())); }
+
     /// Return absolute vector.
     /// Return absolute vector.
     Vector2 Abs() const { return Vector2(Urho3D::Abs(x_), Urho3D::Abs(y_)); }
     Vector2 Abs() const { return Vector2(Urho3D::Abs(x_), Urho3D::Abs(y_)); }