Graphics Reference
In-Depth Information
Figure 15.1 is a screenshot of running Tutorial 15.1. At the lower portion of the
application window, we see all the camera and viewing frustum controls from
Tutorial 14.3, and on the right we see the familiar 2D GUI controls for scene
nodes, XformInfo , and primitive attributes (e.g., from Tutorial 11.7).
The two squares are defined based on the existing PrimitiveRectangleXZ
class. The LargeSq and SmallSq nodes present initial identity transformation
operators to allow the user to interactively manipulate the two squares. Now,
select the LargeSq node and activate the rotation radio button. Now, if we adjust
the x slider bar, as expected we can see the large square rotate with respect to the
x -axis of the orthonormal basis. Leave the x slider bar at some nonzero value,
e.g., at x
Figure 15.1.
Tutorial
15.1.
50. Now, adjust the z slider bar. We can see the square rotating
with respect to the center of the square, but not with respect to the z -axis of the
orthonormal basis. If we leave the z slider bar at some nonzero value (e.g., z
=
65)
and start adjusting the y slider bar, we will see that the square seems to rotate
quite arbitrarily with no obvious relationship to the orthonormal basis. At this
point, it is virtually impossible to interactively control the rotation of this square.
In computer graphics, we refer to this situation as the gimbal lock. As mentioned,
we will learn about 3D rotation in detail in the next chapter.
As described, the UWB _ Camera class only stores the parameters for the current
camera and view frustum settings. It is up to the WindowHandler class to inter-
pret the parameters, compute the transformation matrices, and load the graphics
API matrix processors. Recall that to properly support graphics API-independent
programming, we have designed the WindowHandler to be a hierarchy. In this
case, the new 3D responsibility is spread among the classes:
=
Class
Purpose
New functions in 3D
UWB _ WindowHandler
API-independent
Set/Get Camera
Compute/Load
UWBD3D _ WindowHandler
D3D-specific
View/Projection
( subclass of UWB _ WindowHandler )
matrix processors
Output only
CDrawOnlyHandler
DrawGraphics()
Input/Output
Service mouse events
CDrawAndMouseHandler
( subclasses of UWBD3D _ WindowHandler )
Application-specific
Listing 15.7 shows the implementation of the API-independent UWB _ WindowHand
ler class. At label C, we see an instance of the API-independent UWB _ Camera
and the corresponding support functions at label A. At label B are important
functions that require graphics API knowledge. The implementation of these
functions is deferred to API-specific subclasses. The implementation source file,
uwbgl _ WindowHandler5.cpp at the lower half of Listing 15.7,
shows the
 
Search WWH ::




Custom Search