// A rotating star(pentagram) with class // T. Kosaka CS TNCT 2Aug2002 #include #include #include #include "CGCore2D.h" #ifndef M_PI #define M_PI 3.141592653589793 #endif void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); userdraw(); glutSwapBuffers(); } ////////////////////////////////////////////////////////////////// void drawcharX(float x,float y) //文字 x の表示 { C_Color white(1.,1.,1.); C_Line charX1(x,y,x+10,y+12,white); charX1.draw(); C_Line charX2(x,y+12,x+10,y,white); charX2.draw(); } void drawcharY(float x,float y) //文字 y の表示 { C_Color white(1.,1.,1.); C_Line charY1(x+5,y,x+5,y+7,white); charY1.draw(); C_Line charY2(x,y+12,x+5,y+7,white); charY2.draw(); C_Line charY3(x+10,y+12,x+5,y+7,white); charY3.draw(); } void drawAxes(void) // xy軸の表示 { C_Color white(1.,1.,1.); C_Line charAX1(-310,0,310,0,white); charAX1.draw(); C_Line charAX2(310,0,300,5,white); charAX2.draw(); C_Line charAX3(310,0,300,-5,white); charAX3.draw(); drawcharX(300,-20); C_Line charAY1(0,-230,0,230,white); charAY1.draw(); C_Line charAY2(0,230,5,220,white); charAY2.draw(); C_Line charAY3(0,230,-5,220,white); charAY3.draw(); drawcharY(-20,220); } ////////////////////////////////////////////////////////////////// void userdraw(void) { static int tick=0; C_Point pentagram00[5]; int i; for (i=0;i<5;i++) { float theta=M_PI*(4.*i/5+0.5); pentagram00[i].x=20.*cos(theta); pentagram00[i].y=20.*sin(theta); } C_Color cyan(0.,1.,1.); C_Polygon pentagram0(pentagram00,5,cyan); C_Polygon pentagram; C_Matrix mat,trans,rot1,rot2; drawAxes(); trans.setTranslation(160,0); rot1.setRotation(tick*0.1); rot2.setRotation(tick*0.03); mat=rot2*trans*rot1; pentagram=mat*pentagram0; pentagram.draw(); tick++; } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB ); glutInitWindowPosition(100,100); glutInitWindowSize(640,480); glutCreateWindow ("Rotating star"); glClearColor(0.0, 0.0, 0.0, 0.0); gluOrtho2D(-320., 320., -240.0, 240.0); // Define the dimensions of the Orthographic Viewing Volume glutIdleFunc(display); // idle event call back glutDisplayFunc(display); glutMainLoop(); return 0; }