Viewing Pipeline

trexpeeverΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

80 εμφανίσεις

1

GR2
-
00

GR2

Advanced Computer Graphics

AGR

Lecture 4

Viewing Pipeline

Getting Started with OpenGL

2

GR2
-
00

The Story So Far ...Lecture 2


We have seen how we can model
objects, by transforming them from
their
local co
-
ordinate representation
into a
world co
-
ordinate system

modelling

co
-
ordinates

world

co
-
ordinates

MODELLING

TRANSFORMATION

3

GR2
-
00

The Story So Far...Lecture 3


And we have seen how we can
transform from a
special viewing co
-
ordinate system
(camera on z
-
axis
pointing along the axis) into a
projection co
-
ordinate system

viewing

co
-
ordinates

projection

co
-
ordinates

PROJECTION

TRANSFORMATION

4

GR2
-
00

Completing the Pipeline
-

Lecture 4


We now need to fill in the missing part




to get

world

co
-
ordinates

viewing

co
-
ordinates

VIEWING

TRANSFORMATION

mod’g

co
-
ords

world

co
-
ords

view’g

co
-
ords

proj’n

co
-
ords

5

GR2
-
00

Viewing Coordinate System
-

View Reference Point


In our world co
-
ordinate
system, we need to specify a
view reference point
-

this
will become the origin of the
view co
-
ordinate system


This can be any convenient
point, along the camera
direction from the camera
position


indeed one possibility is the
camera position
itself

x
W

y
W

z
W

P
0

6

GR2
-
00

Viewing Coordinate System
-

View Plane Normal

x
W

y
W

z
W

P
0

N

x
W

y
W

z
W

P
0

Q


Next we need to specify the
view plane normal, N
-

this
will give the camera
direction, or z
-
axis direction


Some graphics systems
require you to specify N ...


... others (including OpenGL)
allow you to specify a ‘
look
at
’ point, Q, from which N is
calculated as direction to
the ‘look at’ point from the
view reference point

7

GR2
-
00

Viewing Coordinate System
-

View Up Direction


Finally we need to specify
the
view
-
up direction, V
-

this will give the y
-
axis
direction

x
W

y
W

z
W

P
0

N

V

8

GR2
-
00

Viewing Co
-
ordinate System


This gives us a view reference
point P
0
,and vectors N
(corresponding to z
V
) and V
(corresponding to y
V
)


We can construct a vector U
perpendicular to both V and
N, and this will correspond to
the x
V

axis


How?

x
W

y
W

z
W

P
0

N

V

U

9

GR2
-
00

Transformation from World to
Viewing Co
-
ordinates


Given an object with positions defined
in world co
-
ordinates, we need to
calculate the transformation to
viewing co
-
ordinates


The view reference point must be
transformed to the origin, and lines
along the U, V, N directions must be
transformed to lie along the x, y, z
directions

10

GR2
-
00

Transformation from World to
Viewing Co
-
ordinates


Translate so that P
0

lies at the origin

x
W

y
W

z
W

P
0

-

apply translation by (
-
x
0
,
-
y
0
,
-
z
0
)

(x
0
, y
0
, z
0
)

T =


1 0 0
-
x
0

0 1 0
-
y
0

0 0 1
-
z
0

0 0 0 1

V

U

N

11

GR2
-
00

Transformation from World to
Viewing Co
-
ordinates


Apply rotations so that the U, V and N
axes are aligned with the x
W
, y
W

and
z
W

directions


This involves three rotations Rx, then
Ry, then Rz


first rotate around x
W

to bring N into the
x
W
-
z
W

plane


second, rotate around y
W

to align N with
z
W


third, rotate around z
W

to align V with y
W


Composite rotation R = Rz. Ry. Rx

12

GR2
-
00

Rotation Matrix


Fortunately there is an easy way to
calculate R, from U, V and N:

R =

u
1

u
2

u
3

0


v
1

v
2

v
3

0


n
1

n
2

n
3

0


0 0 0 1

where U = (u
1

u
2

u
3
)
T

etc

13

GR2
-
00

Viewing Transformation


Thus the viewing transformation is:

M = R . T


This transforms object positions in
world co
-
ordinates to positions in the
viewing co
-
ordinate system..

.. with camera pointing along negative
z
-
axis at a view plane parallel to x
-
y
plane


We can then apply the projection
transformation

14

GR2
-
00

Viewing Pipeline So Far


We now should understand this
viewing pipeline

mod’g

co
-
ords

world

co
-
ords

view’g

co
-
ords

proj’n

co
-
ords

15

GR2
-
00

Clipping


Next we need to understand how the
clipping to the view volume is
performed


Recall that with perspective projection
we defined a view frustum outside of
which we wanted to clip points and
lines, etc


The next slide is from lecture 3 ...

16

GR2
-
00

View Frustum
-

Perspective
Projection

view window

back

plane

front

plane

camera

view frustum

z
V

17

GR2
-
00

Clipping 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)

18

GR2
-
00

Clipping for Parallel Projection


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

view window

back

plane

front

plane

z
V

view volume

19

GR2
-
00

Normalized Projection

Co
-
ordinates


Final step before clipping is to
normalize

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
scale

transformation


Clipping is then carried out against this
standard shape

20

GR2
-
00

Viewing Pipeline So Far


Our pipeline now looks like:

mod’g

co
-
ords

world

co
-
ords

view’g

co
-
ords

proj’n

co
-
ords

normalized

projection

co
-
ordinates

NORMALIZATION

TRANSFORMATION

21

GR2
-
00

And finally...


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


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

22

GR2
-
00

Viewing Pipeline
-

The End


A final viewing pipeline is therefore:

mod’g

co
-
ords

world

co
-
ords

view’g

co
-
ords

proj’n

co
-
ords

normalized

projection

co
-
ordinates

device

co
-
ordinates

DEVICE

TRANSFORMATION

23

GR2
-
00

Interlude


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

24

GR2
-
00

OpenGL
-

Getting Started

25

GR2
-
00

What is OpenGL?


OpenGL provides a set of routines (API) for
advanced 3D graphics


derived from Silicon Graphics GL


acknowledged industry standard, even on PCs
(OpenGL graphics cards available)


integrates 3D drawing into X (and other window
systems such as Windows NT)


draws simple primitives (points, lines, polygons)
but NOT complex primitives such as spheres


provides control over transformations, lighting, etc


Mesa is publically available equivalent

26

GR2
-
00

Geometric Primitives


Defined by a group of vertices
-

for
example to draw a triangle:

glBegin (GL_POLYGON);


glVertex3i (0, 0, 0);


glVertex3i (0, 1, 0);


glVertex3i (1, 0, 1);

glEnd();


See Chapter 2 of the OpenGL
Programming Guide

27

GR2
-
00

Viewing


OpenGL maintains two matrix
transformation modes


MODELVIEW

to specify modelling transformations, and
transformations to align camera


PROJECTION

to specify the type of projection (parallel or
perspective) and clipping planes


See Chapter 3 of OpenGL
Programming Guide

28

GR2
-
00

OpenGL Utility Library (GLU)


Useful set of higher level utility routines
to make some tasks easier


written in terms of OpenGL and provided
with the OpenGL implementation


for example,
gluLookAt()
is a way of
specifying the viewing transformation


Described within the OpenGL
Programming Guide


eg
gluLookAt()
is described in Chap 3,
pp19
-
21


29

GR2
-
00

OpenGL Utility Toolkit (GLUT)


Set of routines to provide an interface to
the underlying windowing system
-

plus
many useful high
-
level primitives (even a
teapot
-

glutSolidTeapot()
!)


See Appendix D of OpenGL Guide


Allows you to write ‘event driven’
applications


you specify call back functions which are
executed when an event (eg window resize)
occurs

30

GR2
-
00

How to Get Started


Look at the GR2/AGR resources page:


http://www.scs.leeds.ac.uk/kwb/GR2/
resources.html


Points you to:


example programs


information about GLUT


information about OpenGL


a simple exercise