Last time, we saw how to load a 3d skeletal model, skin a mesh on top of that model, and animate it using forward kinematics. However, we used the built-in java.awt.Graphics class to perform rasterization of transformed triangles. This limits our control over the rasterization process - it allows us to draw plain triangles with one color, period.
Proper looking 3d graphics requires several additional features. We would like to have smooth shading, where the colors at each vertex are blended together at the internal points of a triangle - this is especially useful to perform smooth lighting. We would also like to apply a 2d texture to each triangle, in order to approximate surface detail using bitmaps, rather than additional geometry, and have this modulated with the (smoothly blended) base color. Finally, we would also like to store and compute depth values, in order to perform proper hidden surface removal. To introduce these features, we are forced to throw out the basic rasterization support, and implement our own.
To rotate the object, we use a "virtual trackball" metaphor. Imagine that
the object was suspended in a large sphere; when you click on the screen with
the left button, the mouse grabs the appropriate location on the sphere.
Moving the mouse will rotate the sphere accordingly, and the object will rotate
with it. This allows for arbitrary rotations around two axes. To rotate
around the vector perpindicular to the screen, hold shift + left button.
The source is in the files: