Browse Source

Minor Math library cleanup. Inline short Ray functions.

Lasse Öörni 12 years ago
parent
commit
0a97b5824c
3 changed files with 18 additions and 21 deletions
  1. 3 3
      Source/Engine/Math/Plane.cpp
  2. 0 12
      Source/Engine/Math/Ray.cpp
  3. 15 6
      Source/Engine/Math/Ray.h

+ 3 - 3
Source/Engine/Math/Plane.cpp

@@ -31,17 +31,17 @@ const Plane Plane::UP(Vector3(0.0f, 1.0f, 0.0f), Vector3(0.0f, 0.0f, 0.0f));
 
 
 void Plane::Transform(const Matrix3& transform)
 void Plane::Transform(const Matrix3& transform)
 {
 {
-    *this = Transformed(transform);
+    Define(Matrix4(transform).Inverse().Transpose() * ToVector4());
 }
 }
 
 
 void Plane::Transform(const Matrix3x4& transform)
 void Plane::Transform(const Matrix3x4& transform)
 {
 {
-    *this = Transformed(transform);
+    Define(transform.ToMatrix4().Inverse().Transpose() * ToVector4());
 }
 }
 
 
 void Plane::Transform(const Matrix4& transform)
 void Plane::Transform(const Matrix4& transform)
 {
 {
-    *this = Transformed(transform);
+    Define(transform.Inverse().Transpose() * ToVector4());
 }
 }
 
 
 Matrix3x4 Plane::ReflectionMatrix() const
 Matrix3x4 Plane::ReflectionMatrix() const

+ 0 - 12
Source/Engine/Math/Ray.cpp

@@ -30,18 +30,6 @@
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
-Vector3 Ray::Project(const Vector3& point) const
-{
-    Vector3 offset = point - origin_;
-    return origin_ + offset.DotProduct(direction_) * direction_;
-}
-
-float Ray::Distance(const Vector3& point) const
-{
-    Vector3 projected = Project(point);
-    return (point - projected).Length();
-}
-
 Vector3 Ray::ClosestPoint(const Ray& ray) const
 Vector3 Ray::ClosestPoint(const Ray& ray) const
 {
 {
     // Algorithm based on http://paulbourke.net/geometry/lineline3d/
     // Algorithm based on http://paulbourke.net/geometry/lineline3d/

+ 15 - 6
Source/Engine/Math/Ray.h

@@ -43,10 +43,9 @@ public:
     }
     }
     
     
     /// Construct from origin and direction. The direction will be normalized.
     /// Construct from origin and direction. The direction will be normalized.
-    Ray(const Vector3& origin, const Vector3& direction) :
-        origin_(origin),
-        direction_(direction.Normalized())
+    Ray(const Vector3& origin, const Vector3& direction)
     {
     {
+        Define(origin, direction);
     }
     }
     
     
     /// Copy-construct from another ray.
     /// Copy-construct from another ray.
@@ -77,9 +76,19 @@ public:
     }
     }
     
     
     /// Project a point on the ray.
     /// Project a point on the ray.
-    Vector3 Project(const Vector3& point) const;
-    /// Return distance of a point from the ray
-    float Distance(const Vector3& point) const;
+    Vector3 Project(const Vector3& point) const
+    {
+        Vector3 offset = point - origin_;
+        return origin_ + offset.DotProduct(direction_) * direction_;
+    }
+
+    /// Return distance of a point from the ray.
+    float Distance(const Vector3& point) const
+    {
+        Vector3 projected = Project(point);
+        return (point - projected).Length();
+    }
+
     /// Return closest point to another ray.
     /// Return closest point to another ray.
     Vector3 ClosestPoint(const Ray& ray) const;
     Vector3 ClosestPoint(const Ray& ray) const;
     /// Return hit distance to a plane, or infinity if no hit.
     /// Return hit distance to a plane, or infinity if no hit.