1gr2-00 gr2 advanced computer graphics agr lecture 2 basic modelling

23
1 GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

Upload: jocelyn-whalen

Post on 28-Mar-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

1GR2-00

GR2Advanced Computer

GraphicsAGR

GR2Advanced Computer

GraphicsAGR

Lecture 2Basic Modelling

Page 2: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2GR2-00

Polygonal RepresentationPolygonal Representation

Any 3D object can be represented as a set of plane, polygonal surfaces

V1

V2V3

V4

V5V8

V7 V6

Note: each vertex part of severalpolygons

Page 3: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

3GR2-00

Polygonal RepresentationPolygonal Representation

Objects with curved surfaces can be approximated by polygons - improved approximation by more polygons

Page 4: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

4GR2-00

Scene OrganisationScene Organisation

Scene = list of objects Object = list of surfaces Surface = list of polygons Polygon = list of vertices

scene

objectsurfaces polygons

vertices

Page 5: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

5GR2-00

Polygon Data StructurePolygon Data Structure

V1

V2V3

V4

V5V8

V7 V6

P1

P2

Object Table

Obj1P1, P2, P3,P4, P5, P6

Object Obj1

Vertex Table

V1X1, Y1, Z1

V2X2, Y2, Z2

. ...

Polygon Table

P1 V1, V2, V3, V4

P2 V1, V5, V6, V2

. ...

Page 6: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

6GR2-00

Typical PrimitivesTypical Primitives

Graphics systems such as OpenGL typically support:– triangles, triangle strips and fans– quads, quad strips– polygons

Which way is front?– convention is that normal points

towards you if vertices are specified counter-clockwise

Page 7: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

7GR2-00

Modelling Regular ObjectsModelling Regular Objects

Sweeping

Spinning

2D Profilesweep axis

spinning axis

R1 R2

Page 8: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

8GR2-00

Sweeping a Circle to Generate a Cylinder as

Polygons

Sweeping a Circle to Generate a Cylinder as

Polygons

vertices at z=0

vertices at z=depthV1

V2

V3V4

V5

V6 V8

V7

V10

V9

V11

V12V13

V14

V15V16

V17

V18

V1[x] = R; V1[y] = 0; V1[z] = 0V2[x] = R cos ; V2[y] = R sin ; V2[z] = 0 (=/4)Vk[x] = R cos k; Vk[y] = R sin k; Vk[z] = 0wherek = 2 (k - 1 )/8, k=1,2,..8

Page 9: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

9GR2-00

Exercise and Further Reading

Exercise and Further Reading

Spinning:– Work out formulae to spin an

outline (in the xy plane) about the y-axis

READING:– Hearn and Baker, Chapter 10

Page 10: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

10GR2-00

Complex PrimitivesComplex Primitives

Some systems such as VRML have cylinders, cones, etc as primitives– polygonal representation calculated

automatically OpenGL has a utility library (GLU)

which contains various high-level primitives– again converted to polygons

For conventional graphics hardware:– POLYGONS RULE!

Page 11: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

11GR2-00

Automatic Generation of Polygonal Objects

Automatic Generation of Polygonal Objects

3D scanners - or laser rangers - are able to generate computer representations of objects– object sits on rotating table– contour outline generated for a

given height– scanner moves up a level and next

contour created– successive contours stitched

together to give polygonal representation

Page 12: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

12GR2-00

A PuzzleA Puzzle

Page 13: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

13GR2-00

Modelling Objects and Creating Worlds

Modelling Objects and Creating Worlds

We have seen how boundary boundary representations representations of simple objects can be created

Typically each object is created in its own co-ordinate systemco-ordinate system

To create a world, we need to understand how to transform objects so as to place them in the right place - translationtranslation, at the right size - scalingscaling, in the right orientation- rotationrotation

Page 14: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

14GR2-00

TransformationsTransformations

The basic linear transformations are:– translation: P = P + T, where T is

translation vector– scaling: P’ = S P, where S is a scaling

matrix– rotation: P’ = R P, where R is a rotation

matrix As in 2D graphics, we use

homogeneoushomogeneous co-ordinates in order to express all transformations as matrices and allow them to be combined easily

Page 15: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

15GR2-00

Homogeneous Co-ordinates

Homogeneous Co-ordinates

In homogeneous coordinates, a 3D point P = (x,y,z)T

is represented as:P = (x,y,z,1)T

That is, a point in 4D space, with its ‘extra’ co-ordinate equal to 1

NoteNote: in homogeneous co-ordinates, multiplication by a constant leaves point unchanged– ie (x, y, z, 1)T = (wx, wy, wz, w)T

Page 16: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

16GR2-00

TranslationTranslation

Suppose we want to translate P (x,y,z)T by a distance (Tx, Ty, Tz)T

We express P as (x, y, z, 1)T and form a translation matrix T as below

The translated point is P’

T P

x’y’z’1

P’ =

1 0 0 Tx0 1 0 Ty0 0 1 Tz0 0 0 1

xyz1

= x + Txy + Tyz + Tz1

=

Page 17: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

17GR2-00

ScalingScaling

Scaling by Sx, Sy, Sz relative to relative to the originthe origin:

x’y’z’1

Sx 0 0 00 Sy 0 00 0 Sz 00 0 0 1

xyz1

P’ = S P

= = Sx . xSy . ySz . z1

Page 18: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

18GR2-00

RotationRotation

Rotation is specified with with respect to an axis respect to an axis - easiest to start with co-ordinate axes

To rotate about the x-axis:

a positive angle corresponds to counterclockwise direction lookingat origin from positive position on axis

EXERCISE: write down the matrices for rotation about y and z axes

x’y’z’1

= 1 0 0 00 cos -sin 00 sin cos 00 0 0 1

xyz1

P’ = Rz () P

Page 19: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

19GR2-00

Composite Transformations

Composite Transformations

The attraction of homogeneous co-ordinates is that a sequence of transformations may be encapsulated as a single matrix

For example, scaling with respect to a with respect to a fixed position (a,b,c) fixed position (a,b,c) can be achieved by:– translate fixed point to origin- say, T(-a,-b,-c)– scale- S– translate fixed point back to its starting

position- T(a,b,c) Thus: P’ = T(a,b,c) S T(-a,-b,-c) P = M P

Page 20: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

20GR2-00

Rotation about a Specified Axis

Rotation about a Specified Axis

It is useful to be able to rotate about any axis in 3D space

This is achieved by composing 7 elementary transformations

Page 21: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

21GR2-00

Rotation through about Specified Axis

Rotation through about Specified Axis

x

y

z

x

y

zrotate throughrequ’d angle,

x

y

z

x

y

z

P2

P1x

y

z

P2

P1x

y

z

initial positiontranslate P1to origin

rotate so that P2 lies on z-axis(2 rotations)

rotate axisto orig orientation

translate back

Page 22: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

22GR2-00

Inverse TransformationsInverse Transformations

As in this example, it is often useful to calculate the inverse of a transformation– ie the transformation that returns to

original state Translation: T-1 (a, b, c) = T (-a, -

b, -c) Scaling: S-1 ( Sx, Sy, Sz ) =

S ............ Rotation: R-1

z () = Rz (-)

Page 23: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

23GR2-00

Rotation about Specified Axis

Rotation about Specified Axis

Thus the sequence is:

T-1 R-1x() R-1

y() Rz() Ry() Rx() T EXERCISE: How are and

calculated? READING:

– Hearn and Baker, chapter 11.