chapter 4.3

Objectives<next>


OpenGL Matrices


Current Transformation Matrix (CTM)


CTM operations


Rotation about a Fixed Point


CTM in OpenGL


Rotation, Translation, Scaling

(see code model.c )

Example


Arbitrary Matrices



Matrix Stacks


Reading Back Matrices



Using Transformations


//main.c
void main(int argc, char **argv)
{


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB |
GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("colorcube");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutIdleFunc(spinCube);
glutMouseFunc(mouse);
glEnable(GL_DEPTH_TEST);

glutMainLoop();
}


//Idle and Mouse callbacks
void spinCube()
{


theta[axis] += 0.05;
if( theta[axis] > 360.0 ) theta[axis] -= 360.0;
glutPostRedisplay();
}

void mouse(int btn, int state, int x, int y)
{


if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN)
axis = 0;
if(btn==GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)
axis = 1;
if(btn==GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
axis = 2;
}


//Display callback
void display()
{


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
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(); //left for later
glutSwapBuffers();
}


Using the Model-View Matrix



Smooth Rotation


Incremental Rotation


Interfaces


Building Models



Objectives


Representing a Mesh


Simple Representation


Inward and Outward Facing Polygons


Geometry vs Topology


Vertex Lists



Shared Edges


Edge List

 


Modeling a Cube (as in cube.c)


Drawing a polygon from a list of indices


Efficiency


Vertex Arrays



Initialization


Mapping indices to faces


Drawing the cube