//
// Draw a simple house

import java.awt.*;

public class House extends BufferedApplet {
	double points[][] = { { -.9, -1, 0 }, {
			1, -1, 0 }, {
			1, .8, 0 }, {
			0, 1.5, 0 }, {
			-1, .8, 0 }, {
			-1, -1, 0 }, {
			.9, .8, 0 }, {
			-.9, .8, 0 }, {
			.9, -.9, 0 }
	};

	double a[] = { 0, 0, 0 }, b[] = { 0, 0, 0 };
	int w, h;

	public void render(Graphics g) {

		
		w = bounds().width; // FIND OUT HOW BIG THE APPLET WINDOW IS
		h = bounds().height;

		g.setColor(Color.white); // MAKE A CLEAR WHITE BACKGROUND
		g.fillRect(0, 0, w, h);

		g.setColor(Color.black); // SET THE DRAWING COLOR TO BLACK

		for (int i = 1;
			i < points.length;
			i++) { // LOOP THROUGH ALL THE LINES IN THE SHAPE
			transform(points[i - 1], a); // TRANSFORM BOTH ENDPOINTS OF LINE
			transform(points[i], b);
			g.drawLine(x(a[0]), y(a[1]), x(b[0]), y(b[1]));
			// DRAW ONE LINE ON THE SCREEN
		}
	}

	//	CONVERT X COORDINATE TO SCREEN PIXELS
	int x(double t) {
		return w / 2 + (int) (t * w / 4);
	}

	//	CONVERT Y COORDINATE TO SCREEN PIXELS
	int y(double t) {
		return h / 2 - (int) (t * w / 4);
	}

	void transform(double src[], double dst[]) {

		///////// THIS IS THE PART YOU SHOULD REPLACE, TO DO COOL TRANSFORMATIONS  /////////
	
		Matrix3D transformer = new Matrix3D();
		transformer.translate(-1,0,0);
		transformer.rotateZ(Math.PI);
		transformer.rotateX(Math.PI/4);
		transformer.rotateY(Math.PI/4);
		transformer.scale(0.5,2,0);
		double[] point = transformer.transform(src);

		dst[0] = point[0];
		dst[1] = point[1];
		dst[2] = point[2];
		////////////////////////////////////////////////////////////////////////////////////
	}
}