The above applet demonstrates a multicolored rotating cube in 3D.
By mouse clicking on the applet, you can change the rotation speed.
By using the keyboard, you can translate and rotate the viewpoint
in six dimensions: x, y, z, pitch, yaw, and roll.
Change cube rotation speed
The Java applet uses the
Java Binding for OpenGL (JOGL) application programming interface (API).
This permits the applet to take advantage of your graphics card for hardware
acceleration. The current frame rate is displayed in the lower left corner
of the applet. I have limited it to the round number of 100 frames per
second so that it will not use excess processor time.
In order to make all of these translations and rotations relative to the
current orientation of the viewer, I used
In the process, I developed a pure Java library of axis angle, matrix,
and quaternion classes for 3D math. Getting the math correct, especially
the signs and the order of operations, took some research and effort so I
wanted to document the library in this tutorial.
JoglModelImp (JOGL model implementation) processes the move request
message by passing the relative axis of translation or rotation and the
distance to translate or rotate to an instance of
JoglCameraImp maintains the viewer orientation, the "camera", as an
AxisAngle instance because that is the data structure that is used by
JoglRendererImp to make the OpenGL rendering call.
During a rotation update called by JoglModelImp,
JoglCameraImp converts the axis angle
representation in order to use
quaternion multiplication and then converts the result back
to axis angle representation again.
The Java code demonstrated here is available for you to reuse under the
terms of an Open Source license. You can download it from the
CroftSoft Code Library.
I included the "linksource" option when I generated the javadoc so you can
browse the source code directly from the javadoc by clicking on the class
name and method name links: