// SphersWithImag.cc // Ray Tracering Static Picture / Animation // 4 Sphers + small 2 Sphers + Triangle + ppm Image // Read image from . // Output to or for Static Picture, // Output to for Animation. // Copyright (C) 1997,1998,1999 Y.Nagatani #include #include "raytrace.h" void Sphers4and2 (int nFrame, int nMaxFrames, PPMRawImage & ppm) { Bool bAnimation = (nMaxFrames >= 2 ? True : False); Real rTime; if (bAnimation) rTime = (Real) nFrame / nMaxFrames; else rTime = 0; List LS; Real rT, rRefrac; Real rX, rY, rZ; Real rAngle; Spher S; // 4 Sphers rT = 10; // Radius of 4 Sphers rRefrac = 1.15; S = Spher (Vector (-rT/2,0,0), 5); S.setRGB (RGB(.02,.02,.05), RGB(.7,.7,.7), RGB(.8,.8,.8)); S.setRefraction (rRefrac); LS.add (S); S = Spher (Vector (+rT/2,0,0), 5); S.setRGB (RGB(.02,.05,.02), RGB(.6,.6,.6), RGB(.8,.8,.8)); S.setRefraction (rRefrac); LS.add (S); S = Spher (Vector (0,rT*sqrt(3)/2,0), 5); S.setRGB (RGB(.05,.02,.02), RGB(.6,.6,.6), RGB(.8,.8,.8)); S.setRefraction (rRefrac); LS.add (S); S = Spher (Vector (0,rT/sqrt(3)/2,rT*sqrt(2.0/3)), 5); S.setRGB (RGB(.04,.04,.04), RGB(.7,.7,.7), RGB(.8,.8,.8)); S.setRefraction (rRefrac); LS.add (S); // Patterned Triangle rT = 10; TrianglePatt T (-rT/2,0,0, +rT/2,0,0, 0,rT/2*sqrt(3),0); T.setRGB (RGB(.7,.2,.1), RGB(.7,.7,.7), 0); T += Vector (0,0,-5.001); LS.add (T); // Rotate & Translate Objects LS.RotateAxesLine (Line(Vector (0,rT/2/sqrt(3),0), Vector (0,rT/2/sqrt(3),1)), (bAnimation ? (rTime*120 - 60)*M_PI/180 : +132.0*M_PI/180)); LS.RotateAxesLine (Line(Vector (0,0,0), Vector (1,0,0)), -61.0*M_PI/180); LS.RotateAxesLine (Line(Vector (0,0,0), Vector (0,1,0)), +33.8*M_PI/180); LS += Vector (rT*0.12,-rT*sqrt(1.0/6),0); // Add Small New 2 Sphers S = Spher (Vector (+1.4142*rT,0,-rT), 2.1); S.setRGB (RGB(.03,.01,.01), RGB(0.8,0.8,0.8), RGB(0.6,0.6,0.6)); S.setRefraction (rRefrac); LS.add (S); S = Spher (Vector (-1.4142*rT,0,-rT), 2.1); S.setRGB (RGB(.01,.01,.03), RGB(0.8,0.8,0.8), RGB(0.6,0.6,0.6)); S.setRefraction (rRefrac); LS.add (S); // Quadrilateral Pic Image rAngle = 0; rT = 120; rX = rT * cos (rAngle); rY = rT / 1.25; rZ = rT * sin (rAngle); QuadrilateralImag Quad (0,0,0, rX,0,rZ, 0,rY,0, ppm); Quad += Vector (-rX/2, -rY*0.27, -rZ/2); Quad.setNoTranspareceWithoutBlack (True); // set black is transp. Quad.setRGB (0, 0, 0); Quad += Vector (0, 0, +50); // -60 for back ground 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 = (bAnimation ? 128 * 3 : 256 * 4); Real rAspect = 1.25; rAngle = 2.0 * M_PI * 0.0; 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 ((bAnimation ? 8 : 10)); // 0 is simplest case PS.setEps (); // as EPS PS.setShowStatus (); // show calculating status PS.setPPM (True); // as PPM not (ps / eps) char szFileNameHead [128]; if (bAnimation) sprintf (szFileNameHead, "x%03d", nFrame); else sprintf (szFileNameHead, "out"); PS.putImagFile (LS, szFileNameHead); } int main (int nArgc, char *pszArgv[]) { Check_rRand (); PPMRawImage ppm ("in.ppm"); #ifdef ANIMATION int nMax = 32; for (int n = 0 ; n < nMax ; n++) Sphers4and2 (n, nMax, ppm); #else Sphers4and2 (0, 1, ppm); #endif return 0; }