Homework 9

  1. Write a Java method that implements a camera view transform. You should be able to pass it an eye point E and an aim point A (each as a Vector3D object), and the method should return (or else fill in the value of) a Matrix3D object which transforms points so that:

    As we went over in class, the math for this consists of two stages:

    1. Create an orthonormal matrix that translates (0,0,0) to E, and that transforms the z direction to align with the vector from A to E,

    2. Invert the above matrix.

    You can do the first step above by calculating:

    Z' = normalize(E - A)
    X' = normalize(Y × Z')
    Y' = normalize(Z' × X')
    in order to create the matrix:
    X'xY'xZ'xEx
    X'yY'yZ'yEy
    X'zY'zZ'zEz
    0 0 0 1

    The inverse of the above orthonormal matrix is then given by:

    X'xX'y X'z-(E · X')
    Y'xY'y Y'z-(E · Y')
    Z'xZ'y Z'z-(E · Z')
    0 0 0 1

  2. Write a Java method that implements a perspective transform, which is generally invoked after a camera view transform. Your method should take the distance f at which the (x,y) scale is preserved, as well as a point (as a Vector3D object) which is to be transformed. Any point (x,y,z) should be transformed to ( fx/z , fy/z , 1/z ).

  3. Demonstrate your work by writing a simple Applet that views a scene consisting of a cube centered at the origin. Render the cube by drawing its 12 edges as vectors. Your applet should be able to show the cube in perspective as seen from various eye points. Just set the Aim point to (0,0,0). Use any method you like for choosing different eye points.