52
CSCE 441: Computer Graphics: Hierarchical Models Jinxiang Chai

CSCE 441: Computer Graphics: Hierarchical Models

  • Upload
    lindsay

  • View
    76

  • Download
    2

Embed Size (px)

DESCRIPTION

CSCE 441: Computer Graphics: Hierarchical Models. Jinxiang Chai. Summary: 3D Geometry Pipeline. Object space. World space. View space. Normalized project space. Image space. 2. Complex Models. Outline. Hierarchical Models - PowerPoint PPT Presentation

Citation preview

Page 1: CSCE 441:  Computer Graphics: Hierarchical Models

CSCE 441: Computer Graphics:Hierarchical Models

Jinxiang Chai

Page 2: CSCE 441:  Computer Graphics: Hierarchical Models

Image space

2

Normalized project

space

View spaceWorld spaceObject space

Summary: 3D Geometry Pipeline

Page 3: CSCE 441:  Computer Graphics: Hierarchical Models

Complex Models

Page 4: CSCE 441:  Computer Graphics: Hierarchical Models

Outline

Hierarchical Models

Reading: HB 9-8&9-9, HB chapter 11, OpenGL Programming Guide, chapter 3, and course slides

Page 5: CSCE 441:  Computer Graphics: Hierarchical Models

• Most graphics API supports a few primitives: - sphere - cube - cylinders

• These symbols are instanced using instance/model transformation:

Symbols and Instances

Page 6: CSCE 441:  Computer Graphics: Hierarchical Models

• Most graphics API supports a few primitives: - sphere - cube - cylinders

• These symbols are instanced using instance transformation:

Symbols and Instances

What’s the matrix for the instance transformation above?

Page 7: CSCE 441:  Computer Graphics: Hierarchical Models

• Most graphics API supports a few primitives: - sphere - cube - cylinders

• These symbols are instanced using instance transformation:

Symbols and Instances

),(*)(*),( yxyx ssSRttTM

Page 8: CSCE 441:  Computer Graphics: Hierarchical Models

• In opengl, instance/model transformation is created by modifying the Model-view matrix:

Sample Instance Trans.

glMatrixMode(GL_MODELVIEW);glLoadIdentity(…);// set current matrix to the identityglTranslate(…); // translate glRotate(…); //rotateglScale(…);//scalehouse();

),(*)(*),(* yxyx ssSRttTI

Page 9: CSCE 441:  Computer Graphics: Hierarchical Models

• In opengl, instance transformation is created by modifying the Model-view matrix:

Sample Instance Trans.

Does the transform seem to be backward?

glMatrixMode(GL_MODELVIEW);glLoadIdentity(…);glTranslate(…);glRotate(…);glScale(…);house();

Page 10: CSCE 441:  Computer Graphics: Hierarchical Models

• Opengl postmultiplies transformation matrices as they are called

• Each subsequent transformation call concatenates the designated transformation matrix on the right of the composite matrix

• We must invoke the transformation in the opposite order from which they are applied.

Composite Transformation: Opengl Implementation

glMatrixMode(GL_MODELVIEW);glLoadIdentity(…);M4;M3;M2;M1;…

xMMMMIx *****' 1234

Page 11: CSCE 441:  Computer Graphics: Hierarchical Models

Lamp

• What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

03221100 )()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp

),,( 0yx0c

11

Page 12: CSCE 441:  Computer Graphics: Hierarchical Models

Lamp

• Suppose we know how to draw each bone in local reference frames

A

Page 13: CSCE 441:  Computer Graphics: Hierarchical Models

Lamp

• How can we draw the character under a particular pose

A

Page 14: CSCE 441:  Computer Graphics: Hierarchical Models

Lamp

• What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

03221100 )()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp

),,( 0yx0c

14

Page 15: CSCE 441:  Computer Graphics: Hierarchical Models

Lamp

• What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

03221100 )()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp

),,( 0yx0c

15

Page 16: CSCE 441:  Computer Graphics: Hierarchical Models

Lamp

• What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

03221100 )()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp

),,( 0yx0c

16

Page 17: CSCE 441:  Computer Graphics: Hierarchical Models

Lamp

• What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

03221100 )()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp

),,( 0yx0c

17

Page 18: CSCE 441:  Computer Graphics: Hierarchical Models

Lamp Implementation• The lamp can be displayed by computing a global matrix

and computing it at each step

)(),( 0RyxT

)(),0()(),( 100 RlTRyxT

)0,()()0,()(),0()(),( 221100 lTRlTRlTRyxT

lamp()

{

M_model =

base();

M_model =

upper_arm();

M_model =

middel_arm();

M_model =

lower_arm();}

)()0,()()0,()(),0()(),( 3221100 RlTRlTRlTRyxT

Matrix M_model;

Main()

{ …

M_model=Identity()

lamp();

}

Page 19: CSCE 441:  Computer Graphics: Hierarchical Models

Lamp Implementation• The lamp can be displayed by computing a global matrix

and computing it at each step

)(),( 0RyxT

)(),0()(),( 100 RlTRyxT

)()0,()(),0()(),( 21100 RlTRlTRyxT

lamp()

{

M_model =

base();

M_model =

upper_arm();

M_model =

middel_arm();

M_model =

lower_arm();}

)()0,()()0,()(),0()(),( 3221100 RlTRlTRlTRyxT

Can we make it more efficiently?

Matrix M_model;

Main()

{ …

M_model=Identity()

lamp();

}

Page 20: CSCE 441:  Computer Graphics: Hierarchical Models

Better Implementation• Instead of recalculating the global matrix each time, we

can just update it in place

)(),( 0RyxT

)(),0( 10 RlT

)()0,( 21 RlT

Matrix M_model;

Main()

{ …

M_model=Identity()

lamp();

}

lamp()

{

M_model *=

base();

M_model *=

upper_arm();

M_model *=

middel_arm();

M_model *=

lower_arm();}

)()0,( 32 RlT

Page 21: CSCE 441:  Computer Graphics: Hierarchical Models

Opengl Implementation• Opengl maintains a global state matrix called model-view

matrix

2D_lamp(x, y, θ0, θ1, θ2, θ3){ glTranslatef(x,y,0) glRotatef(θ0,0,0,1,); base(); glTranslatef(0,l0,0) glRotatef(θ1,0,0,1,); upper_arm(); glTranslatef(0,l1,0) glRotatef(θ2,0,0,1,); middel_arm(); glTranslatef(0,l2,0) glRotatef(θ3,0,0,1,); lower_arm();}

Main(){ … glMatrixMode(GL_MODELVIEW); glLoadIdentity();

2D_lamp(a,b,c,d,e,f) …}

//set current matrixto identity

Page 22: CSCE 441:  Computer Graphics: Hierarchical Models

Hierarchical Modeling• Consider a model of a car – how many symbols? – how many instances?

Page 23: CSCE 441:  Computer Graphics: Hierarchical Models

Hierarchical Modeling• Consider a model of a car – 2 symbols : – 5 instances :

Page 24: CSCE 441:  Computer Graphics: Hierarchical Models

Hierarchical Modeling• Consider a model of a car – 2 symbols : chassis + wheel – 5 instances : 1 chassis + 4 wheel

World system

front-left wheel system

Chasis system

Page 25: CSCE 441:  Computer Graphics: Hierarchical Models

Hierarchical Modeling• Consider a model of a car – 2 symbols : chassis + wheel – 5 instances : 1 chassis + 4 wheel

• We can represent our car as a tree to show the relationship between the parts

- tree nodes store subparts - transition edges represent relationship

between the parts

Page 26: CSCE 441:  Computer Graphics: Hierarchical Models

Hierarchical Modeling• Consider a model of a car – 2 symbols : chassis + wheel – 5 instances : 1 chassis + 4 wheel

• We can represent our car as a tree to show the relationship between the parts

• However, since all 4 wheels are instances of the same model, we’d like to only have that model appear once

Page 27: CSCE 441:  Computer Graphics: Hierarchical Models

Hierarchical Modeling• Hierarchical model can be composed of instances using

trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometry of subparts

Page 28: CSCE 441:  Computer Graphics: Hierarchical Models

Hierarchical Modeling

What might we draw the tree for the lamp?

• Hierarchical model can be composed of instances using trees or directed acyclic graphs (DAGs)

- edges contains geometric transformations - nodes contains geometry of subparts

Page 29: CSCE 441:  Computer Graphics: Hierarchical Models

Hierarchical Modeling• Hierarchical model can be composed of instances using

trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometry

1

23c

2c

1c

A

Page 30: CSCE 441:  Computer Graphics: Hierarchical Models

Hierarchical Modeling• Hierarchical model can be composed of instances using

trees or directed acyclic graphs (DAGs) - edges contains geometric transformations - nodes contains geometry

lower arm

base

Upper arm

world

)(),( 0RyxT

)(),0( 10 RlT

)()0,( 21 RlT

)()0,( 32 RlTmiddle arm1

23c

2c

1c

A

Page 31: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

torso

Page 32: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

torso

Page 33: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most efficient way to draw this figure?

torso

Page 34: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 35: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 36: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 37: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 38: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 39: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 40: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 41: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 42: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 43: CSCE 441:  Computer Graphics: Hierarchical Models

A More Complex Example: Human Figure

What’s the most sensible way to traverse this tree?

torso

Page 44: CSCE 441:  Computer Graphics: Hierarchical Models

Opengl Implementation: Human Figure

Mh

Mlua

Mlla

torso

Page 45: CSCE 441:  Computer Graphics: Hierarchical Models

Opengl Implementation: Human Figure

Mh

Mlua

Mlla

torso

Is this correct?

Page 46: CSCE 441:  Computer Graphics: Hierarchical Models

Opengl Implementation: Human Figure

Mh

Mh*Mlua should be Mlua

Mh*Mlua*Mlla should be Mlua*Mlla

Itorso

Is this correct? No

Page 47: CSCE 441:  Computer Graphics: Hierarchical Models

Matrix Stack

• glMatrixMode(GL_MODELVIEW) - Initially, each of the stacks contains one matrix, an

identity matrix. - The top matrix in the stack is “current matrix” - The depth is at least 32

Mc

…I

11...MMMM kKc

Page 48: CSCE 441:  Computer Graphics: Hierarchical Models

Push and Pop the Current Matrix

• glPushMatrix() copy the current matrix at the top of the stack

Mc

… Mc

Mc

II

Page 49: CSCE 441:  Computer Graphics: Hierarchical Models

Push and Pop the Current Matrix

• glPopMatrix() destroies the matrix at the top of stack

Mtop-1

Mtop Mtop-1

II

Page 50: CSCE 441:  Computer Graphics: Hierarchical Models

Opengl Implementation: Human Figure

Page 51: CSCE 441:  Computer Graphics: Hierarchical Models

Opengl Implementation: Human Figure

I

Mh

Mlua

Mlua Mlla

Page 52: CSCE 441:  Computer Graphics: Hierarchical Models

Articulated Models