/*
file:quadric_surface.c
二次曲面:圆盘,扇形,圆柱面,球面
*/
#include<GL/glut.h>
GLUquadricObj *object;
double angle = 0;
void keyboard(unsigned char key,int x,int y)
{
if(key == 'r')
{
angle +=6;
glRotated(angle,0,1,0);
glutPostRedisplay();
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
gluQuadricDrawStyle(object,GLU_LINE);
glPushMatrix();
glTranslated(-0.8,0.5,0);
glScaled(0.2,0.2,0.2);
gluDisk(object,0.3,1.0,12,8);
glPopMatrix();
glPushMatrix();
glTranslated(-0.8,-0.7,0);
glScaled(0.2,0.2,0.2);
gluPartialDisk(object,0.3,1.0,12,8,0,60);
glPopMatrix();
glPushMatrix();
glTranslated(-0.2,0,0);
glScaled(0.4,0.4,0.4);
gluSphere(object,1.0, 32,32);
glPopMatrix();
glPushMatrix();
glTranslated(0.7,0,0);
glScaled(0.4,0.4,0.4);
gluCylinder(object,0.4,0.3,1,12,6);
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowSize(400,400);
glutCreateWindow("quadric sufrace: press r to rotate");
object = gluNewQuadric();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;