Содержание

Слайд 2

02/21/02 (c) 2001 University of Wisconsin, CS559 Today Viewing Orthographic viewing Homework 3

02/21/02

(c) 2001 University of Wisconsin, CS559

Today

Viewing
Orthographic viewing
Homework 3

Слайд 3

02/21/02 (c) 2001 University of Wisconsin, CS559 Modeling 101 For the

02/21/02

(c) 2001 University of Wisconsin, CS559

Modeling 101

For the moment assume that

all geometry consists of points, lines and faces
Line: A segment between two endpoints
Face: A planar area bounded by line segments
Any face can be triangulated (broken into triangles)
Слайд 4

02/21/02 (c) 2001 University of Wisconsin, CS559 Modeling and OpenGL In

02/21/02

(c) 2001 University of Wisconsin, CS559

Modeling and OpenGL

In OpenGL, all geometry

is specified by stating which type of object and then giving the vertices that define it
glBegin(…) …glEnd()
glVertex[34][fdv]
Three or four components (regular or homogeneous)
Float, double or vector (eg float[3])
Chapter 2 of the red book
Слайд 5

02/21/02 (c) 2001 University of Wisconsin, CS559 Rendering Generate an image

02/21/02

(c) 2001 University of Wisconsin, CS559

Rendering

Generate an image showing the contents

of some region of space
The region is called the view volume, and it is defined by the user
Determine where each object should go in the image
Viewing, Projection
Determine which object is in front at each pixel
Hidden surface elimination, Hidden surface removal, Visibility
Determine what color it is
Lighting, Shading
Слайд 6

02/21/02 (c) 2001 University of Wisconsin, CS559 Graphics Pipeline Graphics hardware

02/21/02

(c) 2001 University of Wisconsin, CS559

Graphics Pipeline

Graphics hardware employs a sequence

of coordinate systems
The location of the geometry is expressed in each coordinate system in turn, and modified along the way
The movement of geometry through these spaces is considered a pipeline

Local Coordinate Space

World Coordinate Space

View Space

3D Screen Space

Display Space

Слайд 7

02/21/02 (c) 2001 University of Wisconsin, CS559 Local Coordinate Space It

02/21/02

(c) 2001 University of Wisconsin, CS559

Local Coordinate Space

It is easiest to

define individual objects in a local coordinate system
For instance, a cube is easiest to define with faces parallel to the coordinate axis
Key idea: Object instantiation
Define an object in a local coordinate system
Use it multiple times by copying it and transforming it into the global system
This is the only effective way to have libraries of 3D objects, and such libraries do exist
Слайд 8

02/21/02 (c) 2001 University of Wisconsin, CS559 Global Coordinate System Everything

02/21/02

(c) 2001 University of Wisconsin, CS559

Global Coordinate System

Everything in the world

is transformed into one coordinate system - the global coordinate system
Actually, some things, like dashboards, may be defined in a different space, but we’ll ignore that
Lighting is defined in this space
The locations, brightness’ and types of lights
The camera is defined with respect to this space
Some higher level operations, such as advanced visibility computations, can be done here
Слайд 9

02/21/02 (c) 2001 University of Wisconsin, CS559 View Space Associate a

02/21/02

(c) 2001 University of Wisconsin, CS559

View Space

Associate a set of axes

with the image plane
The image plane is the plane in space on which the image should “appear,” like the film plane of a camera
One normal to the image plane
One up in the image plane
One right in the image plane
These three axes define a coordinate system (a rigid body transform of the world system)
Some camera parameters are easiest to define in this space
Focal length, image size
Depth is represented by a single number in this space
The “normal to image plane” coordinate
Слайд 10

02/21/02 (c) 2001 University of Wisconsin, CS559 3D Screen Space Transform

02/21/02

(c) 2001 University of Wisconsin, CS559

3D Screen Space

Transform view space into

a cube: [-1,1]×[-1,1]×[-1,1]
The cube is the canonical view volume
Parallel sides make many operations easier
Tasks to do:
Clipping – decide what you can see
Rasterization - decide which pixels are covered
Hidden surface removal - decide what is in front
Shading - decide what color things are
Слайд 11

02/21/02 (c) 2001 University of Wisconsin, CS559 Window Space Also called

02/21/02

(c) 2001 University of Wisconsin, CS559

Window Space

Also called screen space (confusing)
Convert

the virtual screen into real screen coordinates
Drop the depth coordinates and translate
The windowing system takes care of this
Слайд 12

02/21/02 (c) 2001 University of Wisconsin, CS559 3D Screen to Window

02/21/02

(c) 2001 University of Wisconsin, CS559

3D Screen to Window Transform

Typically, windows

are specified by an origin, width and height
Origin is either bottom left or top left corner, expressed as (x,y) on the total visible screen on the monitor or in the framebuffer
This representation can be converted to (xmin,ymin) and (xmax,ymax)
3D Screen Space goes from (-1,-1,-1) to (1,1,1)
Lets say we want to leave z unchanged
What basic transformations will be involved in the total transformation from 3D screen to window coordinates?
Слайд 13

02/21/02 (c) 2001 University of Wisconsin, CS559 3D Screen to Window

02/21/02

(c) 2001 University of Wisconsin, CS559

3D Screen to Window Transform

How much

do we translate?
How much do we scale?

(-1,-1)

(1,1)

(xmin,ymin)

(xmax,ymax)

Слайд 14

02/21/02 (c) 2001 University of Wisconsin, CS559 3D Screen to Window Transform (-1,-1) (1,1) (xmin,ymin) (xmax,ymax)

02/21/02

(c) 2001 University of Wisconsin, CS559

3D Screen to Window Transform

(-1,-1)

(1,1)

(xmin,ymin)

(xmax,ymax)

Слайд 15

02/21/02 (c) 2001 University of Wisconsin, CS559 Orthographic Projection Orthographic projection

02/21/02

(c) 2001 University of Wisconsin, CS559

Orthographic Projection

Orthographic projection projects all the

points in the world along parallel lines onto the image plane
Projection lines are perpendicular to the image plane
Like a camera with infinite focal length
The result is that parallel lines in the world project to parallel lines in the image, and ratios of lengths are preserved
This is important in some applications, like medical imaging and some computer aided design tasks
Слайд 16

02/21/02 (c) 2001 University of Wisconsin, CS559 Simple Orthographic Projection Specify

02/21/02

(c) 2001 University of Wisconsin, CS559

Simple Orthographic Projection

Specify the region of

space that we wish to render as a view volume
Assume that the viewer is looking in the –z direction, with x to the right and y up
Assuming a right-handed coordinate system
The view volume has:
a near plane at z=n
a far plane at z=f , (f < n)
a left plane at x=l
a right plane at x=r
a top plane at y=t
and a bottom plane at y=b

z

y

x

Specify the region of space that we wish to render as a view volume
Assume that the viewer is looking in the –z direction, with x to the right and y up
Assuming a right-handed coordinate system
The view volume has:
a near plane at z=n
a far plane at z=f , (f < n)
a left plane at x=l
a right plane at x=r
a top plane at y=t
and a bottom plane at y=b

Specify the region of space that we wish to render as a view volume
Assume that the viewer is looking in the –z direction, with x to the right and y up
Assuming a right-handed coordinate system
The view volume has:
a near plane at z=n
a far plane at z=f , (f < n)
a left plane at x=l
a right plane at x=r, (r>l)
a top plane at y=t
and a bottom plane at y=b, (b

(r,b,n)

(l,t,f)

Слайд 17

02/21/02 (c) 2001 University of Wisconsin, CS559 Rendering the Volume To

02/21/02

(c) 2001 University of Wisconsin, CS559

Rendering the Volume

To project, map the

view volume onto the canonical view volume
After that, we know how to map the view volume to the window
The mapping looks just like the one for screen->window:
Слайд 18

02/21/02 (c) 2001 University of Wisconsin, CS559 General Orthographic Projection We

02/21/02

(c) 2001 University of Wisconsin, CS559

General Orthographic Projection

We could look at

the world from any direction, not just along –z
The image could rotated in any way about the viewing direction: x need not be right, and y need not be up
How can we specify the view under these circumstances?
Слайд 19

02/21/02 (c) 2001 University of Wisconsin, CS559 Specifying a View The

02/21/02

(c) 2001 University of Wisconsin, CS559

Specifying a View

The location of the

image plane in space
A point in space for the center of the image plane, (cx,cy,cz)
The direction in which we are looking
Specified as a vector that points back toward the viewer: (dx,dy,dz)
This vector will be normal to the image plane
A direction that we want to appear up in the image
This vector does not have to be perpendicular to n
We also need the size of the view volume – l,r,t,b,n,f
Specified with respect to the image plane, not the world
Слайд 20

02/21/02 (c) 2001 University of Wisconsin, CS559 Getting there… We wish

02/21/02

(c) 2001 University of Wisconsin, CS559

Getting there…

We wish to end up

in the “simple” situation, so we need a coordinate system with:
A vector toward the viewer
One pointing right in the image plane
One pointing up in the image plane
The origin at the center of the image
We must:
Define such a coordinate system, view space
Transform points from the world space into view space
Apply our simple projection from before
Слайд 21

02/21/02 (c) 2001 University of Wisconsin, CS559 View Space Given our

02/21/02

(c) 2001 University of Wisconsin, CS559

View Space

Given our camera definition:
Which point

is the origin of view space?
Which direction is the normal to the view plane, n?
How do we find the right vector, u?
How do we find the up vector, v?
Given these points, how do we do the transformation?
Слайд 22

02/21/02 (c) 2001 University of Wisconsin, CS559 View Space The origin

02/21/02

(c) 2001 University of Wisconsin, CS559

View Space

The origin is at the

center of the image plane: (cx,cy,cz)
The normal vector is the normalized viewing direction:
We know which way up should be, and we know we have a right handed system, so u=up×n, normalized:
We have two vectors in a right handed system, so to get the third: v=n×u
Слайд 23

02/21/02 (c) 2001 University of Wisconsin, CS559 World to View We

02/21/02

(c) 2001 University of Wisconsin, CS559

World to View

We must translate the

world so the origin is at (cx,cy,cz)
To complete the transformation we need to do a rotation
After this rotation:
The direction u in world space should be the direction (1,0,0) in view space
The vector v should be (0,1,0)
The vector n should be (0,0,1)
The matrix that does that is:
Слайд 24

02/21/02 (c) 2001 University of Wisconsin, CS559 All Together We apply

02/21/02

(c) 2001 University of Wisconsin, CS559

All Together

We apply a translation and

then a rotation, so the result is:
And to go all the way from world to screen:
Слайд 25

02/21/02 (c) 2001 University of Wisconsin, CS559 OpenGL and Transformations OpenGL

02/21/02

(c) 2001 University of Wisconsin, CS559

OpenGL and Transformations

OpenGL internally stores several

matrices that control viewing of the scene
The MODELVIEW matrix is intended to capture all the transformations up to the view space
The PROJECTION matrix captures the view to screen conversion
You also specify the mapping from the canonical view volume into window space
Directly through function calls to set up the window
Matrix calls multiply some matrix M onto the current matrix C, resulting in CM
Set view transformation first, then set transformations from local to world space – last one set is first one applied
Слайд 26

02/21/02 (c) 2001 University of Wisconsin, CS559 OpenGL Camera The default

02/21/02

(c) 2001 University of Wisconsin, CS559

OpenGL Camera

The default OpenGL image plane

has u aligned with the x axis, v aligned with y, and n aligned with z
Means the default camera looks along the negative z axis
Makes it easy to do 2D drawing (no need for any view transformation)
glOrtho(…) sets the view->screen matrix
Modifies the PROJECTION matrix
gluLookAt(…) sets the world->view matrix
Takes an image center point, a point along the viewing direction and an up vector
Multiplies a world->view matrix onto the current MODELVIEW matrix
You could do this yourself, using glMultMatrix(…) with the matrix from the previous slides