// Draw a simple house import java.awt.*; public class MyHouse extends BufferedApplet { /* The points[][][] array contains the shape of the house. Notice that I organized the points into several parts. In each part, successive points are connected by line segments to draw the house. You do not need to create your edges this way. Feel free to use any technique you want for connecting the points of your model. */ 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} }, { {-.2,-.95,0},{-.2,-.4,0},{.2,-.4,0},{.2,-.95,0} }, }; int width = 0, height = 0; double startTime = System.currentTimeMillis() / 1000.0; double t = 0; double a[] = {0,0,0}, b[] = {0,0,0}; int pa[] = {0,0}, pb[] = {0,0}; public void render(Graphics g) { width = getWidth(); height = getHeight(); g.setColor(Color.white); // MAKE A CLEAR WHITE BACKGROUND g.fillRect(0, 0, width, height); g.setColor(Color.black); // SET THE DRAWING COLOR TO BLACK animate(); // COMPUTE ANIMATION FOR THIS FRAME for (int i = 0 ; i < points.length ; i++) // LOOP THROUGH ALL THE SHAPES for (int j = 1 ; j < points[i].length ; j++) { // LOOP THROUGH ALL THE LINES IN THE SHAPE transform(points[i][j-1], a); // TRANSFORM BOTH ENDPOINTS OF LINE transform(points[i][j ], b); viewport(a, pa); viewport(b, pb); g.drawLine(pa[0], pa[1], pb[0], pb[1]); // DRAW ONE LINE ON THE SCREEN } } void animate() { double time = System.currentTimeMillis() / 1000.0 - startTime; /* In this applet I am doing the animation in a completely fake way. Your animation should be done using your Matrix class. */ t = .2 + .1 * Math.sin(4 * time); } void transform(double src[], double dst[]) { ///////// REPLACE THIS CODE WITH A METHOD CALL TO TRANSFORM THE POINT BY YOUR MATRIX dst[0] = t * src[0]; dst[1] = t * src[1]; dst[2] = t * src[2]; //////////////////////////////////////////////////////////////////////////////////// } public void viewport(double src[], int dst[]) { dst[0] = (int) ( 0.5 * width + src[0] * width ); dst[1] = (int) ( 0.5 * height - src[1] * width ); } }