Classes
HierarchicalApplet
This is the main applet. It creates a user interface and a canvas which do
all of the work, and maintains some state variables that allow these two
components to coordinate their activities.
Matrix44
This class provides various useful 3-D matrix operations:
scale,rotate,translate,camera transform, and perspective transform
and applies them to points.
WorldPoint
This class provides the application with homogeneous points in 3-space.
Homogeneous coordinates are convenient because they allow 3-D
transformations to be represented as matrix operations.
DisplayObject
This is a generic base class for objects that can display themselves.
It provides a generic interface for adding child objects, removing
child objects and inserting lightweight objects into the object
hierarchy.
DisplayRect
This is a basic derived class of DisplayObject that implements a simple
rectangular prism.
DisplayPyramid
This is another derivation of DisplayObject that represents a rectangular-
base pyramid.
DisplaySphere
This is another derivation of DisplayObject that represents a sphere.
It is more interesting that some of the other classes however, because
it works by creating a grid and then applying a parametric transform to
it to give the sphere affect.
DisplayTorus
Like the sphere, the torus is a derivation of the DisplayObject that
creates a grid and applies a parametric transform to it.
DisplayPlane
This is once again a simple derivation of DisplayObject that represents
a plane.
GUIPanel
This class implements the user interface for the applet. It has several
buttons that allow the user to control the hierarchy of the objects that the
applet is representing. It also allows the user to change the current object
by changing its model, scaling, translation, and angle.
InputDialog
Java applets don't explicitly support dialog windows. In fact, there are some
problems related to applets creating child windows. This class take care
of some of those concerns. It gets around the child window restriction and
maintains the appearance of being a modal dialog window through its interaction
with the GUIPanel class. The dialog basically supports a text input box to
allow the user to name and rename objects in the hierarchy.
PaintCanvas
This class draws the actual data and deals with dragging the mouse
to move the camera angle. Basically, this class keeps track of the mouse
in order to determine the user's camera angle. When this angle changes
it redraws the object. Otherwise, it redraws the object based on specific
requests from the GUIPanel which makes such requests when the user has
added or removed an object from the hierarchy or modified the parameters
of an object in such a way as to require redrawing.
When a redraw request occurs, the canvas asks the toplevel object in the
hierarchy to output all of the line segments that need to be drawn. The
coordinates of these points are in world coordinates so the canvas
applies the camera transform to them, followed by the perspective
transform and then actually paints the line segments.
Source Code