CS184 Section 2
Transformations
Brandon Wang
September 5, 2012
Material adapted from Fu-Chung Huang, and Ravi Ramamoorthi.
Brandon Wang
September 5, 2012
Material adapted from Fu-Chung Huang, and Ravi Ramamoorthi.
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.
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...
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(); }
(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
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();
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
We want to rotate by an arbitrary axis.
Why?
It fixes our problem of Gimbal Lock.
(On white board)