Sfoglia il codice sorgente

Merge pull request #1997 from eugeneko/master

Add Vector3::Orthogonalize helper function.
Eugene Kozlov 8 anni fa
parent
commit
1826fdb73a

+ 1 - 0
Source/Urho3D/AngelScript/MathAPI.cpp

@@ -438,6 +438,7 @@ static void RegisterVector3(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Vector3", "float DotProduct(const Vector3&in) const", asMETHOD(Vector3, DotProduct), asCALL_THISCALL);
     engine->RegisterObjectMethod("Vector3", "float AbsDotProduct(const Vector3&in) const", asMETHOD(Vector3, AbsDotProduct), asCALL_THISCALL);
     engine->RegisterObjectMethod("Vector3", "float ProjectOntoAxis(const Vector3&in) const", asMETHOD(Vector3, ProjectOntoAxis), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Vector3", "Vector3 Orthogonalize(const Vector3&in) const", asMETHOD(Vector3, Orthogonalize), asCALL_THISCALL);
     engine->RegisterObjectMethod("Vector3", "Vector3 CrossProduct(const Vector3&in) const", asMETHOD(Vector3, CrossProduct), asCALL_THISCALL);
     engine->RegisterObjectMethod("Vector3", "Vector3 Abs() const", asMETHOD(Vector3, Abs), asCALL_THISCALL);
     engine->RegisterObjectMethod("Vector3", "Vector3 Lerp(const Vector3&in, float) const", asMETHOD(Vector3, Lerp), asCALL_THISCALL);

+ 1 - 0
Source/Urho3D/LuaScript/pkgs/Math/Vector3.pkg

@@ -25,6 +25,7 @@ class Vector3
     float DotProduct(const Vector3& rhs) const;
     float AbsDotProduct(const Vector3& rhs) const;
     float ProjectOntoAxis(const Vector3& axis) const;
+    Vector3 Orthogonalize(const Vector3& axis) const;
     Vector3 CrossProduct(const Vector3& rhs) const;
     Vector3 Abs() const;
     Vector3 Lerp(const Vector3& rhs, float t) const;

+ 7 - 4
Source/Urho3D/Math/Vector3.h

@@ -357,6 +357,9 @@ public:
     /// Project vector onto axis.
     float ProjectOntoAxis(const Vector3& axis) const { return DotProduct(axis.Normalized()); }
 
+    /// Make vector orthogonal to the axis.
+    Vector3 Orthogonalize(const Vector3& axis) const { return axis.CrossProduct(*this).CrossProduct(axis).Normalized(); }
+
     /// Calculate cross product.
     Vector3 CrossProduct(const Vector3& rhs) const
     {
@@ -403,15 +406,15 @@ public:
 
     /// Return as string.
     String ToString() const;
-    
+
     /// Return hash value for HashSet & HashMap.
-    unsigned ToHash() const 
-    { 
+    unsigned ToHash() const
+    {
         unsigned hash = 37;
         hash = 37 * hash + FloatToRawIntBits(x_);
         hash = 37 * hash + FloatToRawIntBits(y_);
         hash = 37 * hash + FloatToRawIntBits(z_);
-        
+
         return hash;
     }