/* 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.*; public class App3 extends Applet implements ActionListener { // Box b,b2; // Line l,l2; Timer t; final double FRAMERATE = 50; //Frames per second final int WIDTH = 800, HEIGHT = 600; final double PI=Math.PI,ANGLE=30.0; public final int CX = WIDTH/2,CY = HEIGHT/2; // public int CX,CY; public final double PX=0,PY=1500,PZ=1000; public final double FACTOR = 1,CLOSERANGE=10; 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); public KeyStates key; //Prism c1 = new Prism(new Point(60,60,-60),new Point(100,100,60),Color.blue), // c2 = new Prism(new Point(-30,-30,-30),new Point(30,30,30),Color.red), // c3 = new Prism(new Point(0,-50,0),new Point(20,-70,20),Color.green); public final int NUMOFCUBES=30; Prism c[] = new Prism[NUMOFCUBES]; // Point[] lp1 = new Point[50],lp2 = new Point[50]; // Graphics gr; // Image img; // Graphics dblBuffer; /* public void update() { // paint(this.getGraphics());; } public void repaint() {//Define as null to prevent it from doing anything }*/ public void init() { // l = new Line(0,-100000,0,100000); // l2 = new Line(-100000,0,100000,0); // b = new Box(new Point(20,20,0),new Point(40,40,0)); // b2 = new Box(new Point(10,-10,0),new Point(-10,10,0)); // for (int a=0;a<50;a++) // { // lp1[a] = new Point((a-25)*50,1000,0); // lp2[a] = new Point((a-25)*50,-1000,0); // } for (int a=0;aarr[a+1].getDistPP()); {//SWITCH: tmp = arr[a]; arr[a]=arr[a+1]; arr[a+1]=tmp; done = false; } } } return arr; }*/ public double[] bubbleSort(double[] dbl) { double[] arr = new double[dbl.length]; 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(); // Buffer.img = createImage(WIDTH,HEIGHT); // Buffer.g = Buffer.img.getGraphics(); // PP= new Point(PX,PY,PZ); // LP=PP; Point lpp1,lpp2; Buffer.g.clearRect(0,0,WIDTH,HEIGHT); Buffer.g.setColor(Color.black); // for (int a=0;a<50;a++) // { // lpp1=lp1[a].point2D(); // lpp2=lp2[a].point2D(); // Buffer.g.drawLine((int)(CX+lpp1.x),(int)(CY-lpp1.y),(int)(CX+lpp2.x),(int)(CY-lpp2.y)); // } double[] cc = new double[NUMOFCUBES]; for (int count=0;count=0;a--) for (int b=0;b1) c[b].draw(Buffer.g); // System.out.println(); /* c1.draw(dblBuffer); c2.draw(dblBuffer); c3.draw(dblBuffer); */ // g.clearRect(0,0,WIDTH,HEIGHT); g.drawImage(Buffer.img,0,0,this); // System.out.println(); // g.drawLine(CX-1,CY-1,CX+1,CY+1); //Draw Origin } /* public double per(Point p1,Point p2,Point pp) { double d1,d2,d3; d1=pp.dist(p1); d2=pp.dist(p2); d3=p1.dist(p2); return 2.0*triArea(d1,d2,d3)/(d1>d2?d1:d2); } double triArea(double s1,double s2,double s3) { double s = (s1+s2+s3)/2.0; return Math.sqrt(s*(s-s1)*(s-s2)*(s-s3)); } */ public boolean isInView(Point p) { return (p.y=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); } } } // System.out.println("one: "+one+", two: "+two+", three: " // + three+", four: "+four+", five: "+five+", six: "+six+"\n"); /* b1.draw(g); b2.draw(g); b3.draw(g); b4.draw(g); b5.draw(g); b6.draw(g);*/ } public void rot(double d) { for (int a=0;a<8;a++) { p[a].rot(d); } update(); } void update() { update2D(); for (int a=0;a<4;a++) dist[a]=f[a].getDistPP(); dist=bubbleSort(dist); center = p[0].midPoint(p[6]); } void update2D() { for (int a=0;a<8;a++) { p2D[a]=p[a].point2D(); } } } class Face { // int[] p; int[] p; int len; Point[] pp,p2; // Color faceColor; int red,green,blue; // Color shade; Color shade; // Vector norm,light; /* public Face() { new Face(new Point(0,0,0),new Point(0,0,0)); } public void update() { center = p1.midPoint(p2).midPoint(p3.midPoint(p4));//new Point((p1.x+p3.x)/2,(p1.y+p3.y)/2,(p1.z+p3.z)/2); } /* public void movAwayY(int d) { p1.y+=d; p2.y+=d; p3.y+=d; p4.y+=d; update(); } public void movAwayX(int d) { p1.x+=d; p2.x+=d; p3.x+=d; p4.x+=d; update(); }*/ public boolean equals(Face f) { return (f.p==p&&f.pp==pp); } public Face(int[] pts,Point[] ppp,Point[] pp2,Color col) { len=pts.length; p = pts; for (int a=0;a