//square // Demonstration of Rotation Transformation // Blue square is fixed at the back and colorful square rotates. // The effect of z-buffer i.e. the intersection of two squares is demonstrated. // T. Kosaka CS TNCT 16Aug2002 #include #include #include #include "GLDrawingtool3D.h" #ifndef M_PI #define M_PI 3.141592653589793 #endif void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); // depth check userdraw(); glutSwapBuffers(); } void userdraw(void) { static int tick=0; myInitView(0); point3D_t square0[]={ {200,110,-100},{-200,110,-100},{-200,-110,-100},{200,-110,-100} }; color_t colBlue={0,0,1}; point3D_t square1[]={ {100,100,180},{-100,100,180},{-100,-100,180},{100,-100,180} }; color_t colors[]={{1,0,0},{0,1,0},{1,1,0},{1,0,1}}; fillPolygon(square0,4,colBlue); glRotatef(tick,0,1,0); // angle[deg],x,y,z gradatePolygon(square1,colors,4); // Each point is automatically multiplied with the transformation matrix defined above tick++; } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); // depth check glutInitWindowPosition(100,100); glutInitWindowSize(640,480); glutCreateWindow ("square"); glClearColor(0.0, 0.0, 0.0, 0.0); glViewport(0,0,640,480); glutIdleFunc(display); // idle event call back glutDisplayFunc(display); glEnable(GL_DEPTH_TEST); // depth check (OpenGL inner Z-Buffer) glutMainLoop(); return 0; }