Tom Kelliher, CS 320
Mar. 21, 2005
What you should be reading: 4.1--4.9, Appendices B and C as necessary.
More on linear algebra basis of transformations.
If you want to rotate an object about its center, in what order do you apply the three transformations? Does the order matter?
void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w, 2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0); else glOrtho(-2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); }(Note use of
glOrtho
.)
There's a hard way and an easy way to do this. Which way is this?
GLfloat vertices[][3] = {{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}}; GLfloat colors[][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0}, {1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}};
Let p be the way from to . p's color is:
(for each color)
What about points on interior of polygon?
void colorcube(void) { /* map vertices to faces */ polygon(0,3,2,1); polygon(2,3,7,6); polygon(0,4,7,3); polygon(1,2,6,5); polygon(4,5,6,7); polygon(0,1,5,4); } void polygon(int a, int b, int c , int d) { /* draw a polygon via list of vertices */ glBegin(GL_POLYGON); glColor3fv(colors[a]); glVertex3fv(vertices[a]); glColor3fv(colors[b]); glVertex3fv(vertices[b]); glColor3fv(colors[c]); glVertex3fv(vertices[c]); glColor3fv(colors[d]); glVertex3fv(vertices[d]); glEnd(); }Are we following the righthand rule for the outer side of each face? Does order of rendering faces matter?
Why represent a cube this way?
Why the normals in the program code?
void display(void) { /* display callback, clear frame buffer and z buffer, rotate cube and draw, swap buffers */ glLoadIdentity(); glRotatef(theta[0], 1.0, 0.0, 0.0); glRotatef(theta[1], 0.0, 1.0, 0.0); glRotatef(theta[2], 0.0, 0.0, 1.0); colorcube(); glutSwapBuffers(); }
Been here, done this. One face:
Two faces:
Will these give the same result?
glLoadIdentity(); glRotatef(theta[0], 1.0, 0.0, 0.0); /* Rotate about x axis. */ glRotatef(theta[2], 0.0, 0.0, 1.0); /* Rotate about z axis. *. glLoadIdentity(); glRotatef(theta[2], 0.0, 0.0, 1.0); /* Rotate about z axis. *. glRotatef(theta[0], 1.0, 0.0, 0.0); /* Rotate about x axis. */Can you describe the results?