4.1si31_2001 si31 advanced computer graphics agr lecture 4 projection clipping viewport...

28
4.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 4 Projection Clipping Viewport Transformation

Post on 21-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

4.1si31_2001

SI31Advanced Computer

GraphicsAGR

SI31Advanced Computer

GraphicsAGR

Lecture 4ProjectionClipping

Viewport Transformation

4.2si31_2001

InterludeInterlude

Why does a mirror reflect left-right and not up-down?

4.3si31_2001

Projection

4.4si31_2001

Viewing Co-ordinate System

Viewing Co-ordinate System

The viewing transformation has transformed objects into the viewing co-ordinate systemviewing co-ordinate system, where the camera position is at the origin, looking along the negative z-direction

zV

yV

xV

camera

cameradirection

4.5si31_2001

View VolumeView Volume

zV

yV

xV

camera

nearplane

farplane

We determine the view volume by:- view angle, - aspect ratio of viewplane- distances to near plane dNP and far plane dFP

dNP

dFP

4.6si31_2001

ProjectionProjection

We shall project on to the near plane. Remember this is atright angles to the zV direction, and has z-coordinate zNP = - dNP

zV

yV

xV

camera

nearplane

dNP

4.7si31_2001

Perspective Projection Calculation

Perspective Projection Calculation

looking down x-axis towardsthe origin

zV

yV

xV

camera

nearplane

dNP

zNP

zV

view plane

Q

camera

yV

zNP zQ

4.8si31_2001

Perspective Projection Calculation

Perspective Projection Calculation

zV

view plane

Q

camera

yV

zNP zQ

P

By similar triangles, yP / yQ = ( - zNP) / ( - zQ)and soyP = yQ * (- zNP) / ( - zQ)oryP = yQ * dNP / ( - zQ)

Similarly for thex-coordinate of P:xP = xQ * dNP / ( - zQ)

4.9si31_2001

Using Matrices and Homogeneous Co-

ordinates

Using Matrices and Homogeneous Co-

ordinates

We can express the perspective transformation in matrix form

Point Q in homogeneous coordinates is (xQ, yQ, zQ, 1)

We shall generate a point H in homogeneous co-ordinates (xH, yH, zH, wH), where wH is not 1

But the point (xH/wH, yH/wH, zH/wH, 1) is the same as H in homogeneous space

This gives us the point P in 3D space, ie xP = xH/wH, sim’ly for yP

4.10si31_2001

Transformation Matrix for Perspective

Transformation Matrix for Perspective

1 0 0 0

0 1 0 0

0 0 1 0

0 0 -1/dNP 0

xQ

yQ

zQ

1

xH

yH

zH

wH

=

Thus in Homogeneous co-ordinates: xH = xQ; yH = yQ; zH = zQ; wH = (-1/dNP)zQ

In Cartesian co-ordinates:xP = xH / wH = xQ*dNP/(-zQ); yP similar; zP = -dNP = zNP

4.11si31_2001

ExercisesExercises

Suppose the camera is not at the origin, but at point zC

Calculate the formulae for perspective projection and work out the resulting transformation matrix in homogeneous co-ordinates

In practice the perspective division is delayed - why might this be done? -what useful information is lost?

4.12si31_2001

OpenGLOpenGL

Perspective projection achieved by:gluPerspective (angle_of_view, aspect_ratio, near, far)

– aspect ratio is width/height– near and far are positive distances

4.13si31_2001

Vanishing PointsVanishing Points

When a 3D object is projected onto a view plane using perspective, parallel lines in object NOT parallel to the view plane converge to a vanishing vanishing pointpoint

view plane

vanishing point

one-pointperspectiveprojectionof cube

4.14si31_2001

One- and Two-Point Perspective DrawingOne- and Two-Point Perspective Drawing

4.15si31_2001

One-point PerspectiveOne-point Perspective

Said to be the firstpainting in perspective

This is:Trinity with the Virgin,St John and Donors,by Mastaccio in 1427

4.16si31_2001

Two-point PerspectiveTwo-point Perspective

EdwardHopperLighthouseat Two Lights

-seewww.postershop.com

4.17si31_2001

Parallel Projection - Two types

Parallel Projection - Two types

OrthographicOrthographic parallel projection has view plane perpendicular to direction of projection

ObliqueOblique parallel projection has view plane at an oblique angle to direction of projection

P1

P2

view plane

P1

P2

view plane

We shall only consider orthographic projectionorthographic projection

4.18si31_2001

Parallel Projection Calculation

Parallel Projection Calculation

zV

yV

xV

nearplane

dNP

zV

view plane

Q

yV

looking down x-axis

zNPzQ

P

yP = yQ

similarly xP= xQ

4.19si31_2001

Parallel Projection Calculation

Parallel Projection Calculation

So this is much easier than perspective!– xP = xQ

– yP = yQ

– zP = zNP

The transformation matrix is simply1 0 0 0

0 1 0 00 0 zNP/zQ 00 0 0 1

4.20si31_2001

Clipping

4.21si31_2001

View Frustum and ClippingView Frustum and Clipping

zV

yV

xV

camera

nearplane

farplane

The view volume is a frustum in viewing co-ordinates - we need tobe able to clip objects outside of this region

dNP

dFP

4.22si31_2001

Clipping to View FrustumClipping to View Frustum

It is quite easy to clip lines to the front and back planes (just clip in z)..

.. but it is difficult to clip to the sides because they are ‘sloping’ planes

Instead we carry out the projection first which converts the frustum to a rectangular parallelepiped (ie a cuboid)

4.23si31_2001

Clipping for Parallel Projection

Clipping for Parallel Projection

In the parallel projection case, the viewing volume is already a rectangular parallelepiped

farplane

nearplane

zV

view volume

4.24si31_2001

Normalized Projection Co-ordinates

Normalized Projection Co-ordinates

Final step before clipping is to normalizenormalize the co-ordinates of the rectangular parallelepiped to some standard shape– for example, in some systems, it is

the cube with limits +1 and -1 in each direction

This is just a scalescale transformation Clipping is then carried out

against this standard shape

4.25si31_2001

Viewing Pipeline So FarViewing Pipeline So Far

Our pipeline now looks like:

mod’gco-ords

worldco-ords

view’gco-ords

proj’nco-ords

normalizedprojectionco-ordinatesNORMALIZATION

TRANSFORMATION

4.26si31_2001

Viewport Transformation

4.27si31_2001

And finally...And finally...

The last step is to position the picture on the display surface

This is done by a viewport viewport transformation transformation where the normalized projection co-ordinates are transformed to display co-ordinates, ie pixels on the screen

4.28si31_2001

Viewing Pipeline - The EndViewing Pipeline - The End

A final viewing pipeline is therefore:

mod’gco-ords

worldco-ords

view’gco-ords

proj’nco-ords

normalizedprojectionco-ordinates

deviceco-ordinates

DEVICETRANSFORMATION