27
Computer Graphics - Week 2 Computer Graphics - Week 2 Bengt-Olaf Schneider Bengt-Olaf Schneider IBM T.J. Watson Research Center IBM T.J. Watson Research Center © Bengt-Olaf Schneider, 1999 Computer Graphics – Week 2 Questions about Last Week ? Questions about Last Week ?

Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

  • Upload
    lebao

  • View
    216

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

Computer Graphics - Week 2Computer Graphics - Week 2

Bengt-Olaf SchneiderBengt-Olaf SchneiderIBM T.J. Watson Research CenterIBM T.J. Watson Research Center

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Questions about Last Week ?Questions about Last Week ?

Page 2: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

AdministriviaAdministrivia

BooksReading list has been forwarded to the bookstore, but ...No success yet :-(Alternatives:www.amazon.comwww.barnesnoble.com

Minor adjustments to the scheduleFinal assignment due on April 28

Regularly check the class home page at www.cs.columbia.edu/graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Programming EnvironmentProgramming Environment

Gateway labSGI workstations with OpenGL and GLUTAccount charge: $35Currently limited business hours ... should improve

ACIS labHP workstation running OpenGL and GLUTNo extra account charge

Windows on PCsVisual C++ Version 5 (6)

Page 3: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Overview of Week 2Overview of Week 2

Overview of the Raster Graphics Pipeline

TransformationGeometric transformationsHomogeneous coordinatesComposing transformationsHierarchical modeling

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Raster Graphics PipelineRaster Graphics Pipeline

Host CPUGraphics

SubsystemInput

DevicesOutputDevice

ClippingLightingCalculations

ModelingTransforms

ViewingTransforms

Geometric Operations

Image Generation

SetupCalculations

ScreenRefresh

FrameBufferRasterization Pixel

Processing

Perspective+ Viewport

Page 4: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Raster Graphics Pipeline: Geometry StageRaster Graphics Pipeline: Geometry StageModeling Transformation

Create the scene: position objects in a common coordinate system

Viewing TransformationSetup and position camera

LightingSetup lights

ClippingRemove portions of the scene outside of the view volume

Perspective & Viewport MappingTransition from 3D to 2DMap the image into screen / window coordinates

?

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Raster Graphics Pipeline: Image Generation Raster Graphics Pipeline: Image Generation Setup

Calculate parameters for rasterization, e.g. line slopes, color gradients etc.Convert floating point positions into fixed point raster coordinates

RasterizationGenerate coordinates and values (color, depth etc.) for pixel covered by an object

Pixel Processing a.k.a. fragment processing

Process and store pixels produced by rasterization processE.g. z-buffer, texture mapping, alpha-blending or stenciling

dx/dy

dx/dy

dx/dy

dc/dx

Page 5: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Geometric Transformations: OverviewGeometric Transformations: Overview

Position,orient and size objectsTranslationRotationScaling

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Cartesian CoordinatesCartesian Coordinates

"Common" rectilinear coordinate system

Usually in 1D, 2D and 3Dn orthogonal, real number lines

Right-handed coordinate system

Looking down the positive z-axis, counter-clockwise rotation will turn the x-axis into the y-axis.

-1 21 3 4 5 6-2-3-4-5-6x

z

-1

123456

-2-3-4-5-6

y

Page 6: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Geometric Transformations: TranslationGeometric Transformations: Translation

x0 x + a0x x

y0

y +b0

y y

x’ = x+ay’ = y+b

Preserves lengths (isometric)Preserves angles (conformal)

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Geometric Transformations: RotationGeometric Transformations: Rotation

x0 x’x x

y0y’

y y

x’ = x cos - y sin y’ = x sin + y cos

α αα α

α

Preserves lengths (isometric)Preserves angles (conformal)

Page 7: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Rigid Body TransformationsRigid Body Transformations

Rigid Body Transformations:Transformations that preserve lengths and angles, i.e. that are isometric and conformal.

Translation and rotation are rigid body transformations.

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Geometric Transformations: ScalingGeometric Transformations: Scaling

x0 x a0x x

y0y b0

y y

x’ = axy’ = by

Does not preserves lengthsPreserves angles only for uniform scaling

Page 8: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Geometric Transformations: ShearGeometric Transformations: Shear

x0 x + ay0x x

y0 y0

y y

x’ = x+ayy’ = y

Does not preserve lengths or angles

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Geometric Transformations: Matrix FormGeometric Transformations: Matrix Form

Rotation

Scaling

x x yy x y

xy

xy

' cos sin' sin cos

''

cos sinsin cos

'

= −= +

⇒ FHG

IKJ=

−FHG

IKJFHG

IKJ

⇒ = •

α αα α

α αα α

p R p

x axy by

xy

ab

xy

''

''

'

==

⇒ FHG

IKJ= F

HGIKJFHG

IKJ

⇒ = •

00

p S p

Shear

Translation

x x ayy y

xy

a xy

x

''

''

'

= +=

⇒ FHG

IKJ= F

HGIKJFHG

IKJ

⇒ = •

10 1

p SH p

x a xy b y

xy

ab

xy

''

''

'

= += +

⇒ FHG

IKJ= F

HGIKJ+ F

HGIKJ

⇒ = +p T p

Page 9: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Geometric TransformationsGeometric Transformations

Translations handled differently than other transformations

Unelegant, cumbersome, clumsy !!Not possible to composite transformations into a single transformation

Homogeneous coordinates solve this problem.

p R p p S p p SH p p T px' ' ' '= • = • = • = + ; ; ;

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Homogeneous Coordinates: DefinitionHomogeneous Coordinates: Definition

Every 2D point is defined by three numbers

P is called the homogeneous coordinates of p.W is the homogeneous component, or simply the W coordinatep is in Cartesian coordinates

ConventionsCartesian coordinates: lower-case lettersHomogeneous coordinates: upper-case lettersMatrices and vectors: bold-face

p P= ≡ == = ≠

x y X Y W

x X W y Y W W

, , ,

/ /b g b g

; for 0

Page 10: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Homogeneous Coordinates: PropertiesHomogeneous Coordinates: Properties

A point in Cartesian coordinates has many corresponding homogeneous representations

The Cartesion point p lies in the plane W = 1.Different values of W trace out a line from the origin through p

X

Y

W

W=1

xy p

P

p P= ≡ = ≠( , ) ( , , )x y tX tY tW t with 0

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

So far, we have excluded homogeneous coordinates with W = 0.

Cartesian coordinates are infinite.

Look at the limit of x/y :

Homogeneous Coordinates: Homogeneous Coordinates: WW = 0 = 0

lim lim//W W

xy

X WY W→ →

FHG

IKJ= F

HGIKJ=

∞∞FHG

IKJ0 0

lim lim//W W

xy

X WY W

XY

xy→ →

= = =0 0

Although the individual coordinates are infinite, their ratio remains finite !Coordinates with W = 0 represent

Points at infinity in a given directionVectors

x

y

Y

X

WW=0

W=1

Page 11: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Homogeneous Coordinates: ApplicationHomogeneous Coordinates: Application

So how does all that help with describing translations ?

XYW

ab

xy

x ay b

x x a y y b

'''

' '

'

FHGG

IKJJ=

FHGG

IKJJFHGG

IKJJ=

++

FHGG

IKJJ

⇒ = + = +

= •

1 00 10 0 1 1 1

;

P T P

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Homogeneous Coordinates: Other UsesHomogeneous Coordinates: Other Uses

As we will see later, homogeneous coordinates are also useful for

Projective geometry, e.g. perspective viewingClippingModeling, e.g. non-uniform rational B-splines (NURBS)

Page 12: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Shear

Translation

Geometric Transformations:Geometric Transformations:Matrix Form w/ Homogeneous CoordinatesMatrix Form w/ Homogeneous Coordinates

Rotation

Scaling

XYW

xy

'''

cos sinsin cos

'

FHGG

IKJJ=

−FHGG

IKJJFHGG

IKJJ

⇒ = •

α αα α

00

0 0 1 1

P R P

XYW

a xy

'''

'

FHGG

IKJJ=

FHGG

IKJJFHGG

IKJJ

⇒ = •

1 00 1 00 0 1 1

P SH Px

XYW

ab

xy

'''

'

FHGG

IKJJ=

FHGG

IKJJFHGG

IKJJ

⇒ = •

0 00 00 0 1 1

P S P

XYW

ab

xy

'''

'

FHGG

IKJJ=

FHGG

IKJJFHGG

IKJJ

⇒ = •

1 00 10 0 1 1

P T P

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Homogeneous Coordinates: 3D SpaceHomogeneous Coordinates: 3D Space

Applying the same concepts to 3D is straight-forwardCartesian coordinates (x,y,z) correspond to homogeneous coordinates (X,Y,Z,W).The transformation matrices for the basic geometric transformations remain essentially the same:

R R R

T S

x y z=−

F

H

GGGG

I

K

JJJJ=

F

H

GGGG

I

K

JJJJ=

−F

H

GGGG

I

K

JJJJF

H

GGGG

I

K

JJJJ

F

H

GGGG

I

K

JJJJ

1 0 0 00 00 00 0 0 1

0 00 1 0 0

0 00 0 0 1

0 00 0

0 0 1 00 0 0 1

1 0 00 1 00 0 10 0 0 1

0 0 00 0 00 0 00 0 0 1

cos sinsin cos

cos sin

sin cos

cos sinsin cosα α

α α

α α

α α

α αα α

= =

abc

ab

c SHx =

F

H

GGGG

I

K

JJJJ

1 0 00 1 0 00 0 1 00 0 0 1

a

Page 13: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Types of TransformationsTypes of Transformations

Linear TransformationsMaps lines to lines (or point)Origin is always mapped into the origin

x a x a y a zy a x a y a zz a x a y a z

xyz

a a aa a aa a a

xyz

'''

'''

= + += + += + +

⇔FHGG

IKJJ=

FHGG

IKJJFHGG

IKJJ

11 12 13

21 22 23

31 32 33

11 12 13

21 22 23

31 32 33

Affine TransformationsPreserves parallel linesOrigin does not always map to the origin

x a x a y a z ay a x a y a z az a x a y a z a

XYZW

a a a aa a a aa a a aa a a a

xyz

'''

''''

= + + += + + += + + +

⇔F

H

GGGG

I

K

JJJJ=

F

H

GGGG

I

K

JJJJ

F

H

GGGG

I

K

JJJJ

11 12 13 14

21 22 23 24

31 32 33 34

11 12 13 14

21 22 23 24

31 32 33 34

41 42 43 44 1

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Combining Transformations ... or Combining Transformations ... or "Why we went through all that trouble""Why we went through all that trouble"

Compositing transformations means to multiply the individual transformation matrices

M M M

P' M P

M M P

M M P1 2

1 2

= •

= •= • •= • •

1 2

b gb g

Notes:Matrix multiplication is not commutativeHowever, it is associativeM2 is applied first !Consider this when setting up transformations in your programs !

Multiplying transformation matrices applies only to homogeneous coordinates

Page 14: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Combining Transformations: ExampleCombining Transformations: Example

1 2 3 4 5 6 7 8 x

y

12345678

1 2 3 4 5 6 7 8 x

y

12345678

1 2 3 4 5 6 7 8 x

y

12345678

1) Translate (-3, -2)2) Rotate (30)3) Translate (6, 4)

1) Rotate (30)2) Translate (-3,-2)3) Translate (6, 4)

1

1

2

2

3

3

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Compositing of Transformations:Compositing of Transformations:Finding a Transformation MatrixFinding a Transformation Matrix

How are how unit vectors and origin are affected?

a b c de f g hi j k lm n o p

a b c de f g hi j k lm n o p

F

H

GGGG

I

K

JJJJ•

F

H

GGGG

I

K

JJJJ=

F

H

GGGG

I

K

JJJJ

1 0 0 00 1 0 00 0 1 00 0 0 1

x-axisy-axisz-axisorigin Identity matrix

Page 15: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Compositing of Transformations:Compositing of Transformations:Finding a Transformation Matrix - ExampleFinding a Transformation Matrix - Example

What is the transformation ?

Origin: (0,0) goes to (8,4)X-axis: (1,0) goes to (-0.707, -0.707)Y-axis: (0,1) goes to (-0.707, 0.707)

1 2 3 4 5 6 7 8 x

y

12345678

1 2 3 4 5 6 7 8 x

y

12345678

?

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Compositing of Transformations:Compositing of Transformations:Finding a Transformation Matrix - ExampleFinding a Transformation Matrix - Example

a b cd e fg h i

FHGG

IKJJ•

FHGG

IKJJ=

− −− +

F

HGGG

I

KJJJ

− −− +

F

HGGG

I

KJJJ•

FHGG

IKJJ=

−−

−−

−−

−+

F

HGGG

I

KJJJ=

1 0 00 1 00 0 1

0 5 0 5 80 5 05 4

0 0 1

0 5 05 80 5 05 4

0 0 1

211

611

631

451

8 3 054 0 5

1

8 7 054 5 05

1

8 9 054 3 05

1

8 9 0 54 05

1

. .

. .

. .

. ...

.

...

..

5883 29

1

3 050 46

1

164188

1

1644 71

1

.

...

.

...

FHGG

IKJJ

1 2 3 4 5 6 7 8 x

y

12345678

1 2 3 4 5 6 7 8 x

y

12345678

?

Page 16: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Geometric Transformations:Geometric Transformations:Transforming Coordinate the SystemTransforming Coordinate the System

Transformations can also be considered as change of coordinate system

Origin and axes are remapped

Object positions can be specified in either coordinate system.

Object's lower-left corner is either (2, 1) or (6, 3.8).

1 2 3 4 5 6 7 8 x

y

12345678

1 2 3 4 5 6 7 8x

y

12

34

56

78

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

An Aside: Vector and Matrix NotationAn Aside: Vector and Matrix Notation

We will be using column format for vectorsVector is multiplied from the left with the matrix MC

Matrices are applied right to left

Vectors can also be represented in row formatVector is multiplied from the right with the matrix MR

MR = MCT ... of course you remember that from linear algebra

Matrices are applied left to right

P M P P P M'

''''

' ' ' ' '=

F

H

GGGG

I

K

JJJJ=

F

H

GGGG

I

K

JJJJ

F

H

GGGG

I

K

JJJJ• =

F

H

GGGG

I

K

JJJJ= •

XYZW

a b c de f g hi j k lm n o p

XYZW

X Y Z W X Y Z W

a e i mb f j nc g k od h l p

= T T Tb g b g

Page 17: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Putting it all to work:Putting it all to work:Hierarchical ModelingHierarchical Modeling

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Hierarchical Modeling: MotivationHierarchical Modeling: Motivation

Scenesdefined in world coordinate systemcomposed from different modelsExample: City

Modelsdefined in model coordinate systembuilt from different partsExample: House, Roads, Trees, ...

Partsdefined in another model coordinates systembuilt from yet more partsExample: Doors, Windows, Walls, ...

Page 18: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Hierarchical Modeling: Scene GraphHierarchical Modeling: Scene Graph

Scenegraph is a directed acyclic graph (DAG)Objects defined in local coordinatesTransformation nodes to transform objects into world coordinatesGroup nodes to create collection of objectsAttribute nodes to define object properties, e.g. materialCamera nodes to define viewing parameters

Used in modern, high-level APIsPHIGSOpenInventorVRMLJava3D

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Scene Graph: ExampleScene Graph: Example

Root node

Group node

Transformation

Object node

G3

G2 G3 O6

G1

T1 T2 T3 T4

T5

O1 O2 O3 O4

O5

O7

Page 19: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Scene Graph Concepts: InstantiationScene Graph Concepts: Instantiation

Objects can be used multiple times, i.e. they can be instantiated

Groups can also be instantiatedExample:

Object O2 is instantiated twiceObject O2 is instantiated twiceGroup G3 is instantiated twiceGroup G3 is instantiated twice(must be defined before use)(must be defined before use)It is placed into the root coordinate It is placed into the root coordinate system in different places defined by system in different places defined by T1 and T2T1 and T2

Root node

Group node

Transformation

Object node

G3

G2 G3 O6

G1

T1 T2 T3 T4

T5

O1 O2 O3 O4

O5

O7

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Scene Graph Concepts: TransformationsScene Graph Concepts: Transformations

Scene graph (implicitely) defines multiple coordinate systems

Transformations are composited along given pathTransformations only affect their child nodes

General concept: Any node has General concept: Any node has effect for its children.effect for its children.Exception: VRML and OpenInventorException: VRML and OpenInventor

Example:Object O7 is transformed by T4*T5 Object O7 is transformed by T4*T5 into the root coordinate systeminto the root coordinate systemObject O6 is only affected by T4Object O6 is only affected by T4

Root node

Group node

Transformation

Object node

G3

G2 G3 O6

G1

T1 T2 T3 T4

T5

O1 O2 O3 O4

O5

O7

Page 20: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Hierarchical Modeling: TransformationsHierarchical Modeling: Transformations

Root node

Group node

Transformation

Object node

G3

G2 G3 O6

G1

T1 T2 T3 T4

T5

O1 O2 O3 O4

O5

O7

Remember:It is important in what order transformations are applied !

When applying a new transformation to an existing transformation, new matrix must by pre-multiplied.

When using row-vectors, matrices When using row-vectors, matrices must be post-multipliedmust be post-multiplied

ExampleFirst T5Then T4T4 * T5 * O7

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Hierarchical Modeling: ImplementationHierarchical Modeling: Implementation

Stack is used to save and restore matrices (coordinate systems) for different levels in the hierarchy

Compute current matrixPush onto the stackMatrix at the top of the stack is the active matrixWhen done with this object,

Pop matrixPop matrixReturn to previous (parent) matrixReturn to previous (parent) matrix

Page 21: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Hierarchical Modeling: Coordinate SystemsHierarchical Modeling: Coordinate Systems

Object or Model CoordinatesLocal coordinate system of an objectChosen to conveniently describe the objectExamples:

Sphere has its center at the originSphere has its center at the originBolts in an airplane are described in units of millimetersBolts in an airplane are described in units of millimeters

World CoordinatesCoordinate system to define the entire sceneChosen to conveniently describe the scene (world)Examples:

Origin defined at the Southern tip of ManhattanOrigin defined at the Southern tip of ManhattanThe airplane is described in units of meters (or worse inches)The airplane is described in units of meters (or worse inches)

Many intermediate coordinate systems

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Hierarchical Modeling: AnimationHierarchical Modeling: Animation

Animations describe changes in a model over timeCharacters are moving across the scene by moving their legsCars are driving down the street (wheels are spinning)Birds are flapping their wings while flying through the air

Each motion has to be described by transformation of the proper object in the proper coordinate system

Mistakes can lead to surprising resultsCharacters loose their legs, cars rotate around their wheels, etc.

Transformations are parameterized in timeFor example, position as a function of timex(t) = x(t-1) + 5

Page 22: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Hierarchical Modeling: AnimationHierarchical Modeling: Animation

Modeling a robot with body, head, arms and grabber

Each is described in its own, local coordinatesPieced together using a scene graphConsider moving the robot, lifting an arm, rotating the grabber, ...

Grabber

Arm

HeadBody

World Coordinates

ArmCoordinates

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Hierarchical Modeling: AnimationHierarchical Modeling: Animation

Body

Arm

Head

Grabber

Page 23: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

OpenGLOpenGL

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

OpenGL: IntroductionOpenGL: Introduction

OpenGL is a graphics system implementing a state machine

First, the current state is defined by issuing state commands, e.g. defining the current color or current transformation.Then, objects are processed using the current state.

OpenGL is (mostly) an immediate mode APICommands take immediate effect and are not collectedSmall amount of internal buffering for efficiency

Page 24: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

OpenGL: Rendering CommandsOpenGL: Rendering Commands

Vertex-based renderingMeaning of vertices is defined by the current rendering primitiveRendering primitive defined by a glBegin() - glEnd() pairAll vertices are subject to current state, e.g. transformation matrix or lighting conditions

For example: Drawing a triangleglBegin(GL_TRIANGLES) ;

glVertex3f (0.0, 0.0, 0.5) ;glVertex3f (0.0, 1.0, 0.5) ;glVertex3f (1.0, 1.0, 0.5) ;

glEnd () ;

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

OpenGL: Matrix RepresentationOpenGL: Matrix Representation

OpenGL matrices are represented as one-dimensional array of 16 numbers, e.g. GLfloat m[16]OpenGL stores the matrix in column-major form:

Memory layout of C arrays is row-major, i.e. different from OpenGL

M[i][j] refers to i-th column and j-th row !!

M =

F

H

GGGG

I

K

JJJJ

m m m mm m m mm m m mm m m m

0 4 8 12

1 5 9 13

2 6 10 14

3 7 11 15

Page 25: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

OpenGL: Matrix CommandsOpenGL: Matrix Commands

glMatrixMode()OpenGL manages 3 matrices: ModelView, Projection and TextureWe will only use ModelView and Projection matrices

glLoadIdentity()Makes the active matrix an identity matrix

glLoadMatrix()Assigns values to the active matrix

glMultMatrix()Post-multiplies current matrix with specified matrix

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

OpenGL: Matrix StacksOpenGL: Matrix Stacks

glPushMatrix()Push current matrix onto the active matrix stack

glPopMatrix()Pop the top matrix and make it the current matrix

Page 26: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

OpenGL: Modeling TransformationsOpenGL: Modeling Transformations

glTranslate()Translation of an object along a given vector

glRotate()Rotation of an object ccw around a given axis by a specified angle

glScale()Scale an object independently along x, y, and z axis

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

SummarySummary

Raster Graphics PipelineOverview and basic understanding of major components

Geometric transformations and hierarchical modelingElementary transformationsRigid body, linear, affine transformationsHomogeneous coordinatesHierarchical modelingBasic animations

If you had any problems with this material ...

Brush up on your basic geometry and linear algebra !!

Page 27: Computer Graphics - Week 2 - Department of …feiner/courses/csw4160/slides/S99-2.pdfComputer Graphics - Week 2 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

HomeworkHomework

Foley et al., Chapter 6

Start reading OpenGL Programming Guide

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 2

Next week ...Next week ...

More on transformations and coordinates systemsViewing transformations and camera models

More on OpenGL

First Assignment

Front-view

Top-view(Plan-view)

Side-view

Z

Y

Front Back

Top

Bottom

VP M vpper= •

F

H

GGGG

I

K

JJJJ=

F

H

GGGG

I

K

JJJJ•

F

H

GGGG

I

K

JJJJ=

F

H

GGGG

I

K

JJJJ⇒ =

FHGG

IKJJ•

0010

1 0 0 00 1 0 00 0 1 00 0 1 1

0010

001

1

00

/ /d dd