/** * SimpleCamera implements the simple camera where the VPN is along * -Z, VUV is Y and the COP is on Z. A viewport is specified on * the XY plane. * * @author Anthony Steed * @version 1.0 */ public class SimpleCamera { /* * Hold the dimensions of the viewport */ private double Xmin, Xmax, Ymin, Ymax; /* * Hold the resolution of rays to cast */ private int xResolution, yResolution; /* * Centre of projection along z-axis */ private double Zcop; /* * Hold the ray pitch and offset for centre of first pixel */ private double Width, Height, Wo2, Ho2; /** * Create a basic camera with resolution of 100 by 100 */ public SimpleCamera() { initBasic(100,100); } /** * Create a basic camera with given resolution * @param x the number of rays across * @param y the number of rays down */ public SimpleCamera(int x, int y) { initBasic(x,y); } /* * Create the basic camera */ protected void initBasic(int x, int y) { xResolution = x; yResolution = y; Zcop = 1.0; setVPWindow(-1.0,1.0,-1.0,1.0); } /** * Set the viewport window on the XY plane * @param xmin the minimum x value * @param xmax the maximum x value * @param ymin the minimum y value * @param ymax the maximum y value */ public void setVPWindow(double xmin, double xmax, double ymin, double ymax) { Xmin = xmin; Xmax = xmax; Ymin = ymin; Ymax = ymax; Width = (Xmax-Xmin)/(double)xResolution; Wo2 = Width/2.0; Height = (Ymax-Ymin)/(double)yResolution; Ho2 = Height/2.0; } /** * Set the centre of projection on the Z axis * @param cop the COP z value */ public void setCOP(double cop) { Zcop = cop; } /** * Set the resolution of the camera in terms of the number of rays * to cast. * @param x the number of rays across * @param y the number of rays down */ public void setResolution(int x, int y) { xResolution = x; yResolution = y; Width = (Xmax-Xmin)/(double)xResolution; Wo2 = Width/2.0; Height = (Ymax-Ymin)/(double)xResolution; Ho2 = Height/2.0; } /** * Get the ray number i, j from the camera model * @param i the x index of the ray to create * @param j the y index of the ray to create * @return a new ray as specified by the camera */ public Ray ray(int i, int j) { Ray ray = new Ray(); ray.Direction.set(Xmin+((double)i)*Width+Wo2, Ymax-((double)j)*Height-Ho2,-Zcop); ray.Origin.set(0.0,0.0,Zcop); return ray; } }