// rotef with class // various rotation examples of charactor 'F' // the examples of composite transformation // In multiplication of transformation matrices the order of multiplication is important. // T. Kosaka CS TNCT 2Aug2002 #include #include #include #include "CGCore2D.h" 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; int disp=(tick/300)%6; int tickindisp=tick%300; C_Point ef00[10]; ef00[0].x= 10, ef00[0].y=100; ef00[1].x= 10, ef00[1].y= 10; ef00[2].x= 30, ef00[2].y= 10; ef00[3].x= 30, ef00[3].y= 40; ef00[4].x= 60, ef00[4].y= 40; ef00[5].x= 60, ef00[5].y= 60; ef00[6].x= 30, ef00[6].y= 60; ef00[7].x= 30, ef00[7].y= 80; ef00[8].x= 70, ef00[8].y= 80; ef00[9].x= 70, ef00[9].y=100; C_Color cyan(0.,1.,1.); C_Polygon ef0(ef00,10,cyan); C_Polygon ef; C_Matrix mat,trans1,rot1,trans2,rot2,scale; float factor; drawAxes(); ef0.draw(); trans1.setTranslation(-40,-50); trans2.setTranslation(160,0); rot1.setRotation(tickindisp*0.02); rot2.setRotation(tickindisp*0.02); switch(disp) { case 0: //translation -> rotation glutSetWindowTitle("composition - translation -> rotation"); mat=rot1*trans1; break; case 1: //translation -> rotation -> translation glutSetWindowTitle("composition - translation -> rotation -> translation"); mat=trans2*rot1*trans1; break; case 2: //translation -> rotation glutSetWindowTitle("composition - translation -> rotation"); mat=rot1*trans1; break; case 3: //translation -> rotation -> translation -> rotation glutSetWindowTitle("composition - translation -> rotation -> translation -> rotation"); mat=rot2*trans2*rot1*trans1; break; case 4: //translation -> rotation -> translation -> rotation glutSetWindowTitle("composition - translation -> rotation -> translation -> rotation"); rot1.setRotation(-tickindisp*0.02); mat=rot2*trans2*rot1*trans1; break; case 5: //trans -> scaling -> rot -> trans -> rot glutSetWindowTitle("composition - trans -> scaling -> rot -> trans -> rot"); factor=0.3+0.35*(sin(tickindisp*0.1)+1); scale.setScale(factor,factor); rot1.setRotation(-tickindisp*0.02); mat=rot2*trans2*rot1*scale*trans1; break; default: break; } ef=mat*ef0; ef.draw(); tick++; } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB ); glutInitWindowPosition(100,100); glutInitWindowSize(640,480); glutCreateWindow ("composition"); 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; }