// SphereInside.cc // Ray Tracing Animation: the moving PPM Image in a Spherical Mirror // Read image from and output to or // Copyright (C) 1997,1998,1999,2003 Y.Nagatani #include "raytrace.h" #include "timerecord.h" Bool SphereInside (int nFrame, PPMImage & ppm) { Real rTimeDistance, rTimeAngle; if (nFrame < 0 + 16) { Real rT = (Real) (nFrame - 0) / 16; rTimeDistance = 0.2 * rT; rTimeAngle = 0; } else if (nFrame < 16 + 48) { Real rT = (Real) (nFrame - 16) / 48; rTimeDistance = 0.2; rTimeAngle = rT; } else if (nFrame < 64 + 32) { Real rT = (Real) (nFrame - 64) / (32 - 1); rTimeDistance = 0.2 + (0.98 - 0.2) * rT; rTimeAngle = 1; } else { return False; } List LS; Real rX, rY, rZ; Real rAngle; // Outer Large Spherical Mirror Real rRadius = 100; Real rReflRate = 1.0; // Perfect Reflector // Real rReflRate = 0.9; // Reflection Rate: 90% Sphere S = Sphere (Vector (0,0,0), rRadius); S.setRGB (RGB(0,0,0), RGB(rReflRate), RGB(0,0,0)); S.setRefraction (1.0); LS.add (S); // Quadrilateral Pic Image Real rSqSize = 30; rAngle = 2.0 * M_PI * rTimeAngle; rX = rSqSize; rY = rSqSize / 1.25; QuadrilateralImag Quad (0,0,0, rX,0,0, 0,rY,0, ppm); Quad += Vector (rX, rY, 0) * (-0.5); // Quad.setRGB (0, 0, RGB(1,1,1)); Quad.setNoTranspareceWithoutBlack (True); // set black is transp. Quad.RotateAxesLine (Line (0,0,0, 0,1,0), -rAngle); Quad += Vector (0, 0, -100 * rTimeDistance); LS.add (Quad); // Back Ground Light LS.setBackGround (RGB (0,0,0)); int nMatrixSize = 256; Real rAspect = 1.25; rAngle = 2.0 * M_PI * 20/360; rX = sin (rAngle); rZ = cos (rAngle); PostScript PS (Line (40*rX,0,40*rZ, 0,0,0), // center view line Vector (12*rZ, 0, -12*rX) * rAspect, // x direction (width) Vector ( 0, 12, 0), // y direction (height) (int)(rAspect*nMatrixSize), nMatrixSize); // Matrix Size PS.setRecursiveLevel (256); // when Refl Rate = 1.0 // PS.setRecursiveLevel (53); // when Refl Rate = 0.9 PS.setPPM (True); // as PPM neither PS nor EPS PS.setShowStatus (); // show calculating status char szFileNameHead [128]; sprintf (szFileNameHead, "x%03d", nFrame); PS.putImagFile (LS, szFileNameHead); return True; } int main (int nArgc, char *pszArgv[]) { Check_rRand (); PPMImage ppm ("in.ppm"); TimeRecord TR; cerr << "Time: " << TR << endl; for (int n = 0 ; SphereInside (n, ppm) ; n++) cerr << "Time: " << TR << endl; return 0; }