Homework 1

This assignment this week is very simple. First grab my Matrix3D.java class (it's the one on my NYU home page). Read through it, making sure you understand how it relates to what we discussed in class.

Then make a simple interactive applet that animates a square shape, rotating, translating and maybe scaling it. If you're ambitious, make it interactive, so that the square responds to a user's mouse movements in interesting ways.

If you want, you can create a class which extends my BufferedApplet class, and renders using the code below (it's entirely up to you):

   
   int[][] square = new int[4][2];
   int[] edge = {1,3,0,2}; // draw edge to this vertex 
   public void render(Graphics g) {
      for (int i = 0 ; i < 4 ; i++) {
	 square[i][0] = 200 * (i / 2) - 100;
	 square[i][1] = 200 * (i % 2) - 100;
         transform(square[i]);
      }
      g.setColor(Color.white);
      g.fillRect(0,0, bounds().width,bounds().height);
      g.setColor(Color.black);
      for (int i = 0 ; i < 4 ; i++) {
	 int j = edge[i];
         g.drawLine(150+square[i][0],150+square[i][1],
		    150+square[j][0],150+square[j][1]);
      }
   }

   Vector3D vec = new Vector3D();
   Matrix3D mat = new Matrix3D();
   void transform(int[] point) {

      vec.set(0, point[0]);
      vec.set(1, point[1]);

      mat.identity();

      // YOUR CODE GOES HERE

      vec.transform(mat);

      point[0] = (int)vec.get(0);
      point[1] = (int)vec.get(1);
   }