//
import java.util.*; public class SimpleRayTracer extends PixApplet { Vector shapes = new Vector(); public void init() { super.init(); shapes.addElement(new Sphere( .07,.06,-2,.07)); shapes.addElement(new Sphere(-.07,.06,-2,.07)); shapes.addElement(new Sphere(0,0,-2.02,.1)); } public void setPix(int frame) { double focal_length = 3.5; // FOCAL LENGTH OF "LENS" double v[] = {0,0,0}; // VIEW POINT double w[] = {0,0,-focal_length}; // RAY DIRECTION double t[] = new double[2]; // PLACE TO STORE ROOTS double p[] = {0,0,0}; // SURFACE POINT double n[] = {0,0,0}; // SURFACE NORMAL // LOOP THROUGH PIXELS OF IMAGE for (int row = 0 ; row < H ; row++) for (int col = 0 ; col < W ; col++) { // CONSTRUCT RAY DIRECTION VECTOR w[0] = col / (double)W - 0.5; w[1] = -row / (double)W + 0.5 * H / W; // LOOP THROUGH ALL SHAPES Shape nearest_s = null; double nearest_t = 1000000; for (int i = 0 ; i < shapes.size() ; i++) { Shape s = (Shape)shapes.elementAt(i); if (s.traceRay(v,w,t)>0 && t[0]>0 && t[0]