+ All Categories
Home > Documents > Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion...

Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion...

Date post: 21-Jan-2016
Category:
Upload: thomasine-parks
View: 215 times
Download: 0 times
Share this document with a friend
Popular Tags:
42
Viewing Viewing Chapter 5 Chapter 5
Transcript
Page 1: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

ViewingViewing

Chapter 5Chapter 5

Page 2: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 2

Introduction:Introduction:- We have completed our discussion of the first half We have completed our discussion of the first half

of the synthetic camera model of the synthetic camera model • specifying objects in three dimensionsspecifying objects in three dimensions

- We now investigate the multitude of ways in which We now investigate the multitude of ways in which we can describe our virtual camera.we can describe our virtual camera.

• First, we look at the types of views we can create, First, we look at the types of views we can create, and why we need more than one type of view.and why we need more than one type of view.

• Then we examine how an application viewer can Then we examine how an application viewer can create a particular view in within OpenGL.create a particular view in within OpenGL.

Page 3: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 3

1. Classical Computer Viewing1. Classical Computer Viewing

- Before looking at the interface between computer Before looking at the interface between computer graphics systems and application programmers for graphics systems and application programmers for 3D viewing, we take a slight diversion to consider 3D viewing, we take a slight diversion to consider classical viewing.classical viewing.

• There are two reasons to do thisThere are two reasons to do this– First, many jobs that were formerly done by hand First, many jobs that were formerly done by hand

drawing - such as animation in movies, architectural drawing - such as animation in movies, architectural rendering, .. Are now done routinely with the aid of rendering, .. Are now done routinely with the aid of compute graphics.compute graphics.

• Practitioners of these fields need to produce Practitioners of these fields need to produce classical views.classical views.

Page 4: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 4

– Second, the relationship between classical and Second, the relationship between classical and computer viewing shows many advantages of, and a computer viewing shows many advantages of, and a few difficulties with, the approach used by most few difficulties with, the approach used by most APIs.APIs.

- When we introduced the synthetic camera model When we introduced the synthetic camera model in Chapter 1, we covered some elements:in Chapter 1, we covered some elements:

• objects, viewers, projectors, and a projection planeobjects, viewers, projectors, and a projection plane

• Figure 5.1Figure 5.1

• The projectors meet at the center of projection The projectors meet at the center of projection (COP)(COP)

– this corresponds to the center of the lens in the this corresponds to the center of the lens in the camera, or in the eyecamera, or in the eye

Page 5: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 5

• Both classical and computer graphics allow the Both classical and computer graphics allow the viewer to be an infinite distance from the objectsviewer to be an infinite distance from the objects

• Note, as we move the COP to infinity, the Note, as we move the COP to infinity, the projectors become parallel and the COP can be projectors become parallel and the COP can be replaced with a direction of projection (DOP)replaced with a direction of projection (DOP)

• Figure 5.2Figure 5.2

Page 6: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 6

• Although computer graphics systems have two Although computer graphics systems have two fundamental types of viewing fundamental types of viewing

– (parallel and perspective), (parallel and perspective),

• classical graphics appears to permit a host of classical graphics appears to permit a host of different views ranging from:different views ranging from:

– multiview orthographic projections, one- two- and multiview orthographic projections, one- two- and three-point perspectivesthree-point perspectives

• This seeming discrepancy arises This seeming discrepancy arises – in classical graphics due to the desire to show a in classical graphics due to the desire to show a

specific relationship among an object, the viewer, specific relationship among an object, the viewer, and the projection plane and the projection plane

– as opposed to the computer graphics approach of as opposed to the computer graphics approach of complete independence of all specificationscomplete independence of all specifications

Page 7: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 7

1.1 Classical Viewing1.1 Classical Viewing- When an architect draws an image of a building,When an architect draws an image of a building,

• they know which sides they wish to display, they know which sides they wish to display,

• and thus where they should place the viewerand thus where they should place the viewer

- Each classical view is determined by a specific Each classical view is determined by a specific relationship between the objects and the viewer.relationship between the objects and the viewer.

- Figure 5.3Figure 5.3

Page 8: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 8

1.2 Orthographic Projections1.2 Orthographic Projections• The classical Orthographic projectionThe classical Orthographic projection

• Figure 5.4Figure 5.4

• Multiview Orthographic projectionsMultiview Orthographic projections

• Figure 5.5Figure 5.5

Page 9: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 9

1.3 Axonometric Projections1.3 Axonometric Projections- If we allow the projection plane to be at any angle If we allow the projection plane to be at any angle

(not just parallel with a face of the object) we end (not just parallel with a face of the object) we end up with an axonometric view.up with an axonometric view.

- Figure 5.6Figure 5.6

- Figure 5.7Figure 5.7

Page 10: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 10

1.4 Oblique Projections1.4 Oblique Projections- These are the most general parallel viewsThese are the most general parallel views

• projectors can make an arbitrary angle with the projectors can make an arbitrary angle with the projection plane.projection plane.

• Figure 5.8Figure 5.8

Page 11: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 11

1.5 Perspective Viewing1.5 Perspective Viewing- All perspective views are characterized by All perspective views are characterized by

diminution of size. diminution of size. • (the farther away, the smaller they are)(the farther away, the smaller they are)

• Figure 5.9Figure 5.9

Page 12: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 12

2. Positioning of the Camera2. Positioning of the Camera

- We can now return to 3D graphics from a We can now return to 3D graphics from a computer perspectivecomputer perspective

• We now examine the API that OpenGL provides for We now examine the API that OpenGL provides for three-dimensional graphics, and show how other three-dimensional graphics, and show how other APIs differAPIs differ

• In this section we deal with positioning the camera.In this section we deal with positioning the camera.

• In Section 5.4 we discuss how we specify the In Section 5.4 we discuss how we specify the desired projection.desired projection.

Page 13: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 13

- In OpenGL, the model-view and projection In OpenGL, the model-view and projection matrices are concatenated together to form the matrices are concatenated together to form the matrix that applies to geometric entities such as matrix that applies to geometric entities such as vertices.vertices.

• We have seen how to use the model-view matrixWe have seen how to use the model-view matrix– to position objects in space.to position objects in space.

• The other is to convert from the reference frame The other is to convert from the reference frame used for modeling to the frame of the cameraused for modeling to the frame of the camera

Page 14: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 14

2.1 Positioning of the Camera Frame2.1 Positioning of the Camera Frame- Initially the camera is at the originInitially the camera is at the origin

- Figure 5.11Figure 5.11

- Consider this sequenceConsider this sequence

- Figure 5.12Figure 5.12

Page 15: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 15

- At any given time, the state of the model-view At any given time, the state of the model-view matrix encapsulates the relation between the matrix encapsulates the relation between the camera frame and the world frame.camera frame and the world frame.

- Although combining the modeling and viewing Although combining the modeling and viewing transformations into a single matrix may initially transformations into a single matrix may initially cause confusion, on closer examination this cause confusion, on closer examination this approach is a good one.approach is a good one.

- The obvious next problems are how we specify the The obvious next problems are how we specify the desired position of the camera and how we desired position of the camera and how we implement camera positioning in OpenGLimplement camera positioning in OpenGL

Page 16: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 16

- Here, we find it convenient to think in terms of Here, we find it convenient to think in terms of moving the default camera relative tot he world moving the default camera relative tot he world frame.frame.

- We will outline three approaches to this.We will outline three approaches to this.

- The First Approach:The First Approach:• Specify the position indirectly by applying a Specify the position indirectly by applying a

sequence of rotations and translations to the model-sequence of rotations and translations to the model-view matrixview matrix

• This is a direct application of the instance This is a direct application of the instance transformations we presented in Chapter 4transformations we presented in Chapter 4

Page 17: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 17

• We must be careful for two reasons:We must be careful for two reasons:– First, we usually want to define the camera First, we usually want to define the camera beforebefore

we position the objects in the scene.we position the objects in the scene.– Second, transformations on the camera may appear Second, transformations on the camera may appear

to be backward from what we might expect.to be backward from what we might expect.

– Figure 5.13Figure 5.13

– glMatrixMode(GL_MODELVIEW);glMatrixMode(GL_MODELVIEW);– glLoadIdentity( );glLoadIdentity( );– glTranslatef(0.0, 0.0, -d);glTranslatef(0.0, 0.0, -d);– glRotatef(-90.0, 0.0, 1.0, 0.0)glRotatef(-90.0, 0.0, 1.0, 0.0)

Page 18: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 18

2.2 Two Viewing APIs2.2 Two Viewing APIs- We can take a different approach to positioning We can take a different approach to positioning

the camera -- an approach used by PHIGS, ...the camera -- an approach used by PHIGS, ...• We describe the camera’s position and orientation We describe the camera’s position and orientation

in the world framein the world frame– It’s desired location is centered at the view-reference It’s desired location is centered at the view-reference

point (VRP)point (VRP)– It’s orientation is specified with the view-plane It’s orientation is specified with the view-plane

normal (VPN) and the vie-up vector (VUPnormal (VPN) and the vie-up vector (VUP

• Figure 5.15Figure 5.15

Page 19: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 19

2.3 The Look-At Function2.3 The Look-At Function- The use if the VRP, VPN, and VUP is but one way The use if the VRP, VPN, and VUP is but one way

to provide an API for specifying the position of a to provide an API for specifying the position of a camera.camera.

• In many situations, as more direct method is In many situations, as more direct method is appropriate.appropriate.

• FIGURE 5.17FIGURE 5.17

• gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz);gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz);

Page 20: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 20

2.4 Other Viewing APIs2.4 Other Viewing APIs- In many applications, neither of the viewing In many applications, neither of the viewing

interfaces that we have presented is appropriate.interfaces that we have presented is appropriate.• Consider a flight simulator:Consider a flight simulator:

– The pilot worries about roll, pitch, and yawThe pilot worries about roll, pitch, and yaw

• Figure 5.18Figure 5.18

Page 21: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 21

- Viewing in many applications is most naturally Viewing in many applications is most naturally specified in polar coordinates -- rather than specified in polar coordinates -- rather than rectilinear coordinates. rectilinear coordinates.

• Applications involving objects that rotate about Applications involving objects that rotate about other objects fit this category.other objects fit this category.

• Figure 5.19Figure 5.19

Page 22: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 22

3. Simple Projections3. Simple Projections

- With a real camera, once we position it, we still must With a real camera, once we position it, we still must select a lens.select a lens.

• In computer graphics we select the type of lens and the In computer graphics we select the type of lens and the size of the film by selecting the type of projection and size of the film by selecting the type of projection and the viewing parameters.the viewing parameters.

- Most APIs distinguish between parallel and Most APIs distinguish between parallel and perspective views by providing different functions for perspective views by providing different functions for the two cases.the two cases.

• In OpenGL we can set the projection matrix with a In OpenGL we can set the projection matrix with a glLoadMatrix function, or we can other functions for the glLoadMatrix function, or we can other functions for the most common viewing conditionsmost common viewing conditions

Page 23: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 23

3.1 Perspective Projections3.1 Perspective Projections- Suppose that we are in the camera frame with the Suppose that we are in the camera frame with the

camera located at the origin pointed in the camera located at the origin pointed in the negative z direction.negative z direction.

- Figure 5.20Figure 5.20

Page 24: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 24

- As we saw in Chapter 2, we can place the As we saw in Chapter 2, we can place the projection plane in front of the center of projection. projection plane in front of the center of projection. If we do so, we get the following views: If we do so, we get the following views:

- Figure 5.21Figure 5.21

Page 25: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 25

3.2 Orthogonal Projections3.2 Orthogonal Projections- Orthogonal or orthographic projections are a Orthogonal or orthographic projections are a

special case of parallel projections, in which the special case of parallel projections, in which the projectors are perpendicular to the view of the projectors are perpendicular to the view of the plane.plane.

- Figure 5.23Figure 5.23

Page 26: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 26

4. Projections in OpenGL4. Projections in OpenGL

- The projections we just developed did not take into The projections we just developed did not take into account the properties of the camera:account the properties of the camera:

• the focal length of its lens,the focal length of its lens,

• the size of the film planethe size of the film plane

- View VolumeView Volume• Figure 5.24Figure 5.24

Page 27: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 27

- Most graphics APIs define clipping parameters Most graphics APIs define clipping parameters through the specification of a projection.through the specification of a projection.

- The resulting view volume is a frustum --a The resulting view volume is a frustum --a truncated pyramid.truncated pyramid.

- Figure 5.25Figure 5.25

Page 28: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 28

4.1 Perspectives in OpenGL4.1 Perspectives in OpenGL- In OpenGL we have two functions for specifying In OpenGL we have two functions for specifying

perspective views and one for specifying parallel perspective views and one for specifying parallel views.views.

- We can specify our camera view by:We can specify our camera view by:• glFrustrum(xmin, xmax, ymin, ymax, near, far)glFrustrum(xmin, xmax, ymin, ymax, near, far)

• Figure 5.26Figure 5.26

Page 29: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 29

- Because the projection matrix determined by Because the projection matrix determined by these specifications multiplies the present matrix, these specifications multiplies the present matrix, we must first select the matrix mode. we must first select the matrix mode.

- • A typical sequence isA typical sequence is

– glMatrixMode(GL_PROJECTION);glMatrixMode(GL_PROJECTION);– glLoadIdentity( );glLoadIdentity( );– glFrustrum(xmin, xmax, ymin, ymax, near, far);glFrustrum(xmin, xmax, ymin, ymax, near, far);

Page 30: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 30

• In many applications, it is natural to specify the In many applications, it is natural to specify the angle or field of viewangle or field of view

• gluPerspective(fovy, aspect, near, far);gluPerspective(fovy, aspect, near, far);

• Figure 5.27Figure 5.27

Page 31: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 31

4.2 Parallel Viewing in OpenGL4.2 Parallel Viewing in OpenGL- The only paralel-viewing function provided by The only paralel-viewing function provided by

OpenGL is the orthographic viewing functionOpenGL is the orthographic viewing function• glOrtho(xmin, xmax, ymin, ymax, near, far)glOrtho(xmin, xmax, ymin, ymax, near, far)

• Figure 5.28Figure 5.28

Page 32: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 32

5. Hidden-Surface Removal5. Hidden-Surface Removal

- Hidden surface removal algorithms can be divided Hidden surface removal algorithms can be divided into two broad classes:into two broad classes:

• Object-space algorithmsObject-space algorithms– attempt to order the surfaces of the objects in the attempt to order the surfaces of the objects in the

scene such that drawing surfaces in a particular scene such that drawing surfaces in a particular order provides the correct image.order provides the correct image.

• Image-space algorithmsImage-space algorithms– work as part of the projection process and seek to work as part of the projection process and seek to

determine the relationship among object points on determine the relationship among object points on each projectoreach projector

– z-buffer fits into this category.z-buffer fits into this category.

Page 33: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 33

- The major advantage of z-buffer is The major advantage of z-buffer is • that its worst case complexity is proportional to the that its worst case complexity is proportional to the

number of polygons.number of polygons.• It can be implemented with a small number of It can be implemented with a small number of

additional calculations over what we have to do additional calculations over what we have to do anyway.anyway.

• Figure 5.29Figure 5.29

• Typically you use these functions:Typically you use these functions:– glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB |

GLUT_DEPTH);GLUT_DEPTH);– glEnable(GL_DEPTH_TEST);glEnable(GL_DEPTH_TEST);

– glClear(GL_DEPTH_BUFFER_BIT);glClear(GL_DEPTH_BUFFER_BIT);

Page 34: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 34

6. Walking Through a Scene6. Walking Through a Scene

- Let us modify the version of our color-cube Let us modify the version of our color-cube program from Chapter 4 program from Chapter 4

• Old Version:Old Version:– the cube rotated about the origin.the cube rotated about the origin.– Orthographic projectionOrthographic projection

• In this versionIn this version– perspective projectionperspective projection– allow the camera to move.allow the camera to move.

Page 35: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 35

• void keys(unsigned char key, int x, int y)void keys(unsigned char key, int x, int y)• {{• if(key == ‘x’) viewer[0] -= 1.0;if(key == ‘x’) viewer[0] -= 1.0;• if(key == ‘X’) viewer[0] += 1.0;if(key == ‘X’) viewer[0] += 1.0;• if(key == ‘y’) viewer[1] -= 1.0;if(key == ‘y’) viewer[1] -= 1.0;• if(key == ‘Y’) viewer[1] += 1.0;if(key == ‘Y’) viewer[1] += 1.0;• if(key == ‘z’) viewer[2] -= 1.0;if(key == ‘z’) viewer[2] -= 1.0;• if(key == ‘Z’) viewer[2] += 1.0;if(key == ‘Z’) viewer[2] += 1.0;• }}

Page 36: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 36

void display(void)void display(void) {{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity( );glLoadIdentity( ); gluLookAt(viewer[0], viewer[1], viewer[2], gluLookAt(viewer[0], viewer[1], viewer[2], 0.0, 0.0, 0.0, 0.0, 1.0 , 0.0);0.0, 0.0, 0.0, 0.0, 1.0 , 0.0); glRotatef(theta[0], 1.0, 0.0, 0.0);glRotatef(theta[0], 1.0, 0.0, 0.0); glRotatef(theta[1], 0.0, 1.0, 0.0);glRotatef(theta[1], 0.0, 1.0, 0.0); glRotatef(theta[2], 0.0, 0.0, 1.0);glRotatef(theta[2], 0.0, 0.0, 1.0);

colorcube( );colorcube( );

glFlush( );glFlush( ); glutSwapBuffers( );glutSwapBuffers( ); }}

Page 37: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 37

void myReshape(int w, int h)void myReshape(int w, int h) {{ glViewport(0,0,w,h);glViewport(0,0,w,h); glLoadMatrix(GL_PROJECTION);glLoadMatrix(GL_PROJECTION); glLoadIdentity( );glLoadIdentity( ); if(w<=h)if(w<=h) glFrustrum(-2.0, 2.0, -2.0 * (Glfloat)h/(Glfloat)w,glFrustrum(-2.0, 2.0, -2.0 * (Glfloat)h/(Glfloat)w, 2.0*(Glfloat(h)/(Glfloat)w, 2.0, 20.0);2.0*(Glfloat(h)/(Glfloat)w, 2.0, 20.0); elseelse glFrustrum(-2.0, 2.0, -2.0 * (Glfloat)w/(Glfloat)h,glFrustrum(-2.0, 2.0, -2.0 * (Glfloat)w/(Glfloat)h, 2.0*(Glfloat)w/(Glfloat)h, 2.0, 20.0);2.0*(Glfloat)w/(Glfloat)h, 2.0, 20.0); glMatrixMode(GL_MODELVIEW);glMatrixMode(GL_MODELVIEW); }}

Page 38: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 38

9. Projections and Shadows9. Projections and Shadows

- The creation of simple shadows is an interesting The creation of simple shadows is an interesting application of projection matrices.application of projection matrices.

- This section covers how to re-project the polygon This section covers how to re-project the polygon casting the shadow onto the groundcasting the shadow onto the ground

• this re-projection is called a shadow polygon.this re-projection is called a shadow polygon.

Page 39: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 39

- For a simple environment, this technique works For a simple environment, this technique works well, however, when objects cast shadows on well, however, when objects cast shadows on other objects, this method becomes impractical.other objects, this method becomes impractical.

- In chapter 9 we address a more general shadow-In chapter 9 we address a more general shadow-creation method that requires more work.creation method that requires more work.

Page 40: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 40

10. Summary10. Summary

- We have come a long way.We have come a long way.• We can now write complete, nontrivial, three We can now write complete, nontrivial, three

dimensional applications.dimensional applications.

• Probably the most instructive activity that you can Probably the most instructive activity that you can do now is to write such an application.do now is to write such an application.

- In Chapter 6 we consider the interaction of light In Chapter 6 we consider the interaction of light with the materials that characterize our objects.with the materials that characterize our objects.

Page 41: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 41

11. Suggested Readings11. Suggested Readings

• Foley (90), Watt (93) and Hern&Baker (94) derive Foley (90), Watt (93) and Hern&Baker (94) derive canonical projection transformationscanonical projection transformations

– All follow the PHIGS orientation, so the API is slightly All follow the PHIGS orientation, so the API is slightly different from the one used here.different from the one used here.

• Most differ in whether they use column or row Most differ in whether they use column or row matrices, in where the COP is located, and in matrices, in where the COP is located, and in whether the projection is in the positive or whether the projection is in the positive or negative z direction.negative z direction.

• See theSee the OpenGL Programmer’s Guide OpenGL Programmer’s Guide (97) for (97) for further discussion of the use of the model-view and further discussion of the use of the model-view and projection matrices projection matrices

Page 42: Viewing Chapter 5. CS 480/680Chapter 5 -- Viewing2 n Introduction: -We have completed our discussion of the first half of the synthetic camera model specifying.

CS 480/680 Chapter 5 -- Viewing 42

Exercises -- Due next classExercises -- Due next class


Recommended