CSCE 441 Lecture 13

From Notes
Jump to navigation Jump to search

« previous | Wednesday, February 12, 2014 | next »


3D Transformations as Matrices

Rotation

[Io01][(1cosθ)vvT+sinθ(v×_)+cI001][Io01][p1]=[p^1]

Mirror Image

[I2vvT2vvTo01][p1]=[p^1]

Orthogonal Projection

[IvvTvvTo01][p1]=[p^1]

Perspective Projection

Perspective transformations are not Affine!

Rational expressions require modification:

[(vT(eo))IevTe(vTo)vTvTe]

homogeneous coordinates

In affine transformations, our matrix equation was

[Lt01][p1]=[p^1]


Now we use

[Ltcd][p1]=[p^w^]

Where c and d represent the stuff in the denominator of the transformation equation

3D Location is p^w^

Note this equation still works for Affine transformations (where we divide by 1)

Hierarchical Animation

Multiple transformations at each joint of a skeleton.

For example, to move a point on the hand, we have to move the wrist (M1), elbow (M2), and shoulder (M3).

p^=M3M2M1p

In general,

p^=jαjMjp


Transformations in OpenGL

4 types:

  • View
  • Model (put things in the scene)
  • Projection (takes 3D objects and projects onto a 2D surface)
  • Viewport

Commands:

  • glTranslatef(x,y,z)
  • glScalef(x,y,z)
  • glRotatef(theta, vx, vy, vz)
  • glLoadIdentity(void): replaces current matrix with identity matrix (i.e. removes current transformations)
  • glPushMatrix(void) and glPopMatrix(void): copies current matrix to new context and removes current matrix (respectively)


Order matters!

  • glTranslatef(0,1,3) = M[1]
  • glRotatef(45,0,1,0) = M[2]
  • glScalef(1,1,2) = M[3]

M1M2M3P

OpenGL combines model and view matrix:

ModelView=V1M

  1. push matrix
  2. specify viewer using inverse of view transformation (negative translation/rotation and in opposite order): (TR)1M=R1T1M
  3. push matrix
  4. position objects with transformations in opposite order of what you would expect
  5. pop matrix
  6. repeat last 3 steps for each object in scene
  7. pop matrix


Special Matrix Commands

  • glMatrixMode(GL_MODELVIEW) and glMatrixMode(GL_PROJECTION)
  • gluLookAt(ex,ey,ez, cx,cy,cz, ux,uy,uz): set position of eye, direction of thing to look at, and the "up direction"
  • gluPerspective(fov, aspect, near, far)
  • glOrtho(left, right, bottom, top, near far) specify orthogonal projection
  • glViewport(x,y,w,h)