Browse Source

Reverting my fix of Darryl's fix of Ray.intersects(Plane) and using the method correctly in Form this time.

Adam Blake 14 years ago
parent
commit
184d7c339d
2 changed files with 3 additions and 3 deletions
  1. 1 1
      gameplay/src/Form.cpp
  2. 2 2
      gameplay/src/Ray.cpp

+ 1 - 1
gameplay/src/Form.cpp

@@ -327,7 +327,7 @@ namespace gameplay
                     const float& a = normal.x; const float& b = normal.y; const float& c = normal.z;
                     const float d = -(a*min.x) - (b*min.y) - (c*min.z);
                     const float distance = abs(d) /  sqrt(a*a + b*b + c*c);
-                    Plane plane(normal, distance);
+                    Plane plane(normal, -distance);
 
                     // Check for collision with plane.
                     float collisionDistance = ray.intersects(plane);

+ 2 - 2
gameplay/src/Ray.cpp

@@ -107,7 +107,7 @@ float Ray::intersects(const Plane& plane) const
 {
     const Vector3& normal = plane.getNormal();
     // If the origin of the ray is on the plane then the distance is zero.
-    float alpha = plane.getDistance() - normal.dot(_origin);
+    float alpha = (normal.dot(_origin) + plane.getDistance());
     if (fabs(alpha) < MATH_EPSILON)
     {
         return 0.0f;
@@ -124,7 +124,7 @@ float Ray::intersects(const Plane& plane) const
     
     // Calculate the distance along the ray's direction vector to the point where
     // the ray intersects the plane (if it is negative the plane is behind the ray).
-    float d = alpha / dot;
+    float d = -alpha / dot;
     if (d < 0.0f)
     {
         return INTERSECTS_NONE;