8 int culooks::drawing::rotcube[3];
10 culooks::window* culooks::drawing::getWin()
12 for (int iwin=0; iwin<culooks::Windows.size(); iwin++)
13 if ( culooks::Windows.at(iwin).first == glutGetWindow() ) {
14 return culooks::Windows.at(iwin).second;
16 cerr << "Something terrible happened: Could not find window-id!" << endl;
20 int culooks::drawing::getCubeFromPos(int x, int y)
22 culooks::window *Win = getWin();
24 int col = x / ((float)Win->w / Win->layout[0]);
25 int row = Win->layout[1] - y / ((float)Win->h / Win->layout[1]);
27 return col + row*Win->layout[0];
31 void culooks::drawing::motionFunc(int x, int y)
33 culooks::window *Win = getWin();
35 Win->cubes.at(rotcube[0]).az += rotcube[1] - x;
36 Win->cubes.at(rotcube[0]).alt += rotcube[2] - y;
45 void culooks::drawing::mouseFunc(int button, int state, int x, int y)
47 culooks::window *Win = getWin();
50 rotcube[0] = getCubeFromPos(x,y);
56 Win->cubes.at(getCubeFromPos(x,y)).zoom *= 1.1;
59 else if (button == 3) {
60 Win->cubes.at(getCubeFromPos(x,y)).zoom *= 0.9;
66 void culooks::drawing::reshapeFunc(int w, int h)
68 culooks::window *Win = getWin();
77 else if ( h == Win->h ) {
79 newh = w / Win->aspect;
82 neww = ( pow(Win->aspect,2)*w + Win->aspect*h ) / ( pow(Win->aspect,2) + 1 );
83 newh = ( Win->aspect*w + h ) / ( pow(Win->aspect,2) + 1 );
86 glutReshapeWindow(neww,newh);
87 glViewport(0,0,neww,newh);
93 void culooks::drawing::displayFunc()
95 culooks::window *Win = getWin();
97 glClearColor(0,0,0,0);
98 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
100 glMatrixMode(GL_MODELVIEW);
103 glScalef(1.0/Win->layout[0],1.0/Win->layout[1],1.0);
104 glTranslatef(-Win->layout[0]+1, -Win->layout[1]+1, 0);
106 for (int icube=0; icube < Win->cubes.size(); icube++) {
107 Win->cubes.at(icube).draw();
108 if ((icube+1)%Win->layout[0] == 0) {
109 glTranslatef(-2*Win->layout[0]+2, 2, 0);
112 glTranslatef(2, 0, 0);
119 void culooks::drawing::initWindow(int winid)
121 glutInitWindowSize(culooks::Windows[winid].second->w, culooks::Windows[winid].second->h);
122 glutInitWindowPosition(winid*100,winid*100);
123 glutCreateWindow( ("culooks / " + culooks::Windows[winid].second->name).c_str() );
125 glutDisplayFunc(&drawing::displayFunc);
126 glutReshapeFunc(&drawing::reshapeFunc);
127 glutMotionFunc(&drawing::motionFunc);
128 glutMouseFunc(&drawing::mouseFunc);
130 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
131 glEnable( GL_BLEND );
133 culooks::Windows[winid].first = glutGetWindow();
135 culooks::Windows[winid].second->initialized = true;
138 void culooks::drawing::idleFunc_master()
140 for (int iwin=0; iwin < culooks::Windows.size(); iwin++)
141 if (!culooks::Windows[iwin].second->initialized)
145 void* culooks::drawing::glutThread(void *leer)
148 glutIdleFunc(&idleFunc_master);