5 int culooks::cube::allid = 0;
7 void culooks::cube::setLink (const int& posdir,
8 const float& red, const float& green, const float& blue, const float& alpha) {
9 linkbuf[(linkbuf_active+1)%2][ posdir*4 ] = red;
10 linkbuf[(linkbuf_active+1)%2][ posdir*4 + 1 ] = green;
11 linkbuf[(linkbuf_active+1)%2][ posdir*4 + 2 ] = blue;
12 linkbuf[(linkbuf_active+1)%2][ posdir*4 + 3 ] = alpha;
15 void culooks::cube::setPlaq (const int& posdir,
16 const float& red, const float& green, const float& blue, const float& alpha) {
17 plaqbuf[(plaqbuf_active+1)%2][ posdir*4 ] = red;
18 plaqbuf[(plaqbuf_active+1)%2][ posdir*4 + 1 ] = green;
19 plaqbuf[(plaqbuf_active+1)%2][ posdir*4 + 2 ] = blue;
20 plaqbuf[(plaqbuf_active+1)%2][ posdir*4 + 3 ] = alpha;
23 void culooks::cube::hidePlaqs()
25 for (int ibuf=0; ibuf<2; ibuf++)
26 for (int i=0; i<l*l*l*3; i++) {
27 plaqbuf[ibuf][i*4+0]=0;
28 plaqbuf[ibuf][i*4+1]=0;
29 plaqbuf[ibuf][i*4+2]=0;
30 plaqbuf[ibuf][i*4+3]=0;
34 void culooks::cube::hideLinks()
36 for (int ibuf=0; ibuf<2; ibuf++)
37 for (int i=0; i<l*l*l*3; i++) {
38 linkbuf[ibuf][i*4+0]=0;
39 linkbuf[ibuf][i*4+1]=0;
40 linkbuf[ibuf][i*4+2]=0;
41 linkbuf[ibuf][i*4+3]=0;
45 void culooks::cube::swapLinkBuffer()
47 linkbuf_active = (linkbuf_active+1)%2;
48 link = linkbuf[linkbuf_active];
51 void culooks::cube::swapPlaqBuffer()
53 plaqbuf_active = (plaqbuf_active+1)%2;
54 plaq = plaqbuf[plaqbuf_active];
57 void culooks::cube::draw()
59 glMatrixMode(GL_MODELVIEW);
62 glScalef(zoom, zoom, zoom);
63 glRotatef(az, 0, 1, 0);
64 glRotatef(alt, 1, 0, 0);
70 glScalef(zoom*1.01, zoom*1.01, zoom*1.01);
71 glRotatef(az, 0, 1, 0);
72 glRotatef(alt, 1, 0, 0);
77 void culooks::cube::drawAll()
79 glMatrixMode(GL_MODELVIEW);
82 glTranslatef(-1,-1,-1);
84 for (int iz=0; iz<l; iz++) {
85 for (int iy=0; iy<l; iy++) {
86 for (int ix=0; ix<l; ix++) {
88 glTranslatef(2.0*ix/l,2.0*iy/l,2.0*iz/l);
89 glScalef(2.0/l,2.0/l,2.0/l);
93 glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
94 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
95 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
96 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
97 glVertex3f(0,0,0); glVertex3f(1,0,0);
98 glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
99 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
100 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
101 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
102 glVertex3f(0,0,0); glVertex3f(0,1,0);
103 glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
104 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
105 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
106 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
107 glVertex3f(0,0,0); glVertex3f(0,0,1);
110 /* draw plaquettes */
111 glColor4f(1,1,1,0.5);
113 glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
114 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
115 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
116 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
117 glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 1, 0); glVertex3f(0, 1, 0);
118 glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
119 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
120 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
121 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
122 glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 0, 1); glVertex3f(0, 0, 1);
123 glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
124 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
125 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
126 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
127 glVertex3f(0, 0, 0); glVertex3f(0, 1, 0); glVertex3f(0, 1, 1); glVertex3f(0, 0, 1);
138 culooks::cube::cube(int _l)
141 plaqbuf[0] = new float[l*l*l*3 * 4];
142 plaqbuf[1] = new float[l*l*l*3 * 4];
143 linkbuf[0] = new float[l*l*l*3 * 4];
144 linkbuf[1] = new float[l*l*l*3 * 4];
157 for (int ibuf=0; ibuf<2; ibuf++)
158 for (int i=0; i<l*l*l*3; i++) {
159 linkbuf[ibuf][i*4+0]=1; linkbuf[ibuf][i*4+3]=0.6;
160 plaqbuf[ibuf][i*4+1]=1; plaqbuf[ibuf][i*4+3]=0.2;
164 void culooks::cube::drawFrame()
168 glColor4f(0, 0, 0, 1);
170 glVertex3f(-1.0f, 1.0f, -1.0f);
171 glVertex3f( 1.0f, 1.0f, -1.0f);
172 glVertex3f(-1.0f, -1.0f, -1.0f);
173 glVertex3f( 1.0f, -1.0f, -1.0f);
174 glVertex3f(-1.0f, 1.0f, 1.0f);
175 glVertex3f( 1.0f, 1.0f, 1.0f);
176 glVertex3f(-1.0f, -1.0f, 1.0f);
177 glVertex3f( 1.0f, -1.0f, 1.0f);
179 glVertex3f( 1.0f, 1.0f, -1.0f);
180 glVertex3f( 1.0f, -1.0f, -1.0f);
181 glVertex3f( -1.0f, 1.0f, -1.0f);
182 glVertex3f( -1.0f, -1.0f, -1.0f);
183 glVertex3f( 1.0f, 1.0f, 1.0f);
184 glVertex3f( 1.0f, -1.0f, 1.0f);
185 glVertex3f( -1.0f, 1.0f, 1.0f);
186 glVertex3f( -1.0f, -1.0f, 1.0f);
188 glVertex3f( -1.0f, -1.0f, 1.0f);
189 glVertex3f( -1.0f, -1.0f, -1.0f);
190 glVertex3f( -1.0f, 1.0f, 1.0f);
191 glVertex3f( -1.0f, 1.0f, -1.0f);
192 glVertex3f( 1.0f, -1.0f, 1.0f);
193 glVertex3f( 1.0f, -1.0f, -1.0f);
194 glVertex3f( 1.0f, 1.0f, 1.0f);
195 glVertex3f( 1.0f, 1.0f, -1.0f);