#include #include "punto2D.h" #include int WIN1, WIN2; //int p[2][1]={{1},{2}}; int p[4][2]={{-60,-60},{60,-60},{60,60},{-60,60}}; int p2[3][2]={{-90,-90},{90,-90},{0,90}}; class quad{ public: quad(){angle =0.0;}; quad(int points[4][2]){ // points vettore di 4 punti int i; angle = 0.0; for(i=0;i<4;i++) pXY[i].SetPxy(points[i][0],points[i][1]); }; quad(int x1,int y1,int x2,int y2, int x3, int y3, int x4, int y4) { angle =0.0; pXY[0].SetPxy(x1,y1); pXY[1].SetPxy(x2,y2); pXY[2].SetPxy(x3,y3); pXY[3].SetPxy(x4,y4); }; void Draw(){ glColor3f(0.0,1.0,0.0); glBegin(GL_QUADS); glVertex2i(pXY[0].GetX(), pXY[0].GetY()); glVertex2i(pXY[1].GetX(), pXY[1].GetY()); glVertex2i(pXY[2].GetX(), pXY[2].GetY()); glVertex2i(pXY[3].GetX(), pXY[3].GetY()); glEnd(); glFlush(); }; inline void SetAngle(float theta){ if(angle < 360) angle += theta; else angle = 0.0; }; inline float GetAngle(){ return(angle); }; private: float angle; point2D pXY[4]; }; class triang{ public: triang(){angle = 0.0;}; triang(int p[3][2]){ int i; angle = 0.0; for(i=0;i<3;i++) pXY[i].SetPxy(p[i][0],p[i][1]); }; triang(int x1, int y1, int x2, int y2, int x3, int y3){ angle = 0.0; pXY[0].SetPxy(x1,y1); pXY[1].SetPxy(x2,y2); pXY[2].SetPxy(x3,y3); } void Draw(){ glColor3f(1.0,0.0,0.0); glBegin(GL_TRIANGLES); glVertex2i(pXY[0].GetX(), pXY[0].GetY()); glVertex2i(pXY[1].GetX(), pXY[1].GetY()); glVertex2i(pXY[2].GetX(), pXY[2].GetY()); glEnd(); glFlush(); }; inline void SetAngle(float theta){ if(angle < 360) angle += theta; else angle = 0.0; } inline float GetAngle(){ return(angle); } private: float angle; //angolo di rotazione point2D pXY[3]; }; triang t(p2); quad q(p); void win1Display(void){ printf("Display1\n"); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(t.GetAngle(),0.0,0.0,1.0); t.Draw(); glPopMatrix(); q.Draw(); glFlush(); } void win2Display(void){ printf("Display2\n"); glClearColor(0.0,0.0,(GLfloat)0.8,0.0); glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(t.GetAngle(),0.0,0.0,1.0); t.Draw(); glPopMatrix(); glPushMatrix(); glRotatef(q.GetAngle(),0.0,0.0,1.0); q.Draw(); glPopMatrix(); glFlush(); } void win1Reshape(int w, int h){ printf("RESHAPE1\n"); glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-150,150,-150,150); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void win2Reshape(int w, int h){ printf("Reshape2\n"); glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-150,150,-150,150); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void win1EntryMouse(int state) { if(state == GLUT_ENTERED){ glutSetWindow(WIN1); } } void win2EntryMouse(int state) { if(state == GLUT_ENTERED){ glutSetWindow(WIN2); } } void winMouse(int b, int state, int x, int y){ if(b==GLUT_LEFT_BUTTON && state == GLUT_DOWN){ t.SetAngle(5.0); q.SetAngle(5.0); glutSetWindow(WIN1); glutPostRedisplay(); glutSetWindow(WIN2); glutPostRedisplay(); } } void InitGLUT(void){ glutInitDisplayMode(GLUT_RGB);// SECONDA FINESTRA glutInitWindowPosition(315,0); glutInitWindowSize(300,300); WIN2=glutCreateWindow("TRANSFORM NON PUSH"); //Registrazione glutDisplayFunc(win2Display); glutReshapeFunc(win2Reshape); glutEntryFunc(win2EntryMouse); glutMouseFunc(winMouse); glutInitDisplayMode(GLUT_RGB);// PRIMA FINESTRA glutInitWindowPosition(0,0); glutInitWindowSize(300,300); WIN1=glutCreateWindow("Transform YES PUSH"); //Registrazione glutDisplayFunc(win1Display); glutReshapeFunc(win1Reshape); glutEntryFunc(win1EntryMouse); glutMouseFunc(winMouse); } void main(int argc, char *argv[]){ glutInit(&argc, argv); InitGLUT(); glutMainLoop(); exit(0); }