//matrixvector // introducing classes and functions for vectors and matrices // // This program demonstrates translation examples. // T. Kosaka CS TNCT 1Aug2002 #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/100)%5; 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 trans,rot,scale,refxaxis,refyaxis,reforg; int loop; drawAxes(); ef0.draw(); switch(disp) { case 0: glutSetWindowTitle("matrixvector"); break; case 1: //translation glutSetWindowTitle("matrixvector - translation"); for (loop=0;loop<4;loop++) { trans.setTranslation(62*(loop+1),22*(loop+1)); ef=trans*ef0; ef.draw(); } break; case 2: //rotation glutSetWindowTitle("matrixvector - rotation"); for (loop=0;loop<4;loop++) { rot.setRotation(1.*(loop+1)); ef=rot*ef0; ef.draw(); } break; case 3: //scaling glutSetWindowTitle("matrixvector - scaling"); for (loop=0;loop<4;loop++) { scale.setScale(1+0.2*(loop+1),1+0.2*(loop+1)); ef=scale*ef0; ef.draw(); } break; case 4: //reflection a special case of scaling glutSetWindowTitle("matrixvector - reflection"); refxaxis.setScale(1.,-1.); refyaxis.setScale(-1.,1.); reforg.setScale(-1.,-1.); ef=refxaxis*ef0; ef.draw(); ef=refyaxis*ef0; ef.draw(); ef=reforg*ef0; ef.draw(); break; default: break; } tick++; } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB ); glutInitWindowPosition(100,100); glutInitWindowSize(640,480); glutCreateWindow ("matrixvector"); 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; }