/* Will Dietz dtzTech.com (c) 2004 This is subject to the GNU GPL license see http://www.gnu.org/licenses/gpl.txt for a copy of the license */ import java.applet.Applet; import java.awt.*; import java.awt.event.*; import javax.swing.*; //1152x 864 public class App6 extends Applet implements ActionListener { Timer t; final double FRAMERATE = 50; //Frames per second final int WIDTH = 1024, HEIGHT = 768; final double PI=Math.PI,ANGLE=30.0; public final int CX = WIDTH/2,CY = HEIGHT/2;//Middle of screen public final double ROTFACTOR=4,MOVFACTOR=6,ANG=.6; public final double PX=0,PY=800,PZ=1; public final double FACTOR = .6,CLOSERANGE=30; public Point PP= new Point(PX,PY,PZ);//,VP= new Point(PX,PY-200,PZ-100); public final double OFFX = 0, OFFY = -PY,OFFZ = -PZ; public Point LP= new Point(PX,PY,PZ); public Point OP = new Point(0,0,0),origin = new Point(0,0,0); public KeyStates key; public Vector vDir; public double[] arr,cc; public final int NUMOFCUBES=30; Prism c[] = new Prism[NUMOFCUBES]; public void init() { for (int a=0;aarr[a+1]) {//SWITCH: tmp = arr[a]; arr[a]=arr[a+1]; arr[a+1]=tmp; done = false; } } return arr; } public void paint(Graphics g) { // updateObjs(); Point lpp1,lpp2; Buffer.g.setColor(Color.black); Buffer.g.fillRect(0,0,WIDTH,HEIGHT); for (int a=NUMOFCUBES-1;a>=0;a--) for (int b=0;b1 g.drawImage(Buffer.img,0,0,this); } public boolean isMoveInvalid(double x,double y,double z) { Point p = new Point(PP.x+x,PP.y+y,PP.z+z); boolean bool; for (int i=0;iANG); } public void actionPerformed(ActionEvent ae) { updateObjs(); paint(this.getGraphics()); } void mov() { double yDiff=0; if (key.UP && arr[0]>CLOSERANGE)yDiff=-MOVFACTOR;//PP.y-=MOVFACTOR; if (key.DOWN)yDiff=MOVFACTOR;//PP.y+=MOVFACTOR; if (key.LEFT)rot(-ROTFACTOR,PP);//PP.x++; if (key.RIGHT)rot(ROTFACTOR,PP);//PP.x--; if(!isMoveInvalid(0,yDiff,0))PP.y+=yDiff; // Point p = new Point(PP.x,PP.y+yDiff,PP.z); cc = new double[NUMOFCUBES]; for (int count=0;countCLOSERANGE)PP.y+=yDiff; } void updateObjs() { mov(); LP = PP; vDir = new Vector(OP,PP); OP = new Point(PP.x-OFFX,PP.y-OFFY,PP.z-OFFZ); for (double a=0;a=0;a--) { for (int b=0;b<6;b++) { if (arr[a]==fc[b]) { //System.out.println("Face num: "+b); f[b].draw(g,center); } } } } public void rot(double d,Point relO) { for (int a=0;a<8;a++) { p[a].rot(d,relO); } update(); } void update() { update2D(); for (int a=0;a<4;a++) dist[a]=f[a].getDist(PP); dist=bubbleSort(dist); center = p[0].midPoint(p[6]); } boolean isTooClose(Point pointp) { double minD=10000000,dis; for (int a=0;a<4;a++) { dis = Math.abs(f[a].getDist(pointp)); if (minD>dis)minD=dis; } return (minD