Text archives Help
- 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 ¢er,//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
- [Manta] r2340 - trunk/Model/Intersections, Thiago Ize, 10/23/2008
Archive powered by MHonArc 2.6.16.