Example simple robotic arm | OBJECTIVE: This lab is to introduce you to 3D perspective animation in OpenGL, including:
|
gluPerspective(30.0, 1.0, 10.0, 600.0);
// Create light components
GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8, 1.0f };
GLfloat specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat position[] = { -50.0f, 40.0f, -50.0f, 1.0f };
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// Assign created components to GL_LIGHT0
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, position);
float colorBlue[] = {0.0,0.0,1.0,1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colorBlue);
You can also let the current color be assigned to material properties (AMBIENT_AND_DIFFUSE by default) by:
glEnable(GL_COLOR_MATERIAL)
M = I
for i=0 to n
M = M Pi Ai
save M
M = M Di
Vi
restore M
where Pi is the transform to position the element relative to its parent
Ai is the transform that animates the element
Di is the transform that prepares the element for animation
(scales and translates the joint to the origin)
Vi are the vertex commands that define the element
glutTimerFunc(1000/fps,updateModel,0)
where updateModel is the user-supplied callback routine that updates the state of the model.
The timer instruction must be re-issued in the updateModel callback routine in order to set up the next iteration.
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)
glutSwapBuffers()
which is typically issued right after all the OpenGl commands have been issued that display all the models.