06 cg transformation 01

Upload: dereje-dhufera

Post on 03-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 06 CG Transformation 01

    1/34

    Course:Computer Graphics 2010

    Lecture 6:

    geometric transformationsPart 1

    Vernica [email protected]

    www.dcc.fc.up.pt/~veronica.orvalho

    mailto:[email protected]:[email protected]
  • 7/28/2019 06 CG Transformation 01

    2/34

    agenda

    . brief introduction to transformations

    . OpenGL: geometric transformation

    . examples

  • 7/28/2019 06 CG Transformation 01

    3/34

    introduction

    rigid bodytransformations non-rigid bodytransformations

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

  • 7/28/2019 06 CG Transformation 01

    4/34

    introduction

    rigid body transformations

    orient and place the objects on a scene

    rotation translation

  • 7/28/2019 06 CG Transformation 01

    5/34

    introduction

    non-rigid body transformations

    distance between points on objects

    DO NOT remain constant

  • 7/28/2019 06 CG Transformation 01

    6/34

    introduction

    what can you do with transformations?

  • 7/28/2019 06 CG Transformation 01

    7/34

    introduction

    what can you do with transformations?

    rotatetranslate

    stretchshrinkwrapetc.

    project 3D coordinates onto a 2D screen

    (move around)

  • 7/28/2019 06 CG Transformation 01

    8/34

    transform:operation that takes an attribute:points, vectors or colors

    converts them in some way

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

    transform

  • 7/28/2019 06 CG Transformation 01

    9/34

    examples

    Textures >

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

    3D Object >

    http://www.youtube.com/watch?v=de7tOeiMcLc

  • 7/28/2019 06 CG Transformation 01

    10/34

    OpenGL transformations

    view

    modeling

    modelview

    projection

    viewport

    specifies the location of theviewer or camera

    moves objects around scene

    describes the duality of viewingand modeling transformations

    clips and sizes the viewing

    volume

    scales final output to thewindow

  • 7/28/2019 06 CG Transformation 01

    11/34

    OpenGL transformations

    view

    modeling

    modelview

    projection

    viewport

    specifies the location of theviewer or camera

    moves objects around scene

    describes the duality of viewingand modeling transformations

    clips and sizes the viewing

    volume

    scales final output to thewindow

  • 7/28/2019 06 CG Transformation 01

    12/34

    OpenGL transformations pipeline

  • 7/28/2019 06 CG Transformation 01

    13/34

    OpenGL transformations pipeline

    xyzw

    0

    0

    0

    0

    originalvertexdata

    in homogeneouscoordinates

  • 7/28/2019 06 CG Transformation 01

    14/34

    OpenGL transformations pipeline

    xyzw

    0

    0

    0

    0

    modelviewmatrix

    originalvertexdata

    in homogeneouscoordinates

  • 7/28/2019 06 CG Transformation 01

    15/34

    OpenGL transformations pipeline

    xyzw

    0

    0

    0

    0

    modelviewmatrix

    xyzw

    e

    e

    e

    e

    originalvertexdata

    transformedeye

    coordinates

    in homogeneouscoordinates

  • 7/28/2019 06 CG Transformation 01

    16/34

    OpenGL transformations pipeline

    xyzw

    0

    0

    0

    0

    modelviewmatrix

    xyzw

    e

    e

    e

    e

    projectionmatrix

    originalvertexdata

    transformedeye

    coordinates

    in homogeneouscoordinates

  • 7/28/2019 06 CG Transformation 01

    17/34

    OpenGL transformations pipeline

    xyzw

    0

    0

    0

    0

    modelviewmatrix

    xyzw

    e

    e

    e

    e

    projectionmatrix

    xyzw

    c

    c

    c

    c

    originalvertexdata

    transformedeye

    coordinates

    clipcoordinates

    in homogeneouscoordinates

  • 7/28/2019 06 CG Transformation 01

    18/34

    OpenGL transformations pipeline

    xyzw

    0

    0

    0

    0

    modelviewmatrix

    xyzw

    e

    e

    e

    e

    projectionmatrix

    xyzw

    c

    c

    c

    c

    perspectivematrix

    originalvertexdata

    transformedeye

    coordinates

    clipcoordinates

    in homogeneouscoordinates

  • 7/28/2019 06 CG Transformation 01

    19/34

    OpenGL transformations pipeline

    xyzw

    0

    0

    0

    0

    modelviewmatrix

    xyzw

    e

    e

    e

    e

    projectionmatrix

    xyzw

    c

    c

    c

    c

    perspectivematrix

    x /wy /wz /w

    c

    c

    c

    c

    c

    c

    originalvertexdata

    transformedeye

    coordinates

    clipcoordinates

    normalized

    coordinatesin homogeneouscoordinates

  • 7/28/2019 06 CG Transformation 01

    20/34

    OpenGL transformations pipeline

    xyzw

    0

    0

    0

    0

    modelviewmatrix

    xyzw

    e

    e

    e

    e

    projectionmatrix

    xyzw

    c

    c

    c

    c

    perspectivematrix

    x /wy /wz /w

    cc

    c

    viewporttrasform(also amatrix)

    cc

    c

    originalvertexdata

    transformedeye

    coordinates

    clipcoordinates

    normalized

    coordinatesin homogeneouscoordinates

  • 7/28/2019 06 CG Transformation 01

    21/34

    OpenGL transformations pipeline

    xyzw

    0

    0

    0

    0

    modelviewmatrix

    xyzw

    e

    e

    e

    e

    projectionmatrix

    xyzw

    c

    c

    c

    c

    perspectivematrix

    x /wy /wz /w

    cc

    c

    viewporttrasform(also amatrix)

    cc

    c

    windowcoordinates

    originalvertexdata

    transformedeye

    coordinates

    clipcoordinates

    normalized

    coordinatesin homogeneouscoordinates

  • 7/28/2019 06 CG Transformation 01

    22/34

    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

  • 7/28/2019 06 CG Transformation 01

    23/34

    glTranslatef (float x, float y, float z)

    glTranslatef (0, 2, 0)

    translate, rotate and scale in OpenGL

    x

    y

    x

    y

    you can translate in any direction

    (1,0,0)

  • 7/28/2019 06 CG Transformation 01

    24/34

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

    glRotatef (45, 1, 1, 1)

    around an arbitrary axis specified by (1,1,1)

    translate, rotate and scale in OpenGL

    x

    y

    x

    y

    the angle of rotation is in counterclockwise

    (1,1,1)

  • 7/28/2019 06 CG Transformation 01

    25/34

    glScalef (float x, float y, float z)

    glScalef (2, 1, 1)

    translate, rotate and scale in OpenGL

    multiplies the X, Y, Z values by the scalingfactor

    2x

  • 7/28/2019 06 CG Transformation 01

    26/34

    glLoadIdentity ()

    very useful to reset the ModelView Matrix!

    the identity matrix in OpenGL

  • 7/28/2019 06 CG Transformation 01

    27/34

    example

    // set current matrix to Modelview and restglMatrixMode( GL_MODELVIEW);glLoadIdentity ();

    glTranslatef(0, 2, 0); //go 2 units up the y-axisdrawObject_1();

    glLoadIdentity(); //reset modelview matrix againglTranslatef(2, 0, 0); //go 2 units out the x-axisdrawObject_2();

    the identity matrix in OpenGL

  • 7/28/2019 06 CG Transformation 01

    28/34

    Example Transformations OpenGL

    glMatrixMode(GL_MODELVIEW);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glLoadIdentity();glTranslatef(...);glTranslatef(...);

    glRotatef(...);glRotatef(...);glScalef(...);glScalef(...);glutSolidCylinder(...)glutSolidCylinder(...)

  • 7/28/2019 06 CG Transformation 01

    29/34

    matrix stack OpenGL

    glPushMatrix() glPopMatrix()

    matrix stack

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

    k

  • 7/28/2019 06 CG Transformation 01

    30/34

    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 datastructure e.g. a simple robot arm

    Example:

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

    i k O GL

  • 7/28/2019 06 CG Transformation 01

    31/34

    matrix stack OpenGL

    i k O GL

  • 7/28/2019 06 CG Transformation 01

    32/34

    matrix stack OpenGLglLoadIdentity();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 againglTranslatef(-(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

    d t i i l ti O GL

  • 7/28/2019 06 CG Transformation 01

    33/34

    advance matrix manipulation OpenGLglFloat 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);

  • 7/28/2019 06 CG Transformation 01

    34/34

    questions