Docsity

Viewing and Modeling Transformations - Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Viewing and Modeling Transformations - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Computer

Graphics

Lecture 42

Viewing Using

OpenGL II

Viewing and modeling transformations are related in OpenGL and are combined into a single modelview matrix. One of the toughest problems newcomers to computer graphics face is understanding the effects of combined three-dimensional transformations.

As we've already seen, there are alternative ways to think about transformations - do we want to move the camera in one direction, or move the object in the opposite direction?

If we can find a natural approach for our particular application, it's easier to visualize the necessary transformations and then write the corresponding code to specify the matrix manipulations.

The first part of this section discusses how to think about transformations; later, specific commands are presented. For now, we use only the matrix-manipulation commands we've already seen.

Thinking about

Transformations

Let's start with a simple case of two transfor- mations: a 45 o^ degree counterclockwise rotation about the origin around the z-axis, and a translation down the x- axis.

If we rotate the object first and then translate it, the rotated object appears on the x-axis. If we translate it down the x-axis first and then rotate about the origin, the object is on the line y=x, as shown in Figure.

In general, the order of transformations is critical. If we do transformation A and then transformation B, we almost always get something different than if we do them in the opposite order.

All viewing and modeling transformations are repre- sented as 4 Ɨ 4 matrices. Each successive glMultMatrix*() or transfor- mation command multiplies a new 4 Ɨ 4 matrix M by the current modelview matrix C to yield CM.

Finally, vertices v are multiplied by the current modelview matrix. This process means that the last transformation command called in our program is actually the first one applied to the vertices: CMv.

Like many other things, however, once we've gotten used to thinking about this correctly, backward will seem like forward. Consider the following code sequence, which draws a single point using three transformations:

glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(N); glMultMatrixf(M); glMultMatrixf(L); glBegin(GL_POINTS); glVertex3f(v); glEnd();