Sei sulla pagina 1di 34

Course: Computer Graphics 2010 Lecture 6: geometric transformations Part 1 Vernica Orvalho veronica.orvalho@dcc.fc.up.pt www.dcc.fc.up.pt/~veronica.

orvalho

agenda . brief introduction to transformations . OpenGL: geometric transformation . examples

introduction
rigid body transformations non-rigid body transformations

Images by Ron Fedkiw Stanford University http://physbam.stanford.edu/~fedkiw/

introduction
rigid body transformations

rotation

translation

orient and place the objects on a scene

introduction
non-rigid body transformations

distance between points on objects DO NOT remain constant

introduction
what can you do with transformations?

introduction
what can you do with transformations? rotate translate stretch shrink wrap etc.

(move around)

project 3D coordinates onto a 2D screen

transform
transform: operation that takes an attribute: points, vectors or colors converts them in some way

http://www.lohmueller.business.t-online.de/pov_tut/trans/scale1t.jpg

http://www.ltutech.com

examples
Textures >
http://www.youtube.com/watch?v=QNJMz5xqEuE&feature=related

3D Object >
http://www.youtube.com/watch?v=de7tOeiMcLc

OpenGL transformations
view modeling modelview projection viewport specifies the location of the viewer or camera moves objects around scene describes the duality of viewing and modeling transformations clips and sizes the viewing volume scales final output to the window

OpenGL transformations
view modeling modelview projection viewport specifies the location of the viewer or camera moves objects around scene describes the duality of viewing and modeling transformations clips and sizes the viewing volume scales final output to the window

OpenGL transformations pipeline

OpenGL transformations pipeline


x0 y0 z0 w0
original vertex data

in homogeneous coordinates

OpenGL transformations pipeline


x0 y0 z0 w0
original vertex data

modelview matrix

in homogeneous coordinates

OpenGL transformations pipeline


x0 y0 z0 w0
original vertex data

modelview matrix

xe ye ze we
transformed eye coordinates

in homogeneous coordinates

OpenGL transformations pipeline


x0 y0 z0 w0
original vertex data

modelview matrix

xe ye ze we
transformed eye coordinates

projection matrix

in homogeneous coordinates

OpenGL transformations pipeline


x0 y0 z0 w0
original vertex data

modelview matrix

xe ye ze we
transformed eye coordinates

projection matrix

xc yc zc wc
clip coordinates

in homogeneous coordinates

OpenGL transformations pipeline


x0 y0 z0 w0
original vertex data

modelview matrix

xe ye ze we
transformed eye coordinates

projection matrix

xc yc zc wc
clip coordinates

perspective matrix

in homogeneous coordinates

OpenGL transformations pipeline


x0 y0 z0 w0
original vertex data

modelview matrix

xe ye ze we
transformed eye coordinates

projection matrix

xc yc zc wc
clip coordinates

perspective matrix

xc /wc yc /wc zc /wc


normalized coordinates

in homogeneous coordinates

OpenGL transformations pipeline


x0 y0 z0 w0
original vertex data

modelview matrix

xe ye ze we
transformed eye coordinates

projection matrix

xc yc zc wc
clip coordinates

perspective matrix

xc /wc yc /wc zc /wc


normalized coordinates

viewport trasform (also a matrix)

in homogeneous coordinates

OpenGL transformations pipeline


x0 y0 z0 w0
original vertex data

modelview matrix

xe ye ze we
transformed eye coordinates

projection matrix

xc yc zc wc
clip coordinates

perspective matrix

xc /wc yc /wc zc /wc


normalized coordinates

viewport trasform (also a matrix)

window coordinates

in homogeneous coordinates

translate, rotate and scale in OpenGL


glTranslatef (float x, float y, float z) glRotatef (float angle, float x, float y, float z) glScalef( float x, float y, float z)

translate, rotate and scale in OpenGL


glTranslatef (float x, float y, float z) glTranslatef (0, 2, 0)
y x y
(1,0,0)

you can translate in any direction

translate, rotate and scale in OpenGL


glRotatef (float angle, float x, float y, float z) glRotatef (45, 1, 1, 1) around an arbitrary axis specified by (1,1,1)
y x y
(1,1,1)

the angle of rotation is in counterclockwise

translate, rotate and scale in OpenGL


glScalef (float x, float y, float z) glScalef (2, 1, 1)

2x

multiplies the X, Y, Z values by the scaling factor

the identity matrix in OpenGL


glLoadIdentity () very useful to reset the ModelView Matrix!

the identity matrix in OpenGL


example
// set current matrix to Modelview and rest glMatrixMode( GL_MODELVIEW); glLoadIdentity (); glTranslatef(0, 2, 0); drawObject_1(); glLoadIdentity(); glTranslatef(2, 0, 0); drawObject_2(); //go 2 units up the y-axis //reset modelview matrix again //go 2 units out the x-axis

Example Transformations OpenGL

glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(...); glRotatef(...); glScalef(...); glutSolidCylinder(...)

matrix stack OpenGL

glPushMatrix() matrix stack

glPopMatrix()

Example: http://www.gamedev.net/reference/articles/article1267.asp

matrix stack OpenGL

When to use Push and Pop ? if parts of a model depend on one another. Moving one part, causes other parts to move

Models MUST be arranged as a tree data structure e.g. a simple robot arm

Example: http://www.gamedev.net/reference/articles/article1267.asp

matrix stack OpenGL

matrix stack OpenGL


glLoadIdentity(); glColor3f(1.0, 0.0, 0.0); glRotatef(theta[0], 0.0, 1.0, 0.0); torso(); glPushMatrix(); //save current model-view matrix glTranslatef(0.0, TORSO_HEIGHT+0.5*HEAD_HEIGHT, 0.0); glRotatef(theta[1], 1.0, 0.0, 0.0); glRotatef(theta[2], 0.0, 1.0, 0.0); glTranslatef(0.0, -0.5*HEAD_HEIGHT, 0.0); head(); glPopMatrix(); //we have drawn the head so go back up to torso glPushMatrix(); //but now want to draw left arm so save the torso matrix again glTranslatef(-(TORSO_RADIUS+UPPER_ARM_RADIUS), 0.9*TORSO_HEIGHT, 0.0); glRotatef(theta[3], 1.0, 0.0, 0.0); left_upper_arm(); glTranslatef(0.0, UPPER_ARM_HEIGHT, 0.0); glRotatef(theta[4], 1.0, 0.0, 0.0); left_lower_arm(); glPopMatrix(); //we have drawn the left_arm so go back up to torso

advance matrix manipulation OpenGL


glFloat m[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; glMatrixMode(GL_MODELVIEW) glLoadMatrixf(m); //Define a translation Matrix glFloat m_t[] = { 1, 0, 0, 10, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; // multiply the translation matrix by the current modelview matrix. // the new matrix becomes the modelview matrix glMatrixMode(GL_MODELVIEW) glLoadMatrixf(m_t);

questions

Potrebbero piacerti anche