Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] Re: r2340 - trunk/Model/Intersections


Chronological Thread 
  • From: Solomon Boulos < >
  • To:
  • Subject: [Manta] Re: r2340 - trunk/Model/Intersections
  • Date: Thu, 23 Oct 2008 14:14:30 -0700

The CMakeLists.txt file is missing .h on the new Sphere code you added. This doesn't matter much (since the .h files aren't used in the makefile) but will affect Visual Studio users (Sphere.h won't show up in their project).

On Oct 23, 2008, at 2:07 PM, Thiago Ize wrote:

Author: thiago
Date: Thu Oct 23 15:07:20 2008
New Revision: 2340

Added:
  trunk/Model/Intersections/Sphere.h
Modified:
  trunk/Model/Intersections/CMakeLists.txt
Log:
Added a ray/Sphere intersection function.

Modified: trunk/Model/Intersections/CMakeLists.txt
= = = = = = = = ======================================================================
--- trunk/Model/Intersections/CMakeLists.txt    (original)
+++ trunk/Model/Intersections/CMakeLists.txt    Thu Oct 23 15:07:20 2008
@@ -4,4 +4,5 @@
    Intersections/IsosurfaceImplicit.h
    Intersections/TriangleEdge.h
    Intersections/Plane.h
+    Intersections/Sphere
)

Added: trunk/Model/Intersections/Sphere.h
= = = = = = = = ======================================================================
--- (empty file)
+++ trunk/Model/Intersections/Sphere.h  Thu Oct 23 15:07:20 2008
@@ -0,0 +1,37 @@
+#ifndef Manta_Model_Intersections_Sphere__H
+#define Manta_Model_Intersections_Sphere__H
+
+namespace Manta {
+  namespace Intersection {
+
+    // This is the single ray version.
+    inline bool intersectSphere(const Vector &center,//sphere center
+                                const Real radius,   //sphere radius
+                                const Ray &ray,      // Input Ray.
+                                Real &tmin,          // Output min t.
+                                Real &tmax           // Output max t.
+                                )
+    {
+      // Rays of constant origin for not normalized directions
+      Vector O(ray.origin()-center);
+      Real C = Dot(O, O) - radius*radius;
+      Real A = Dot(ray.direction(), ray.direction());
+      Real B = Dot(O, ray.direction());
+      Real disc = B*B-A*C;
+      if(disc >= 0){
+        Real r = Sqrt(disc);
+        Real tmin = -(r+B)/A;
+        Real tmax = (r-B)/A;
+        if (tmax < tmin) {
+          Real temp = tmax;
+          tmax = tmin;
+          tmin = temp;
+        }
+        return true;
+      }
+      return false;
+    }
+  }
+}
+
+#endif




Archive powered by MHonArc 2.6.16.

Top of page