23
2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

  • View
    221

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.1si31-2001

SI31Advanced Computer

GraphicsAGR

SI31Advanced Computer

GraphicsAGR

Lecture 2Basic Modelling

Page 2: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.2si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.3si31-2001

Polygonal RepresentationPolygonal Representation

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

Page 4: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.4si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.5si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.6si31-2001

Typical PrimitivesOrder of VerticesTypical PrimitivesOrder of Vertices

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

How are vertices ordered?– convention is that vertices are ordered

counter-clockwise when looking from outside an object

– allows us to distinguish outer and inner faces of a polygon

Page 7: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.7si31-2001

Modelling Regular ObjectsModelling Regular Objects

Sweeping

Spinning

2D Profilesweep axis

spinning axis

R1 R2

Page 8: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.8si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.9si31-2001

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– Watt, Chapter 2 (2.1)

Page 10: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.10si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.11si31-2001

Automatic Generation of Polygonal Objects

Automatic Generation of Polygonal Objects

3D laser scanners are able to generate computer representations of objects

– for successive heights, 2d outline generated as object rotates

– contours stitched together into 3D polygonal representation

Cyberware Cyberscanner in Med Physics at LGI able to scan human faces

Page 12: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.12si31-2001

A PuzzleA Puzzle

Page 13: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.13si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.14si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.15si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.16si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.17si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.18si31-2001

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’ = Rx () P

Page 19: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.19si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.20si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.21si31-2001

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: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.22si31-2001

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 (…….)

Exercise: Check T-1 T = I (identity matrix)

Page 23: 2.1 si31-2001 SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling

2.23si31-2001

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.– Watt, Chapter 1 (1.1)