11 int cubelooks::cube::allid = 0;
13 void cubelooks::cube::drawBox()
17 glVertex3f(-1.0f, 1.0f, -1.0f);
18 glVertex3f( 1.0f, 1.0f, -1.0f);
19 glVertex3f(-1.0f, -1.0f, -1.0f);
20 glVertex3f( 1.0f, -1.0f, -1.0f);
21 glVertex3f(-1.0f, 1.0f, 1.0f);
22 glVertex3f( 1.0f, 1.0f, 1.0f);
23 glVertex3f(-1.0f, -1.0f, 1.0f);
24 glVertex3f( 1.0f, -1.0f, 1.0f);
26 glVertex3f( 1.0f, 1.0f, -1.0f);
27 glVertex3f( 1.0f, -1.0f, -1.0f);
28 glVertex3f( -1.0f, 1.0f, -1.0f);
29 glVertex3f( -1.0f, -1.0f, -1.0f);
30 glVertex3f( 1.0f, 1.0f, 1.0f);
31 glVertex3f( 1.0f, -1.0f, 1.0f);
32 glVertex3f( -1.0f, 1.0f, 1.0f);
33 glVertex3f( -1.0f, -1.0f, 1.0f);
35 glVertex3f( -1.0f, -1.0f, 1.0f);
36 glVertex3f( -1.0f, -1.0f, -1.0f);
37 glVertex3f( -1.0f, 1.0f, 1.0f);
38 glVertex3f( -1.0f, 1.0f, -1.0f);
39 glVertex3f( 1.0f, -1.0f, 1.0f);
40 glVertex3f( 1.0f, -1.0f, -1.0f);
41 glVertex3f( 1.0f, 1.0f, 1.0f);
42 glVertex3f( 1.0f, 1.0f, -1.0f);
47 void cubelooks::cube::drawAll()
49 glMatrixMode(GL_MODELVIEW);
52 glTranslatef(-1,-1,-1);
54 for (int iz=0; iz<l; iz++) {
55 for (int iy=0; iy<l; iy++) {
56 for (int ix=0; ix<l; ix++) {
58 glTranslatef(2.0*ix/l,2.0*iy/l,2.0*iz/l);
59 glScalef(2.0/l,2.0/l,2.0/l);
63 glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
64 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
65 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
66 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
67 glVertex3f(0,0,0); glVertex3f(1,0,0);
68 glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
69 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
70 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
71 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
72 glVertex3f(0,0,0); glVertex3f(0,1,0);
73 glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
74 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
75 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
76 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
77 glVertex3f(0,0,0); glVertex3f(0,0,1);
83 glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
84 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
85 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
86 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
87 glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 1, 0); glVertex3f(0, 1, 0);
88 glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
89 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
90 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
91 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
92 glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 0, 1); glVertex3f(0, 0, 1);
93 glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
94 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
95 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
96 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
97 glVertex3f(0, 0, 0); glVertex3f(0, 1, 0); glVertex3f(0, 1, 1); glVertex3f(0, 0, 1);
108 void cubelooks::cube::draw()
110 glMatrixMode(GL_MODELVIEW);
113 //cout << zoom << endl;
115 glScalef(zoom, zoom, zoom);
116 glRotatef(az, 0, 1, 0);
117 glRotatef(alt, 1, 0, 0);
121 glVertex2f(-1, -1); glVertex2f(1, -1); glVertex2f(1, 1); glVertex2f(-1, 1);
135 static int getCubeFromPos(int x, int y)
137 int col = x / ((float)Env->w / Env->layout[0]);
138 int row = Env->layout[1] - y / ((float)Env->h / Env->layout[1]);
140 return col + row*Env->layout[0];
143 static void idleFunc()
148 static void motionFunc(int x, int y)
150 Env->cubes.at(rotcube[0]).az += rotcube[1] - x;
151 Env->cubes.at(rotcube[0]).alt += rotcube[2] - y;
159 static void mouseFunc(int button, int state, int x, int y)
162 rotcube[0] = getCubeFromPos(x,y);
168 Env->cubes.at(getCubeFromPos(x,y)).zoom *= 1.1;
171 else if (button == 3) {
172 Env->cubes.at(getCubeFromPos(x,y)).zoom *= 0.9;
177 static void reshapeFunc(int w, int h)
184 neww = Env->aspect*h;
186 else if ( h == Env->h ) {
188 newh = w / Env->aspect;
191 neww = ( pow(Env->aspect,2)*w + Env->aspect*h ) / ( pow(Env->aspect,2) + 1 );
192 newh = ( Env->aspect*w + h ) / ( pow(Env->aspect,2) + 1 );
195 glutReshapeWindow(neww,newh);
196 glViewport(0,0,neww,newh);
202 static void displayFunc()
204 glClearColor(0,0,0,0);
205 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
207 glMatrixMode(GL_MODELVIEW);
210 glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
211 glTranslatef(-Env->layout[0]+1, -Env->layout[1]+1, 0);
213 for (int icube=0; icube < Env->cubes.size(); icube++) {
214 //glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
215 //glRotatef(2, 1, 0, 0);
216 Env->cubes.at(icube).draw();
217 if ((icube+1)%Env->layout[0] == 0) {
218 glTranslatef(-2*Env->layout[0]+2, 2, 0);
221 glTranslatef(2, 0, 0);
228 static void* glutThread(void *_Env)
232 glutInit( ((cubelooks::env*)Env)->argc, ((cubelooks::env*)Env)->argv );
233 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
235 if( Env->layout[0] >= Env->layout[1] ) {
237 winsize[1] = (640.0/Env->layout[0])*Env->layout[1];
241 winsize[0] = (640.0/Env->layout[1])*Env->layout[0];
247 glutInitWindowSize(winsize[0], winsize[1]);
249 glutInitWindowPosition(0,0);
251 glutCreateWindow("cubelooks");
253 glutDisplayFunc(&displayFunc);
254 glutReshapeFunc(&reshapeFunc);
255 glutMotionFunc(&motionFunc);
256 glutMouseFunc(&mouseFunc);
257 //glutIdleFunc(&idleFunc);
259 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
260 glEnable( GL_BLEND );
266 cubelooks::cube::cube(int _l)
269 link = new float[l*l*l*3 * 4];
270 plaq = new float[l*l*l*3 * 4];
277 for (int i=0; i<l*l*l*3; i++) {
278 link[i*4+0]=1; link[i*4+3]=0.6;
279 plaq[i*4+1]=1; plaq[i*4+3]=0.2;
283 cubelooks::cubelooks(const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv)
287 _Env.layout[0] = xcubes;
288 _Env.layout[1] = ycubes;
289 _Env.aspect = (double)xcubes/ycubes;
290 for (int icube=0; icube<xcubes*ycubes; icube++) {
292 _Env.cubes.push_back(newCube);
297 pthread_create(&glThreadId, 0, &mygl::glutThread, NULL);