-#include "culooks_cube.h"
+#include "culooks.h"
#include <GL/glut.h>
-int cube::allid = 0;
+int culooks::cube::allid = 0;
-void cube::draw()
+void culooks::cube::setLink (const int& posdir,
+ const float& red, const float& green, const float& blue, const float& alpha) {
+ linkbuf[(linkbuf_active+1)%2][ posdir*4 ] = red;
+ linkbuf[(linkbuf_active+1)%2][ posdir*4 + 1 ] = green;
+ linkbuf[(linkbuf_active+1)%2][ posdir*4 + 2 ] = blue;
+ linkbuf[(linkbuf_active+1)%2][ posdir*4 + 3 ] = alpha;
+}
+
+void culooks::cube::setPlaq (const int& posdir,
+ const float& red, const float& green, const float& blue, const float& alpha) {
+ plaqbuf[(plaqbuf_active+1)%2][ posdir*4 ] = red;
+ plaqbuf[(plaqbuf_active+1)%2][ posdir*4 + 1 ] = green;
+ plaqbuf[(plaqbuf_active+1)%2][ posdir*4 + 2 ] = blue;
+ plaqbuf[(plaqbuf_active+1)%2][ posdir*4 + 3 ] = alpha;
+}
+
+void culooks::cube::hidePlaqs()
+{
+ for (int ibuf=0; ibuf<2; ibuf++)
+ for (int i=0; i<l*l*l*3; i++) {
+ plaqbuf[ibuf][i*4+0]=0;
+ plaqbuf[ibuf][i*4+1]=0;
+ plaqbuf[ibuf][i*4+2]=0;
+ plaqbuf[ibuf][i*4+3]=0;
+ }
+}
+
+void culooks::cube::hideLinks()
+{
+ for (int ibuf=0; ibuf<2; ibuf++)
+ for (int i=0; i<l*l*l*3; i++) {
+ linkbuf[ibuf][i*4+0]=0;
+ linkbuf[ibuf][i*4+1]=0;
+ linkbuf[ibuf][i*4+2]=0;
+ linkbuf[ibuf][i*4+3]=0;
+ }
+}
+
+void culooks::cube::swapLinkBuffer()
+{
+ linkbuf_active = (linkbuf_active+1)%2;
+ link = linkbuf[linkbuf_active];
+}
+
+void culooks::cube::swapPlaqBuffer()
+{
+ plaqbuf_active = (plaqbuf_active+1)%2;
+ plaq = plaqbuf[plaqbuf_active];
+}
+
+void culooks::cube::draw()
{
glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
+ glPushMatrix();
glScalef(zoom, zoom, zoom);
glRotatef(az, 0, 1, 0);
glRotatef(alt, 1, 0, 0);
-
drawAll();
+ glPopMatrix();
+ /* draw frame */
+ glPushMatrix();
+ glScalef(zoom*1.01, zoom*1.01, zoom*1.01);
+ glRotatef(az, 0, 1, 0);
+ glRotatef(alt, 1, 0, 0);
+ drawFrame();
glPopMatrix();
}
-void cube::drawAll()
+void culooks::cube::drawAll()
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPopMatrix();
}
-cube::cube(int _l)
+culooks::cube::cube(int _l)
{
l = _l;
- link = new float[l*l*l*3 * 4];
- plaq = new float[l*l*l*3 * 4];
+ plaqbuf[0] = new float[l*l*l*3 * 4];
+ plaqbuf[1] = new float[l*l*l*3 * 4];
+ linkbuf[0] = new float[l*l*l*3 * 4];
+ linkbuf[1] = new float[l*l*l*3 * 4];
+
+ linkbuf_active = 0;
+ plaqbuf_active = 0;
+
+ link = linkbuf[0];
+ plaq = plaqbuf[0];
az = 30;
alt = -20;
zoom = 0.6;
id = allid;
allid++;
- for (int i=0; i<l*l*l*3; i++) {
- link[i*4+0]=1; link[i*4+3]=0.6;
- plaq[i*4+1]=1; plaq[i*4+3]=0.2;
- }
+ for (int ibuf=0; ibuf<2; ibuf++)
+ for (int i=0; i<l*l*l*3; i++) {
+ linkbuf[ibuf][i*4+0]=1; linkbuf[ibuf][i*4+3]=0.6;
+ plaqbuf[ibuf][i*4+1]=1; plaqbuf[ibuf][i*4+3]=0.2;
+ }
+}
+
+void culooks::cube::drawFrame()
+{
+ glBegin(GL_LINES);
+
+ glColor4f(0, 0, 0, 1);
+
+ glVertex3f(-1.0f, 1.0f, -1.0f);
+ glVertex3f( 1.0f, 1.0f, -1.0f);
+ glVertex3f(-1.0f, -1.0f, -1.0f);
+ glVertex3f( 1.0f, -1.0f, -1.0f);
+ glVertex3f(-1.0f, 1.0f, 1.0f);
+ glVertex3f( 1.0f, 1.0f, 1.0f);
+ glVertex3f(-1.0f, -1.0f, 1.0f);
+ glVertex3f( 1.0f, -1.0f, 1.0f);
+
+ glVertex3f( 1.0f, 1.0f, -1.0f);
+ glVertex3f( 1.0f, -1.0f, -1.0f);
+ glVertex3f( -1.0f, 1.0f, -1.0f);
+ glVertex3f( -1.0f, -1.0f, -1.0f);
+ glVertex3f( 1.0f, 1.0f, 1.0f);
+ glVertex3f( 1.0f, -1.0f, 1.0f);
+ glVertex3f( -1.0f, 1.0f, 1.0f);
+ glVertex3f( -1.0f, -1.0f, 1.0f);
+
+ glVertex3f( -1.0f, -1.0f, 1.0f);
+ glVertex3f( -1.0f, -1.0f, -1.0f);
+ glVertex3f( -1.0f, 1.0f, 1.0f);
+ glVertex3f( -1.0f, 1.0f, -1.0f);
+ glVertex3f( 1.0f, -1.0f, 1.0f);
+ glVertex3f( 1.0f, -1.0f, -1.0f);
+ glVertex3f( 1.0f, 1.0f, 1.0f);
+ glVertex3f( 1.0f, 1.0f, -1.0f);
+
+ glEnd();
}