hierarchical transformation

23
Hierarchical Transformation

Upload: bertha-hardy

Post on 02-Jan-2016

39 views

Category:

Documents


1 download

DESCRIPTION

Hierarchical Transformation. Summary. If we think : Each transformation updates the vertex in an absolute world. Then, the code is arranged in a reverse order. Alternatively, OpenGL thinks: A transformation updates the coordinate system. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Hierarchical Transformation

Hierarchical Transformation

Page 2: Hierarchical Transformation

Summary

• Alternatively, OpenGL thinks:• A transformation updates the coordinate system.• For each change, the transformation is defined in the

current (local) coordinate system.• Transformation matrix and coordinate system are

equivalent.• The code is in the forward order!

• If we think:• Each transformation updates the vertex in an

absolute world.• Then, the code is arranged in a reverse order.

Page 3: Hierarchical Transformation

A hierarchy

WglLoadIdentity();//A dot at 0,0,0

W

Page 4: Hierarchical Transformation

A hierarchy

W

L1

glLoadIdentity();//A dot at 0,0,0glTranslatef(2,0,0);//A dot at 0,0,0

L1W

Page 5: Hierarchical Transformation

A hierarchy

W

L1

L2

glLoadIdentity();//A dot at 0,0,0glTranslatef(2,0,0);//A dot at 0,0,0glTranslatef(1,1,0);glRotatef(45,0,0,1);//A dot at 0,0,0

L1

L2W

Page 6: Hierarchical Transformation

A hierarchy

L1

L2W

L3

W

L1

L2

glLoadIdentity();//A dot at 0,0,0glTranslatef(2,0,0);//A dot at 0,0,0glTranslatef(1,1,0);glRotatef(45,0,0,1);//A dot at 0,0,0glTranslatef(1,1,0);glRotate(45,0,0,1);//A dot at 0,0,0 L3

Page 7: Hierarchical Transformation

A hierarchy

glLoadIdentity();//A dot at 0,0,0glTranslatef(2,0,0);//A dot at 0,0,0glTranslatef(1.41,0,0);glRotatef(90,0,0,1);//A dot at 0,0,0glTranslatef(1,1,0);glRotate(45,0,0,1);//A dot at 0,0,0

L1

L2

W

L3

Unchanged

W

L1

L2

L3

Page 8: Hierarchical Transformation

A hierarchy

L1W

L4

L2

L3

W

L1

L2

L3 L4• Draw in W• W->L1; Draw in L1• L1->L2; Draw in L2• L2->L3; Draw in L3• L3->L2;• L2->L4; Draw in L4

Page 9: Hierarchical Transformation

A hierarchy

L1W

L4

L2

L3

W

L1

L2

L3 L4• Draw in W• W->L1; Draw in L1• L1->L2; Draw in L2• L2->L3; Draw in L3• L3->L2;• L2->L4; Draw in L4• L4->L2• L2->L1• L1->L5; Draw in L5

L5

L5

Page 10: Hierarchical Transformation

Summary

W

L1

L2

L3 L4

L5

• The skeleton model can be defined as a tree.

• Rendering can be done by depth-first transversal.

• Matrix and coordinate system has the same idea: the matrix gives

• You can use inverse transformation (not a good way) to rewind:• such as L3->L2, L2->L1…

Page 11: Hierarchical Transformation

2

1

Matrix Stack

//Transformation+DrawglPushMatrix();//Transformation+DrawglPushMatrix();//Transformation+DrawglPopMatrix();//Transformation+DrawglPushMatrix();//Transformation+DrawglPopMatrix();//Transformation+DrawglPopMatrix();

Matrix 1

Matrix 2

Matrix 2

Matrix 3

Matrix 3

Matrix 1

1

1

3 1

1

Page 12: Hierarchical Transformation

Matrix Stack

W

L1

L2

L3 L4

L5

//Starts with W//Do W->L1glPushMatrix(); //Back up L1//Do L1->L2glPushMatrix(); //Back up L2//Do L2->L3glPopMatrix(); //Restore L2//Do L2->L4glPopMatrix(); //Restore L1//Do L1->L5//Done

Instead of doing inverse transformation, we can easily rewind using the matrix stack.

Depth-First Traversal

Page 13: Hierarchical Transformation

The Human Body

Hip

Abdomen lButtock rButtock

Chest

Neck lCollar rCollar

lShoulder

lForeArm

lHand

Head rShoulder

rForeArm

rHand

lThigh

lShin

lFoot

lToe

End

rThigh

rShin

rFoot

rToe

End

Page 14: Hierarchical Transformation

Motion Capture

Page 15: Hierarchical Transformation

Performance Capture

Page 16: Hierarchical Transformation

BVH

• The Biovision Hierarchy (BVH) file format was developed by Biovision, a defunct motion capture company.

• It stores motion capture data.• It’s a text file.• It matches with OpenGL well. (That is why you

will learn how to use it in Lab2.)• It has two parts: hierarchy and data.

Page 17: Hierarchical Transformation

Part 1: Hierarchy

• The hierarchy is a joint tree.• Each joint has an offset and a channel list.

• Offset is a bone vector (defined in L1) from Joint 1 to Joint 2.

• Let L12 be a shifted L1 at Joint 2.• The channel list defines a

sequence of transformationsfrom L12 to L2.

L1

L2

Joint 1

Joint 2

L12

Page 18: Hierarchical Transformation

Part 1: Hierarchy• The channel list uses nine deformations:• Xposition, Yposition, Zposition• Xrotation, Yrotation, Zrotation• Xscale, Yscale, Zscale

• The list only tells us transformation types and their orders. The order is the same as in OpenGL.

• To know the actual transformation,we need to read the data.

L1

L2

Joint 1

Joint 2

L12

Page 19: Hierarchical Transformation

An exampleChest Joint and its local coordinate system

Neck Joint and its local coordinate system

Neck’s offset from chest(like a bone)

Channel list:Transformation from chest coordinate

system to neck coordinate system

Page 20: Hierarchical Transformation

Variable 1 Variable 2 Variable 3

Variable 4 Variable 5 Variable 6

Variable 7 Variable 8 Variable 9• The data part stores a number of frames.• Each frame is a list of variables.• The model is animated, when each frame uses

variables.

Part 2: Data

Page 21: Hierarchical Transformation

How to use BVH.h

class BVH{public:

BVH_NODE root;…void Read_File(…);void

Set_Data(frame_id);void Forward();void Backward();void Render();

}

• BVH.h does most things for you.• Your job is to complete the render function.

class BVH_NODE{public:

char name[1024];float offset[3];BVH_NODE* children;int children_number;

float *tx, *ty, *tz;float *rx, *ry, *rz;float *sx, *sy, *sz;int data_order[9];

}

Page 22: Hierarchical Transformation

The Data OrderIn data_order:

1 means tx; 2 means ty; 3 means tz4 means rx; 5 means ry; 6 means rz7 means sx; 8 means sy; 9 means sz

0 means end

327950

• Translate *tz• Translate *ty• Scale *sx• Scale *sz• Rotate *ry• end

Page 23: Hierarchical Transformation

The Camera View

• To change the camera view

• We can update the gluLookAt function (which is not very easy…).

• Or, we can combine gluLookAt with transformation functions. (Check Lab2 for details.)

gluLookAt(eye_x, eye_y, eye_z, center_x, center_y, center_z, up_x, up_y, up_z)