#include <stdio.h>
#include <GL/glut.h>
#include <math.h>
static GLfloat spin=0.0;
GLfloat d=0.0;
GLfloat e=0.0;
GLfloat a=0.0;
int autorotate=0;
void display(void){
GLdouble eqn[4] = {0.0,1.0,0.0,0.0};
GLdouble eqn2[4] = {1.0,0.0,0.0,0.0};
GLfloat circle;
GLfloat i;
GLfloat oldx;
GLfloat oldy;
GLfloat alpha;
GLfloat length;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(180.0f,(GLfloat)320/(GLfloat)240, .0f ,0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0,0,0.2,0);
glColor3f (0, 0, 0.9);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
if(autorotate==1){
a++;
glRotatef(a,1,1,1);
if(a==360){
a=0;
}
}
glRotatef(d,1,0,0);
glRotatef(e,0,1,0);
glBegin(GL_LINES);
glVertex3f(0,0,0);
glVertex3f(0,1,0);
glVertex3f(0,0,0);
glVertex3f(0,0,1);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glEnd();
for(i=1;i<360;i+=5){
glBegin(GL_LINES);
for(circle=0;circle<=360;circle++){
glVertex3f(sin(circle/180*M_PI),cos(circle/180*M_PI),0);
}
glEnd();
glRotatef(5,0,1,0);
}
for(i=-1;i<=1;i+=0.1){
length=cos(asin(i));
glBegin(GL_LINES);
for(circle=0;circle<=360;circle++){
if(length!=0){
glVertex3f(length*sin(circle/180*M_PI),i,length*cos(circle/180*M_PI));
}
}
glEnd();
}
glFlush();
glutSwapBuffers();
}
void keyboard(int key, int x, int y){
// glMatrixMode(GL_MODELVIEW);
// glLoadIdentity();
switch(key){
case GLUT_KEY_UP:
printf("key up!\n");
d--;
break;
case GLUT_KEY_DOWN:
printf("key down!\n");
d++;
break;
case GLUT_KEY_LEFT:
printf("key left!\n");
e--;
break;
case GLUT_KEY_RIGHT:
printf("key right!\n");
e++;
break;
case GLUT_KEY_PAGE_UP:
autorotate=1;
a++;
break;
case GLUT_KEY_PAGE_DOWN:
autorotate=0;
break;
}
display();
}
int main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB| GLUT_DEPTH);
glutInitWindowSize(640,480);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)640/(GLfloat)480, .5f ,150.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutInitWindowPosition(0,0);
glutCreateWindow("revenger's tutorial");
glutSpecialFunc(keyboard);
// display();
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
return(0);
} |