Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2340 - trunk/Model/Intersections


Chronological Thread 
  • From: "Thiago Ize" < >
  • To:
  • Subject: [Manta] r2340 - trunk/Model/Intersections
  • Date: Thu, 23 Oct 2008 15:07:22 -0600 (MDT)

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