import java.awt.*; /** Program: LitSurface100 Purpose: @author: Paul Garrett, garrett@math.umn.edu @version: 100, Mon Feb 17 21:55:30 CST 1997 */ public class LitSurface100 extends java.applet.Applet { final int xMax = 60; 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) .05; 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) // float[][][] theTriangles; // grid of triples of points // may use theSurface to compute final float xScale = 8F; final float yScale = 10F; final float zScale = 80F; int[][][] theProjection; // 2D projection, depending upon Light and POV final float[] theLight = {0F,0F,1F}; // (unit?) vector direction of light Color[] theColors; // depending on at least lighting... int[][][] theLighting; // for 2 triangles final float theFunction(int firstIn, int secondIn) { return (float) Math.sin(Math.PI * ((float) (firstIn*secondIn)) / 400F); } /* 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] = 1F; avector[1] = 0F; another[0] = 0F; another[1] = 1F; float[] crossp = new float[3]; float len; for (int i=0; i