소스 검색

Merge pull request #1997 from eugeneko/master

Add Vector3::Orthogonalize helper function.
Eugene Kozlov 8 년 전
부모
커밋
1826fdb73a
3개의 변경된 파일9개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 0
      Source/Urho3D/AngelScript/MathAPI.cpp
  2. 1 0
      Source/Urho3D/LuaScript/pkgs/Math/Vector3.pkg
  3. 7 4
      Source/Urho3D/Math/Vector3.h

+ 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 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 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", "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 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 Abs() const", asMETHOD(Vector3, Abs), asCALL_THISCALL);
     engine->RegisterObjectMethod("Vector3", "Vector3 Lerp(const Vector3&in, float) const", asMETHOD(Vector3, Lerp), 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 DotProduct(const Vector3& rhs) const;
     float AbsDotProduct(const Vector3& rhs) const;
     float AbsDotProduct(const Vector3& rhs) const;
     float ProjectOntoAxis(const Vector3& axis) const;
     float ProjectOntoAxis(const Vector3& axis) const;
+    Vector3 Orthogonalize(const Vector3& axis) const;
     Vector3 CrossProduct(const Vector3& rhs) const;
     Vector3 CrossProduct(const Vector3& rhs) const;
     Vector3 Abs() const;
     Vector3 Abs() const;
     Vector3 Lerp(const Vector3& rhs, float t) 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.
     /// Project vector onto axis.
     float ProjectOntoAxis(const Vector3& axis) const { return DotProduct(axis.Normalized()); }
     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.
     /// Calculate cross product.
     Vector3 CrossProduct(const Vector3& rhs) const
     Vector3 CrossProduct(const Vector3& rhs) const
     {
     {
@@ -403,15 +406,15 @@ public:
 
 
     /// Return as string.
     /// Return as string.
     String ToString() const;
     String ToString() const;
-    
+
     /// Return hash value for HashSet & HashMap.
     /// Return hash value for HashSet & HashMap.
-    unsigned ToHash() const 
-    { 
+    unsigned ToHash() const
+    {
         unsigned hash = 37;
         unsigned hash = 37;
         hash = 37 * hash + FloatToRawIntBits(x_);
         hash = 37 * hash + FloatToRawIntBits(x_);
         hash = 37 * hash + FloatToRawIntBits(y_);
         hash = 37 * hash + FloatToRawIntBits(y_);
         hash = 37 * hash + FloatToRawIntBits(z_);
         hash = 37 * hash + FloatToRawIntBits(z_);
-        
+
         return hash;
         return hash;
     }
     }