// SphersInside.cc // Ray Tracing Animation of the moving PPM Image in Spher // Read image from and output to or // Copyright (C) 1997,1998,1999 Y.Nagatani #include #include "raytrace.h" inline Real r01Bound (Real f) { if (f < 0) return 0.0; if (f > 1.0) return 1.0; return f; } void Ball4and2 (int nFrame, int nMaxFrames, PPMRawImage & ppm) { Real rTime = (Real) nFrame / nMaxFrames; // Real rTime1 = r01Bound (2*rTime), // rTime2 = r01Bound (2*rTime - 1); Real rTimeDistance, rTimeAngle; Real rTimeSwitch = 0.1; if (rTime < rTimeSwitch) { rTimeDistance = 2 * rTime; rTimeAngle = 0; } else if (rTime < 0.5 + rTimeSwitch) { rTimeDistance = 2 * rTimeSwitch; rTimeAngle = 2 * (rTime - rTimeSwitch); } else { rTimeDistance = 2 * (rTime - 0.5); rTimeAngle = 1; } List LS; Real rRadius, rRefrac; Real rX, rY, rZ; Real rAngle; Spher S; // Outer Large Spher Mirror rRadius = 100; rRefrac = 1.0; S = Spher (Vector (0,0.0,0.0), rRadius); S.setRGB (RGB(.0,.0,.0), RGB(.8,.8,.8), RGB(.0,.0,.0)); S.setRefraction (rRefrac); LS.add (S); // Quadrilateral Pic Image Real rSqSize = 30; rAngle = 2.0 * M_PI * rTimeAngle; rX = rSqSize * cos (rAngle), rY = rSqSize / 1.25; rZ = rSqSize * sin (rAngle); QuadrilateralImag Quad (0,0,0, rX,0,rZ, 0,rY,0, ppm); Quad.setNoTranspareceWithoutBlack (True); // set black is transp. Quad += Vector (-rX*0.5, -rY*0.5, -rZ*0.5); Quad.setRGB (0, 0, RGB(1,1,1)); Quad += Vector (0, 0, -100 * rTimeDistance); LS.add (Quad); // Back Ground Light LS.setBackGround (RGB ( .0, .0, .0)); LS.setBackGroundDir (Vector (2,-1,-1), RGB (.5,.6,.7), 10); 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 (10); // 0 is most simple case // 6 org PS.setEps (); // as EPS PS.setShowStatus (); // show calculating status PS.setPPM (True); // as PPM not (ps / eps) char szFileNameHead [128]; sprintf (szFileNameHead, "x%03d", nFrame); PS.putImagFile (LS, szFileNameHead); } int main (int nArgc, char *pszArgv[]) { Check_rRand (); PPMRawImage ppm ("in.ppm"); int nMax = 64; for (int n = 0 ; n < nMax ; n++) Ball4and2 (n, nMax, ppm); return 0; }