Click for manipulateProjectionMatrix.cpp Program Windows Project
E
xper
iment
18.1. Run manipulateProjectionMatrix.cpp, a simple modification of manipulateModelviewMatrix.cpp of Chapter 5. Figure 18.4 is a screenshot, though the output to the OpenGL window is of little interest. Of interest, though, are the new statements in the resize() routine that output the current projection matrix just before and after the call glFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 100.0).Compare the second matrix output to the command window with P (glFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 100.0)) computed with the
help of Equation (18.4).
E
ndClick for ballAndTorusShadowMapped.cpp Program Windows Project
E
xper
iment
18.2. Before running ballAndTorusShadowMapped.cpp you may want to run again ballAndTorusShadowed.cpp from Section 4.7.2, which implements a simple-minded blacken-and-flatten strategy, with help of a scaling degenerate along the y-direction, to draw shadows on the floor.The scenes of the two programs are almost identical, except, of course, that ballAndTorusShadowMapped.cpp shadow maps a local light source, whose position is indicated by a red sphere. Controls are identical too: press space to start the ball traveling around the torus and the up and down arrow keys to change its speed. Figure 18.6 is a screenshot.
E
ndClick for rationalBezierCurve1.cpp Program Windows Project 115
Chapter 18 Applications of Projective Spaces
E
xper
iment
18.3. Run rationalBezierCurve1.cpp, which draws the cubic rational B´ezier curve specified by four control points on the plane at fixed locations, but with changeable weights.The control points on the plane (light gray triangular mesh) are all red, except for the currently selected one, which is black. Press space to cycle through the control points. The control point weights are shown at the upper-left, that of the currently selected one being changed by pressing the up/down arrow keys. The rational B´ezier curve on the plane is red as well.
Figure 18.8 is a screenshot.
Drawn in green are all the lifted control points, except for that of the currently selected control point, which is black. The projective polynomial B´ezier curve approximating the lifted control points is green too. The lifted control points are a larger size as well.
Note: The lifted control points and the projective B´ezier curve are primitives in P2, of course, but represented in R3using their homogeneous coordinates.
Also drawn is a cone of several gray lines through the projective B´ezier curve which intersects the plane in its projection, the rational B´ezier curve.
Observe that increasing the weight of a control point pulls the (red rational B´ezier) curve toward it, while reducing it has the opposite effect.
Moreover, the end control points are always interpolated regardless of assigned weights. It’s sometimes hard to discern the very gradual change in the shape of the curve as one varies the weights. A trick is to press delete for the curve to spring back to its original configuration, at which moment the difference should be clear.
It seems, then, that the control point weights are an additional set of
“dials” at the designer’s disposal for use to edit the curve.
The code of rationalBezierCurve1.cpp is instructive as well, as we’ll
see in the next section on drawing.
E
ndClick for rationalBezierCurve2.cpp Program Windows Project
E
xper
iment
18.4. Run rationalBezierCurve2.cpp, which draws a red quadratic rational B´ezier curve on the plane specified by the three control points [1, 0]T, [1, 1]T and [0, 1]T. See Figure 18.9. Also drawn is the unit circle centered at the origin. Press the up/down arrow keys to change the weight of the middle control point [1, 1]T. The weights of the two end control points are fixed at 1.Decrease the weight of the control point [1, 1]T from its initial value of 1.5. It seems that at some value between 0.70 and 0.71 the curve lies exactly along a quarter of the circle (the screenshot of Figure 18.9 is at 1.13). This is no accident, as the following exercise shows.
E
nd116
Click for rationalBezierCurve3.cpp Program Windows Project
E
xper
iment
18.5. Run rationalBezierCurve3.cpp, which shows a rational B´ezier curve on the plane specified by six control points. See Figure 18.10 for a screenshot. A control point is selected by pressing the space key, moved with the arrow keys and its weight changed by the pageup/down keys. Pressing delete resets.
E
ndClick for turnFilm2.cpp Program Windows Project
E
xper
iment
18.6. Run turnFilm2.cpp, which animates the snapshot transformation of a polynomial B´ezier curve described above. Three control points and their red dashed approximating polynomial B´ezier curve are initially drawn on the z = 1 plane. See Figure 18.12(a). The locations of the control points, and so of their approximating curve as well, are fixed in world space. However, they will appear to move as the film rotates.Initially, the film lies along the z = 1 plane. Pressing the right arrow key rotates it toward the x = 1 plane, while pressing the left arrow key rotates it back. The film itself, of course, is never seen. As the film changes position, so do the control points and the red dashed curve, these being the projections (snapshot transformations, particularly) onto the current film of the control points and their approximating curve (all fixed, as said, in world space). Also drawn on the film is a green dashed curve, which is the polynomial B´ezier curve approximating the current projections of the control points.
Note: The control points and their approximating curve, all fixed on the z = 1 plane, and corresponding to the control points p0, p1 and p2and the solid red curve in Figure 18.11, are not drawn by the program – only their snapshot transformations on the turning film.
Initially, when the plane of the film coincides with that on which the control points are drawn, viz. z = 1, the projection onto the film of the polynomial B´ezier curve approximating the control points (the red dashed curve) coincides with the polynomial B´ezier curve approximating the projected control points (the green dashed curve). This is to be expected because the control points coincide with their projections. However, as the film turns away from the z = 1 plane, the red and green dashed curves begin to separate. Their final configuration, when the film lies along x = 1, is shown in Figure 18.12(b).
There is more functionality to the program that we’ll discuss momentarily.
E
ndClick for turnFilm2.cpp Program Windows Project 117
Chapter 18 Applications of Projective Spaces
E
xper
iment
18.7. Fire up turnFilm2.cpp once again. Pressing space at any time draws, instead of the green dashed curve, a blue dashed rational B´ezier curve approximating the projected control points on the current plane of the film. The control point weights of the blue dashed curve are computed according to the strategy just described. Voil`a! The blue dashed rational curve and the red dashed projection are inseparable.E
ndClick for rationalBezierSurface.cpp Program Windows Project
E
xper
iment
18.8. Run rationalBezierSurface.cpp, based on bezier-Surface.cpp, which draws a rational B´ezier surface with the functionality that the location and weight of each control point can be changed. Press the space and tab keys to select a control point. Use the arrow and page up/down keys to translate the selected control point. Press ‘</>’ to change its weight. Press delete to reset. The ‘x/X’, ‘y/Y’ and ‘z/Z’ keys turn the viewpoint. Figure 18.14 is a screenshot.Mark the use of glMap2f(GL MAP2 VERTEX 4, . . .), as also of glEnable-(GL MAP2 VERTEX 4). The 2’s in the syntax are for a surface.
E
nd118