import wonderlab.graphics.world.*;
import wonderlab.graphics.geometry.*;
import wonderlab.graphics.shape.*;
import wonderlab.graphics.renderer.*;
import wonderlab.graphics.camera.*;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Iterator;


public class hw7 extends World3D{

	Shape3D shape1,shape2,shape3, shape4, shape5;
	
	double z = -5;
	double x = 0;
	double y = 0;
	
	public hw7() {
		super();
		camera = new Camera(3);
		viewport = new Viewport(500, 500, camera);
		clippingPlanes.add(new ClippingPlane(new Vector3D(0,0,-1,1), new Vector3D(0,0,-.6,1)));
		//clippingPlanes.add(new ClippingPlane(new Vector3D(0,0,1,1), new Vector3D(0,0,-12,1)));
		shape1 = new Sphere();
 		shape2 = new Sphere();
 		shape3 = new Sphere();
 		shape4 = new Sphere();
 		shape5 = new Sphere();
		shapes.add(shape1);
		shapes.add(shape2);
		shapes.add(shape3);
		shapes.add(shape4);
		shapes.add(shape5);
		shape1.setMaterial(new Material(0.2,0.0,0.0, .6,.6,.2, .0,.0,.0,1.0));
		shape2.setMaterial(new Material(0.0,0.2,0.0, .2,.6,.2, .0,.0,.0,1.0));
		shape3.setMaterial(new Material(0.0,0.0,0.2, .2,.2,.6, .0,.0,.0,1.0));
		shape4.setMaterial(new Material(0.1,0.1,0.1, .1,.1,.1, .6,.6,.6,4.0));
		shape5.setMaterial(new Material(0.1,0.0,0.0, .8,.5,.5, .8,.5,.3,4.0));

		lights.add(new Light(-1, -1, 1, .6, .6, .6));
		lights.add(new Light(.5,1,-1, .3, .3, .3));
		camera.moveAbs(new Vector3D(0.0,0.0,0.0,1.0));

	}
	
	public void initFrame(double time) { // INITIALIZE ONE ANIMATION FRAME
			S.initialize();
			camera.initialize();
			resetScreen();
			animate();
			super.initFrame();
    }

	public void animate() {
			camera.m().inverse();
			S.m().copy(camera.m());
 			S.push();
				S.m().scale(0.5,0.5,0.5);
				S.m().translate(-1,0,-8);
				//S.m().rotateX(Math.PI/4);
				//S.m().rotateY(-0.01*time());
				shape1.update(S.m());
			S.pop();
			S.push();
				S.m().scale(0.5,0.5,0.5);
				S.m().translate(1,0,-8);
				//S.m().rotateX(Math.PI/4);
				//S.m().rotateY(-0.01*time());
				shape2.update(S.m());
			S.pop();				
			S.push();
				S.m().scale(0.5,0.5,0.5);
				S.m().translate(0,0,-6);
				//S.m().rotateX(Math.PI/4);
				//S.m().rotateY(-0.01*time());
				shape3.update(S.m());
			S.pop();				
			S.push();
				S.m().scale(0.5,0.5,0.5);
				S.m().translate(0,-1,-7);
				//S.m().rotateY(-0.01*time());
				shape4.update(S.m());
			S.pop();				
			S.push();
				S.m().scale(0.5,0.5,0.5);
				S.m().translate(0,1,-7);
				//S.m().rotateY(-0.01*time());
				shape5.update(S.m());
			S.pop();				
				
	}

			 
	// not used
   	public boolean mouseUp(Event e, int x, int y) {
		
      	return true;
   	}
   
   	public boolean mouseDrag(Event e, int x, int y) {
	 	return true;
   	}
   	   		
   	// handle key events
   	public boolean keyDown(Event e, int key) {
      switch (key) {
      	// UP ARROW 	-- zoom in
      	case '\u03EC':  y =  y - 0.2;
      			break;						
		// DOWN ARROW 	-- zoom out
      	case '\u03ED':  y = y + 0.2; 
      			break;
      	// LEFT ARROW
      	case '\u03EE':  x = x - 0.2; 	
      			break;		
      	// RIGHT ARROW
      	case '\u03EF': 	x = x + 0.2;
      			break;		
      	case '\u0020': 	
      			break;
      	case '.': 		z = z - 0.2;
      			break;		
      	case '/': 		z = z + 0.2;
      			break;
      	case 'd':		debug = !debug;
      			break;
      	case 'a':		animate = !animate;
				break;
		}
		System.out.println("xyz: " + x + " " + y + " " + z);
		return true;
	}

}