Homework due Wednesday, September 28

Look at the API we defined for matrices. This defines the public methods that an application programmer would call to make use of a basic library to support linear transformations.

Your task for next Wednesday is to implement such a library, and to test it to show that it works.

In order to implement these public methods of the Matrix class, you will also find it necessary to maintain some internal temporary "working data" areas like:

   double tmp1_data[4][4]
   double tmp2_data[4][4]
for keeping temporary results, as we discussed in class,

you will need to implement some other methods as well, such as:

void makeTranslation(double dst[][],double x,double y,double z) // make a translation matrix
void makeRotationX(double dst[][],double theta) // make a rotation matrix
void makeRotationY(double dst[][],double theta) // make a rotation matrix
void makeRotationZ(double dst[][],double theta) // make a rotation matrix
void makeScale(double dst[][],double x,double y,double z) // make a scale matrix
void rightMultiply(double src[][]) // right-multiply by another matrix

In order to test your results, you will want to create a simple Java applet that contains some points, and draws lines between them. You can use the eight vertices of a simple cube as your collection of points:

0: (-1,-1,-1) 1: (1,-1,-1)
2: (-1, 1,-1) 3: (1, 1,-1)
4: (-1,-1, 1) 5: (1,-1, 1)
6: (-1, 1, 1) 7: (1, 1, 1)

For now, you can draw the cube by drawing its twelve edges:

0→1 2→3 4→5 6→7
0→2 1→3 4→6 5→7
0→4 1→5 2→6 3→7

As we discussed in class, to figure out where a point is on the screen after it has been transformed, you need to do two things in succession:

Also as we discussed in class, we're going to fake the first of the above two steps, by using a camera with an orthogonal view from z = +∞. In other words, we're just going to throw out the z coordinate.

For the viewport transform (ie: mapping x,y coordinates to screen pixel coordinates) you need to do the following, as we said in class:

   int pixel_x = (int)(w / 2 + w * x / 2);
   int pixel_y = (int)(h / 2 - w * y / 2);

where w and h denote the width and height of the applet, and where x and y are the coordinate values of the point after you've done your matrix transformation.

Once you actually have pixel values for each of the eight vertices of your cube, you can just draw the edges between them using the same:

   g.drawLine(int ax,int ay,int bx,int by)

method that you've already been using.