CS184 Section 2
Transformations

Brandon Wang
January 31, 2012
Material adapted from Fu-Chung Huang, and Ravi Ramamoorthi.

Logistics

Today

HW1

You will be implementing a "crystal ball" interface for HW1. You won't need to know much OpenGL/GLUT for this, as Prof. Ramamoorthi will be covering this topic later.

But there are some basics that I'll cover quickly.

HW1

You're modifying HW1 to do rotations. The skeleton code gives you a teapot, and we want you to rotate it, by allowing the user to use arrow keys.

Arrow keys are governed by GLUT. This means we want you to look at main.cpp, and...

glutSpecialFunc(specialKey);
glutKeyboardFunc(keyboard);

And then...

HW1

main.cpp

void keyboard(unsigned char key,int x,int y) {
  switch(key) {
    case '+':
      amount++;
      std::cout << "amount set to " << amount << "\n";
      break;
    /*...*/
  }
  glutPostRedisplay();
}

void specialKey(int key,int x,int y) {
  switch(key) {
    case 100: //left
      Transform::left(amount,eye,up);
      break;
    case 101: //up
      Transform::up(amount,eye,up);
      break;
    /*...*/
  }
  glutPostRedisplay();
}

HW1

Transform.cpp

(Most, if not all your work goes here)

mat3 Transform::rotate(const float degrees, const vec3& axis) {
  mat3 R; 
  // FILL IN YOUR CODE HERE
  return R; 
}

Read the comments! It talks about row-major and column-major vectors

HW1

main.cpp

  if (useGlu) mv = glm::lookAt(eye,center,up); 
  else {
    mv = Transform::lookAt(eye,up); 
    mv = glm::transpose(mv); // accounting for row major
  }
  glLoadMatrixf(&mv[0][0]); 

  /* ... */

  glutSolidTeapot(2);
  glutSwapBuffers();

gluLookAt

Don't move your eyes to see the world

Move the world to be in your field of vision

Simply a rotation followed by a translation

Rodrigues' (Rotation) Formula

We want to rotate by an arbitrary axis.

Why?

It fixes our problem of Gimbal Lock.

Rodrigues' (Rotation) Formula

(On white board)

Transformations: Demonstrations