6 vector< pair<int,culooks::window*> > culooks::Windows;
7 pthread_t culooks::glThreadId;
9 int culooks::windowid = 0;
11 int culooks::cube::allid = 0;
15 void culooks::cube::draw()
17 glMatrixMode(GL_MODELVIEW);
20 //cout << zoom << endl;
22 glScalef(zoom, zoom, zoom);
23 glRotatef(az, 0, 1, 0);
24 glRotatef(alt, 1, 0, 0);
28 glVertex2f(-1, -1); glVertex2f(1, -1); glVertex2f(1, 1); glVertex2f(-1, 1);
38 void culooks::cube::drawAll()
40 glMatrixMode(GL_MODELVIEW);
43 glTranslatef(-1,-1,-1);
45 for (int iz=0; iz<l; iz++) {
46 for (int iy=0; iy<l; iy++) {
47 for (int ix=0; ix<l; ix++) {
49 glTranslatef(2.0*ix/l,2.0*iy/l,2.0*iz/l);
50 glScalef(2.0/l,2.0/l,2.0/l);
54 glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
55 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
56 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
57 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
58 glVertex3f(0,0,0); glVertex3f(1,0,0);
59 glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
60 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
61 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
62 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
63 glVertex3f(0,0,0); glVertex3f(0,1,0);
64 glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
65 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
66 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
67 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
68 glVertex3f(0,0,0); glVertex3f(0,0,1);
74 glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
75 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
76 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
77 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
78 glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 1, 0); glVertex3f(0, 1, 0);
79 glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
80 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
81 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
82 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
83 glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 0, 1); glVertex3f(0, 0, 1);
84 glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
85 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
86 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
87 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
88 glVertex3f(0, 0, 0); glVertex3f(0, 1, 0); glVertex3f(0, 1, 1); glVertex3f(0, 0, 1);
103 culooks::window* getWin()
105 for (int iwin=0; iwin<culooks::Windows.size(); iwin++)
106 if ( culooks::Windows.at(iwin).first == glutGetWindow() ) {
107 return culooks::Windows.at(iwin).second;
109 //cerr << "Something terrible happened: Could not find window-id!" << endl;
113 static int getCubeFromPos(int x, int y)
115 culooks::window *Win = getWin();
117 int col = x / ((float)Win->w / Win->layout[0]);
118 int row = Win->layout[1] - y / ((float)Win->h / Win->layout[1]);
120 return col + row*Win->layout[0];
124 static void motionFunc(int x, int y)
127 culooks::window *Win = getWin();
129 Win->cubes.at(rotcube[0]).az += rotcube[1] - x;
130 Win->cubes.at(rotcube[0]).alt += rotcube[2] - y;
139 static void mouseFunc(int button, int state, int x, int y)
141 culooks::window *Win = getWin();
144 rotcube[0] = getCubeFromPos(x,y);
150 Win->cubes.at(getCubeFromPos(x,y)).zoom *= 1.1;
153 else if (button == 3) {
154 Win->cubes.at(getCubeFromPos(x,y)).zoom *= 0.9;
160 static void reshapeFunc(int w, int h)
162 culooks::window *Win = getWin();
169 neww = Win->aspect*h;
171 else if ( h == Win->h ) {
173 newh = w / Win->aspect;
176 neww = ( pow(Win->aspect,2)*w + Win->aspect*h ) / ( pow(Win->aspect,2) + 1 );
177 newh = ( Win->aspect*w + h ) / ( pow(Win->aspect,2) + 1 );
180 glutReshapeWindow(neww,newh);
181 glViewport(0,0,neww,newh);
187 static void displayFunc()
189 //cout << ":" << glutGetWindow() << endl;
191 culooks::window *Win = getWin();
193 glClearColor(0,0,0,0);
194 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
196 glMatrixMode(GL_MODELVIEW);
199 glScalef(1.0/Win->layout[0],1.0/Win->layout[1],1.0);
200 glTranslatef(-Win->layout[0]+1, -Win->layout[1]+1, 0);
202 for (int icube=0; icube < Win->cubes.size(); icube++) {
203 //glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
204 //glRotatef(2, 1, 0, 0);
205 Win->cubes.at(icube).draw();
206 if ((icube+1)%Win->layout[0] == 0) {
207 glTranslatef(-2*Win->layout[0]+2, 2, 0);
210 glTranslatef(2, 0, 0);
217 static void initWindow(int winid)
219 glutInitWindowSize(culooks::Windows[winid].second->w, culooks::Windows[winid].second->h);
220 glutInitWindowPosition(winid*100,winid*100);
221 glutCreateWindow( ("culooks / " + culooks::Windows[winid].second->name).c_str() );
223 glutDisplayFunc(&mygl::displayFunc);
224 glutReshapeFunc(&mygl::reshapeFunc);
225 glutMotionFunc(&mygl::motionFunc);
226 glutMouseFunc(&mygl::mouseFunc);
228 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
229 glEnable( GL_BLEND );
231 culooks::Windows[winid].first = glutGetWindow();
233 culooks::Windows[winid].second->initialized = true;
236 static void idleFunc_master()
238 for (int iwin=0; iwin < culooks::Windows.size(); iwin++)
239 if (!culooks::Windows[iwin].second->initialized)
243 static void* glutThread(void *leer)
246 glutIdleFunc(&idleFunc_master);
252 culooks::culooks (const char* name, const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv)
254 window *Win = new window;
259 glutInit(argc, argv);
260 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
263 Win->layout[0] = xcubes;
264 Win->layout[1] = ycubes;
265 Win->aspect = (double)xcubes/ycubes;
266 for (int icube=0; icube<xcubes*ycubes; icube++) {
268 Win->cubes.push_back(newCube);
271 if( Win->layout[0] >= Win->layout[1] ) {
273 winsize[1] = (640.0/Win->layout[0])*Win->layout[1];
277 winsize[0] = (640.0/Win->layout[1])*Win->layout[0];
285 Win->initialized = false;
287 Windows.push_back( pair<int,culooks::window*>(0, Win) );
290 glXMakeCurrent(0,0,0);
291 pthread_create(&glThreadId, 0, &mygl::glutThread, NULL);
298 culooks::cube::cube(int _l)
301 link = new float[l*l*l*3 * 4];
302 plaq = new float[l*l*l*3 * 4];
309 for (int i=0; i<l*l*l*3; i++) {
310 link[i*4+0]=1; link[i*4+3]=0.6;
311 plaq[i*4+1]=1; plaq[i*4+3]=0.2;