43
lecture 3 view transformations model transformations GL_MODELVIEW transformation

lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

lecture 3

view transformations

model transformations

GL_MODELVIEW transformation

Page 2: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

view transformations:

How do we map from world coordinates to camera/view/eyecoordinates ?

model transformations:

How do we map from object coordinates to world coordinates?

GL_MODELVIEW transformation

How do we map from object (to world) to view coordinates?

Page 3: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:
Page 4: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

How can we specify the viewer's coordinate system ?

Page 5: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Define the z axis of the viewer by a vector from the 'look at'point to the viewer.

Page 6: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

The z coordinate axis of the viewer is a unit vector inthe direction is from the 'look at' point to the viewer.

Page 7: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

To specify the viewer's x and y coordinate axes, weneed to choose from 360 degrees of possibilities.

Which way is up ?

Page 8: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Define any 3D vector Vup suchthat

This defines a plane, containing Vup and z_c .

Page 9: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

will be defined to lie in this plane.

Page 10: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:
Page 11: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

See lecture notes for the calculation.

Page 12: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

eye = ... // 3D pointslookat = ...up = ...

gluLookAt( eye[0], eye[1], eye[2],

lookat[0], lookat[1], lookat[2],

up[0], up[1], up[2] )

What does this definition do ("under the hood") ?Coming soon...

As a programmer using OpenGL, you don't have tocompute these vectors. Instead you just define:

Page 13: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

What is the relationship between the world coordinatesystem and the viewer's coordinate system?

Page 14: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

To re-map a general scene point (x,y,z) from worldcoordinates to viewer coordinates, we translate and rotate.

Page 15: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:
Page 16: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Let the viewer's position be expressed in world coordinates.The matrix T translates the viewer's position to the origin.

Page 17: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

R rotates into the viewer'sorientation.

Page 18: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Recall slide 7 from lecture 2.

R maps to a new coordinate system byprojecting onto new axes.

Page 19: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:
Page 20: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

view transformations:

How do we map from world coordinates to camera/view/eyecoordinates ?

model transformations:

How do we map from object coordinates to worldcoordinates ?

GL_MODELVIEW transformation

How do we map from object (to world) to view coordinates?

Page 21: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

glVertex3f(x1, y1, z1)glVertex3f(x2, y2, z2)glVertex3f(x3, y3, z3)

Page 22: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

glBegin( GL_LINES ) glVertex3f(x1, y1 , z1) glVertex3f(x2, y2 , z2) glVertex3f(x3, y3, z3) glVertex3f(x4, y4 , z4)

// more vertex pairs gives more lines

glEnd()

Page 23: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

glBegin( GL_TRIANGLES ) glVertex3f(x1, y1 , z1) glVertex3f(x2, y2 , z2) glVertex3f(x3, y3, z3) // more vertex triples gives more trianglesglEnd()

Page 24: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

glBegin( GL_POLYGON ) glVertex3f(x1, y1 , z1) glVertex3f(x2, y2 , z2) glVertex3f(x4, y4 , z4) glVertex3f(x3, y3 , z3)glEnd()

Page 25: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

"Quadric" (Quadratic) Surfaces: examples

Page 26: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Quadric Surfaces: General

Page 27: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Recall homogeneous coordinates. Same quadric surfaceis represented if we scale 4D vector by a constant.

Page 28: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:
Page 29: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Q: What is this surface ? (a, b, c > 0)

A: rotated and translated ellipsoid.

Page 30: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

How to define quadric surfaces in OpenGL ?

GLUquadricObj myQuadric = gluNewQuadric()

gluSphere(myQuadric, ...) // need to supplyparametersgluCylinder(myQuadric, ...)

Page 31: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

glutSolidCube()glutWireCube()

glutSolidTorus()glutWireTorus()

glutSolidTeapot()glutWireTeapot()

Non-quadric surfaces from OpenGL Utility Toolkit(GLUT)

Page 32: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

How to transform objects in OpenGL ?

glRotatef( vx, vy, vz, angle )glTranslatef( x, y, z)glScalef( sx, sy, sz)

The parameters of each of these calls specify a 4x4 matrix.

These transformations are not associated with (bound to)any particular object, however.

We'll see how this works next.

Page 33: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Recall how to transform from world coordinatesto viewer coordinates:

Page 34: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

How to transform from dog (object)coordinates to viewer coordinates?

Page 35: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

gluLookAt( ... ) glTranslate( ... )glRotate( ... )

Page 36: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

gluLookAt( ... ) // transform from world coordinates // to viewer/eye coordinates

glTranslate( ... ) // transform position and orientationglRotate( ... ) // of dog to world coordinates

glVertex( ) // etc. all the triangles of the dog object...... // defined in dog coordinate system

Page 37: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

OpenGL is a "state machine". One of its states is theGL_MODELVIEW matrix. This is a 4x4 matrix thattransforms a vertex into eye coordinates.

We would like :

GL_MODELVIEW

GL_MODELVIEW

Page 38: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

glMatrixMode(GL_MODELVIEW)glLoadIdentity()

initializes:GL_MODELVIEW

ASIDE: How to examine the GL_MODELVIEW matrix ?(python)m = (GLfloat * 16)()glGetFloatv(GL_MODELVIEW_MATRIX,m)glModelViewMatrix = [ [ ] ,[ ], [ ], [ ] ]for i in range(16):

glModelViewMatrix[i % 4].append(m[i]) # OpenGL stores in column major orderprint 'GL_MODELVIEW ', glModelViewMatrix

Page 39: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

gluLookAt( ... )

glRotatef( ... )

glTranslatef( ... )

glScalef( ... )

Q: What happens whenyou make these calls ? Answer:

GL_MODELVIEW

Page 40: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:
Page 41: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

glMatrixMode(GL_MODELVIEW)glLoadIdentity()gluLookAt( eye ... , lookat..., up ...)

glTranslate( ...)glRotate(...)drawDog() // glVertex() etc...

glTranslate( ...)glRotate(...)drawHouse() // glVertex() etc...

Problem: the GL_MODELVIEW matrix only keeps trackof one (model to view) transformation. But we may havehundreds of object models.

How do we keep track of all these transformations?

Page 42: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Solution: use a stack of GL_MODELVIEW transformations.

glMatrixMode(GL_MODELVIEW)glLoadIdentity()gluLookAt( eye ... , lookat..., up ...)

glPushMatrix() glTranslate( ...) glRotate(...) drawDog()glPopMatrix()

glPushMatrix() glTranslate( ...) glRotate(...) drawHouse()glPopMatrix()

Page 43: lecture 3 view transformations model transformations GL ...langer/557/3-slides.pdf · As a programmer using OpenGL, you don't have to compute these vectors. Instead you just define:

Summary of Today

viewer coordinate systems

view transformations : gluLookAt()

model transformations : glRotate(), glTranslate(),glScale()

GL_MODELVIEW transformation