Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.

Similar presentations


Presentation on theme: "Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003."— Presentation transcript:

1 Introduction to 3-D Viewing Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003

2 27 Oct 2003CS 3812 Review: Some Notes on 3-D [1/3] 1. All graphics is 2-D graphics. 2. If it looks good and runs fast, then it’s good enough.* 3. When choosing between two equally likely options, try one; if it doesn’t work, try the other. *Don’t try to claim this when doing scientific visualization (or when told to use a specific method on an assignment).

3 27 Oct 2003CS 3813 Review: Some Notes on 3-D [2/3] To draw many objects of the same general type: Write a function that draws the object in “standard” position. Centered at the origin, unrotated. More generally: The point you put at the origin is the point you want to rotate/scale about. Repeat: Set up a transformation. Call the function.

4 27 Oct 2003CS 3814 Review: Some Notes on 3-D [3/3] Transformations are performed in the reverse order from how they are given in the code. This is why we say (in the code) translate first, then rotate & scale. Because we want scale & rotation to happen about the origin, before translations. Rotation about a line that does not pass through the origin: We want to rotate about the line 1 unit above (+y) the x-axis. Solution: Translate down (0, –1, 0). Then rotate (as above). Then translate back up (0, +1, 0). In the code, the transformations are given in the reverse order: glTranslated(0., 1., 0.); glRotated( angle, 1.,0.,0.); glTranslated(0., -1., 0.);

5 27 Oct 2003CS 3815 Review: OpenGL Geometry Pipeline Model/view Transformation Projection Transformation Viewport Transformation World Coordinates Object Coordinates Eye Coordinates Window Coordinates Vertices (window coord’s) Vertex Operations Rasterization Fragment Operations Vertices (object coord’s) Fragments Vertex enters here To framebuffer Convert vertex data to fragment data Depth test, etc. Lighting Clipping (view-frustum)

6 27 Oct 2003CS 3816 Introduction to 3-D Viewing: Model/View vs. Projection We have used the model/view transformation for: Moving and sizing objects ( glTranslate *, etc.). We have used the projection transformation for: Setting up a coordinate system in the window ( gluOrtho2D ). Drawing in perspective ( glFrustum, gluPerspective ). More generally: We use model/view for: Placing objects in the world (the “model” part). Placing the camera in the world (the “view” part). After model/view we do lighting and “take the picture”. We use projection for: Determining the properties of the camera: Wide or narrow angle. Perspective or parallel/orthogonal projection. After projection, we deal mostly with 2-D operations.

7 27 Oct 2003CS 3817 A single matrix can store a sequence of transformations. Each time a transformation command ( glTranslate *, glRotate *, glScale *, etc.) is executed, a new transformation is added to the head of this list. But we can add a new transformation to the tail by adding a transformation command at the beginning of the transformation- setting code. These two can be thought of in different ways. Transformations at the head of the model/view list move an object. Transformations at the tail of the model/view list move the entire scene or the camera. Introduction to 3-D Viewing: Model/View & the Camera [1/2] Transformation #1 Transformation #2 Transformation #3 Transformation #4 Model/view transformation

8 27 Oct 2003CS 3818 Introduction to 3-D Viewing: Model/View & the Camera [2/2] Again: These two can be thought of in different ways. Transformations at the head of the model/view list move an object. Transformations at the tail of the model/view list move the camera. Examples How would you rotate an object 90 about its own natural x-axis? Do “ glRotated(90, 1,0,0); ” just before drawing the object. How would you rotate the scene 90 about its x-axis? Do the above command near the beginning of the transformation code. The above command would come after those commands that are conceptually viewing transformations. How would you rotate the camera 90 about its x-axis? Do the above command at the beginning of the transformation code. How would you move the scene 4 units in the –z direction? Do “ glTranslated(0., 0., -4.); ”. See above comments for positioning. How would you move the camera 4 units in the –z direction? Do “ glTranslated(0., 0., 4.); ”. See above comments for positioning. Note the sign change!

9 27 Oct 2003CS 3819 Introduction to 3-D Viewing: Placing the Camera [1/3] How would you position the camera so that it sits at the point (3, –2, 1) and looks toward the point (–1, 1, 0), with “up” generally aimed toward the +z direction? Answer: Ick! Actually, the translation part is easy, but the rotations look tricky. This would seem to be a common enough thing to do. Can it be made easier with an interface other than glTranslate *, etc.?

10 27 Oct 2003CS 38110 Introduction to 3-D Viewing: Placing the Camera [2/3] We want to be at a certain place. The eye point. We want to look towards a certain place. The at point. We still have not specified any direction other than forward. We fix this by telling which way is up. The up vector. Why specify “up” and not (say) “right”? Because, in most situations, “up” does not change as you move around, while “right” does change. “Up” is therefore probably easier to compute. Since this can all be built out of existing OpenGL commands, GLU would be a good place to put it …

11 27 Oct 2003CS 38111 Introduction to 3-D Viewing: Placing the Camera [3/3] GLU implements this interface for us. The function used is gluLookAt. In lieu of extensive doc’s, an example. To sit at (3, –2, 1), look toward (–1, 1, 0), with “up” generally aimed toward the +z direction, do gluLookAt(3,-2,1, -1,1,0, 0,0,1); Where in the code should this call go? At the beginning of the transformation code. But other (conceptually later) camera movement commands may go before it. How do you suppose gluLookAt is implemented internally? Use glTranslate * to move to the eye point (above would be “ glTranslated(-3,2,-1); ”. Note the signs! Before this, in the code, use various glRotate * calls to get the orientation correct.

12 27 Oct 2003CS 38112 Introduction to 3-D Viewing: Another Camera-Placement Idea What if we want to sit at a certain point and look in a certain direction? This direction is called the view-plane normal. Do you see why? How can we do this in a program? Use gluLookAt. The eye point and up vector are as usual. The at point is the v.p.n. added to the eye point (vector + point = point).


Download ppt "Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003."

Similar presentations


Ads by Google