import java.awt.*; /** Program: LitSurf19 Purpose: @author: Paul Garrett, garrett@math.umn.edu @version: 19, Tue Feb 18 15:35:14 CST 1997 */ public class LitSurf19 extends java.applet.Applet { final int xMax = 80; final int yMax = 40; float[] uPov, iPov, jPov; // coords in which to view int theHeight, theWidth; /* z-axis up, y-axis to right, x-axis 'out of board': this respects the right-hand rule... */ final double div = (double) .04; final float cos = (float) Math.cos(Math.PI * div); final float sin = (float) Math.sin(Math.PI * div); final float[][] uRotMx = {{1F,0F,0F}, {0F,cos,-sin}, {0F,sin,cos}}; final float[][] iRotMx = {{cos,0F,-sin}, {0F,1F,0F}, {sin,0F,cos}}; final float[][] jRotMx = {{cos,-sin,0F}, {sin,cos,0F}, {0F,0F,1F}}; float[][] theSurface; // 3D graph in native numbers z = f(x,y) final float xScale = 10F; final float yScale = 10F; final float zScale = 80F; int[][][] theProjection; // 2D projection, depending upon Light and POV float[] theLight; // (unit?) vector direction of light Color[] theColors; // depending on at least lighting... int[][][] theLighting; // for 2 triangles boolean[][][] queryVisible; // query visible from POV? final float theFunction(int firstIn, int secondIn) { return (float) (Math.sin(Math.PI * ((float) firstIn) / 20F) * Math.sin(Math.PI * ((float) secondIn) / 20F)) ; } final void computeQueryVisible() { queryVisible = new boolean[xMax+1][yMax+1][2]; float[] avector = new float[3]; float[] another = new float[3]; avector[0] = xScale; avector[1] = 0F; another[0] = 0F; another[1] = yScale; float[] crossp = new float[3]; for (int i=0; i 0) { queryVisible[i][j][0] = true; } else { queryVisible[i][j][0] = false; } avector[2] = zScale * (theSurface[i+1][j+1] - theSurface[i][j+1]); another[2] = zScale * (theSurface[i+1][j+1] - theSurface[i+1][j]); if (dotProduct(uPov, crossProduct(avector,another)) > 0) { queryVisible[i][j][1] = true; } else { queryVisible[i][j][1] = false; } } } } /* The following method computes the two components of * theLighting array to be the dot product of theLight vector with a normal vector * to the 'forward' resp. 'backward' triangle with flip-flop vertex there * See the formula below */ final void computeLighting() { theLighting = new int[xMax+1][yMax+1][2]; float[] avector = new float[3]; float[] another = new float[3]; avector[0] = xScale; avector[1] = 0F; another[0] = 0F; another[1] = yScale; float[] crossp = new float[3]; float len; for (int i=0; i