Below are some problems related to the material covered
in class recently.
Answers are in the
Answers section, below.
Do not turn these in.
We may certainly discuss any of these problems in class,
if you want.
You can expect Test 2 (on Friday, November 7)
to contain problems similar to some of these.
Problems
Note: On the test you will be expected to do problems like these without books or notes.
What steps need to be taken to add a display-affecting global variable to a GLUT program?
How can we use OpenGL to conveniently set the value of a matrix variable?
Either explain in a couple of sentences or give some sample code/pseudocode.
We divided advanced viewing interfaces into two categories.
For each category:
name it, indicate its distinguishing characteristic(s),
indicate how its being in this category affects the internal implementation,
and give an example of an interface in the category.
When indicating scene rotations via mouse motions,
what line do we often what to rotate about?
What problem often occurs in flying-style interfaces
in which the user can only turn up, down, left, and right?
Briefly explain how we can use projection techniques to draw a shadow.
When we do shadowing via projection, where in the pipeline transformations
should the shadow projection occur?
List some problems or important issues with the projection-based shadowing technique
discussed in class.
In the example shadow-projection code I gave, the
shadowing matrix is computed only once.
Under what circumstances would the matrix need to be recomputed?
For each of the following,
if it can be done with a singleglRotate* call,
write out the call.
If not, answer “impossible”.
Do not worry about clockwise or counterclockwise.
Rotate 30° about the x axis.
Rotate 30° about the line through the points (0, 0, 0)
and (1, 2, 3).
Rotate 30° about the line through the points (1, 0, 0)
and (1, 1, 0).
Rotate 30° about the line through the points (1, 1, 1)
and (–1, –1, –1). (Be careful!)
Answers
To add a display-affecting global to a GLUT program:
Declare the variable.
Initialize the variable.
Use the variable in the display function.
Change the variable where appropriate.
When the variable is changed, call glutPostRedisplay.
We can use the OpenGL matrix operations to set a matrix variable by
Setting the model/view matrix using transformation commands.
Using glGetDoublev to copy the model/view matrix to the matrix variable.
Surrounding the whole thing with a push-pop pair so that there is no
permanent effect on the pipeline transformations.
The code would look something like this:
glPushMatrix();
Use transformation commands here.
glGetDoublev(GL_MODELVIEW_MATRIX, my_matrix_variable);
glPopMatrix();
The two categories are “view the world” and “move in the world”.
“View the world”:
The distiguishing characteristic of this category is that the “action”
takes plane at the point the camera is viewing.
Thus, we rotate and scale about the point we are looking at, not the camera.
The primary effect on the implementation is that the usual translation that moves objects to
where we can see them, does not go in a saved viewing matrix.
Examples: Manipulating an object, driving from above.
“Move in the world”:
The distiguishing characteristic of this category is that the “action”
takes at the camera location.
Thus, we rotate and scale about the camera, not the point the camera is vieing.
The primary effect on the implementation is that, if we save a viewing matrix,
the usual translation that moves objects to
where we can see them, goes in this matrix.
Examples: flying, driving from inside the car.
When indicating scene rotations with mouse motions,
we often want to rotate about a line perpendicular to the
mouse motion.
So, if the mouse motion is expressed as the 2-D vector (x, y),
then we probably want to rotate about the line through the origin and
the point (–y, x, 0).
When the user can only turn up, down, left, and right, the “up”
direction often becomes rotated, resulting in a slanted view of the world.
This can be fixed by allowing the user to roll.
A shadow is just a projection of (the shape of) an object on another object.
Thus, to draw a shadow, determine a matrix giving the required projection,
draw the object once without this matrix (draws the object itself)
and once with this matrix (draws the shadow).
The shadow and the object should be colored or lit differently,
in order to make the shadow look like a shadow.
The shadow projection places an object (the shadow) in the scene.
Thus it goes in the model/view transformation, after the viewing transformations.
The shadow projection should also go before those transformations that place
the object that is casting the shadow.
Here are six issues:
When we use this technique, we project by drawing lines through the point to
be projected and the light source.
Where a line hits the plane is where the shadow appears.
This means that, unless we are careful, objects that do not
lie between the light source and the plane will still cast shadows.
In this method, the shadow is an object.
Thus, it is not automatically confined to the polygon it is being cast on.
The technique casts a shadow on a single plane, or, with a little more work,
a single polygon.
Thus, it is difficult to use this method to cast a shadow on a complex object.
A shadow occupies the same spot in space as the plane it is cast on.
When two objects are drawn in the same spot, HSR sometimes does not work well.
Even though we do not need lighting to use this technique,
we do need lighting for it to produce realistic-looking results,
since a shadow is an unlit region.
We need to create the projection matrix ourselves;
OpenGL transformation commands do not help much.
The shadowing matrix depends on the light position
and the equation of the plane that the shadow falls on.
It would thus need to be recomputed if either the light
source or the plane moves.
glRotated(30, 1,0,0);
glRotated(30, 1,2,3);
Impossible.
glRotated(30, 1,1,1);
(This line passes through the origin.)