Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r990 - trunk/Model/Primitives


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r990 - trunk/Model/Primitives
  • Date: Wed, 15 Mar 2006 14:21:35 -0700 (MST)

Author: bigler
Date: Wed Mar 15 14:21:34 2006
New Revision: 990

Modified:
   trunk/Model/Primitives/Cylinder.cc
   trunk/Model/Primitives/Cylinder.h
Log:

Cylinder.cc

  Initialize xform and ixform in constructor.

  double -> Real

  Use T_EPSILON instead of 1.e-6.  Fixes some speckles in shadowed
  regions.  I think the shadows are correct, but I'm having a hard
  time verifying it.

Cylinder.h

  Radius in constructor should be a Real instead of double.




Modified: trunk/Model/Primitives/Cylinder.cc
==============================================================================
--- trunk/Model/Primitives/Cylinder.cc  (original)
+++ trunk/Model/Primitives/Cylinder.cc  Wed Mar 15 14:21:34 2006
@@ -3,13 +3,27 @@
 #include <Core/Geometry/BBox.h>
 #include <Core/Exceptions/BadPrimitive.h>
 
+#include <Core/Math/Expon.h>
+
 using namespace Manta;
+using namespace SCIRun;
 using namespace std;
 
 Cylinder::Cylinder(Material* mat, const Vector& bottom, const Vector& top,
                    Real radius)
   : PrimitiveCommon(mat, this), bottom(bottom), top(top), radius(radius) 
 {
+  Vector axis(top-bottom);
+  Real height = axis.normalize();
+  // Set up unit transformation
+  xform.initWithTranslation(-bottom);
+  xform.rotate(axis, Vector(0,0,1));
+  Real inv_radius = 1/radius;
+  xform.scale(Vector(inv_radius, inv_radius, 1/height));
+  // And the inverse for normals and what not
+  ixform.initWithScale(Vector(radius, radius, height));
+  ixform.rotate(Vector(0,0,1), axis);
+  ixform.translate(bottom);
 }
 
 Cylinder::~Cylinder()
@@ -28,36 +42,36 @@
 {
   for(int i=rays.begin(); i<rays.end(); i++) {
     Vector v(xform.multiply_vector(rays.getDirection(i)));
-    double dist_scale=v.normalize();
+    Real dist_scale=v.normalize();
     Ray xray(xform.multiply_point(rays.getOrigin(i)), v);
-    double dx=xray.direction().x();
-    double dy=xray.direction().y();
-    double a=dx*dx+dy*dy;
-    if(a >= 1.e-6) {
+    Real dx=xray.direction().x();
+    Real dy=xray.direction().y();
+    Real a=dx*dx+dy*dy;
+    if(a >= T_EPSILON) {
       // Check sides...
-      double ox=xray.origin().x();
-      double oy=xray.origin().y();
-      double oz=xray.origin().z();
-      double dz=xray.direction().z();
-
-      double b=2*(ox*dx+oy*dy);
-      double c=ox*ox+oy*oy-1;
-      double d=b*b-4*a*c;
-      if(d>0.0) {
-       double sd=sqrt(d);
-       double t1=(-b+sd)/(2*a);
-       double t2=(-b-sd)/(2*a);
+      Real ox=xray.origin().x();
+      Real oy=xray.origin().y();
+      Real oz=xray.origin().z();
+      Real dz=xray.direction().z();
+
+      Real b=2*(ox*dx+oy*dy);
+      Real c=ox*ox+oy*oy-1;
+      Real d=b*b-4*a*c;
+      if(d>T_EPSILON) {
+       Real sd=Sqrt(d);
+       Real t1=(-b+sd)/(2*a);
+       Real t2=(-b-sd)/(2*a);
        
        if(t1>t2){
-         double tmp=t1;
+         Real tmp=t1;
          t1=t2;
          t2=tmp;
        }
-       double z1=oz+t1*dz;
-       double z2=oz+t2*dz;
-       if(t1 > 1.e-6 && z1 > 0.0 && z1 < 1.0){
+       Real z1=oz+t1*dz;
+       Real z2=oz+t2*dz;
+       if(t1 > T_EPSILON && z1 > 0 && z1 < 1){
          rays.hit(i, t1/dist_scale, getMaterial(), this, 
getTexCoordMapper());
-       } else if(t2 > 1.e-6 && z2 > 0.0 && z2 < 1.0){
+       } else if(t2 > T_EPSILON && z2 > 0 && z2 < 1){
          rays.hit(i, t2/dist_scale, getMaterial(), this, 
getTexCoordMapper());
        }
       }

Modified: trunk/Model/Primitives/Cylinder.h
==============================================================================
--- trunk/Model/Primitives/Cylinder.h   (original)
+++ trunk/Model/Primitives/Cylinder.h   Wed Mar 15 14:21:34 2006
@@ -13,7 +13,7 @@
   class Cylinder : public PrimitiveCommon, public TexCoordMapper {
   public:
     Cylinder(Material* mat, const Vector& bottom, const Vector& top,
-            double radius);
+            Real radius);
     virtual ~Cylinder();
     
     virtual void computeBounds(const PreprocessContext& context,




  • [MANTA] r990 - trunk/Model/Primitives, bigler, 03/15/2006

Archive powered by MHonArc 2.6.16.

Top of page