]> git.treefish.org Git - phys/latlib.git/commitdiff
...
authorAlex Schmidt <alex@treefish.org>
Tue, 19 Feb 2013 09:24:39 +0000 (10:24 +0100)
committerAlex Schmidt <alex@treefish.org>
Tue, 19 Feb 2013 09:24:39 +0000 (10:24 +0100)
culooks_cube.cpp [new file with mode: 0644]
culooks_cube.h [new file with mode: 0644]

diff --git a/culooks_cube.cpp b/culooks_cube.cpp
new file mode 100644 (file)
index 0000000..2498fef
--- /dev/null
@@ -0,0 +1,97 @@
+#include "culooks_cube.h"
+
+#include <GL/glut.h>
+
+int cube::allid = 0;
+
+void cube::draw()
+{
+  glMatrixMode(GL_MODELVIEW);
+  glPushMatrix();
+
+  glScalef(zoom, zoom, zoom);
+  glRotatef(az, 0, 1, 0);
+  glRotatef(alt, 1, 0, 0);
+
+  drawAll();
+
+  glPopMatrix();
+}
+
+void cube::drawAll()
+{
+  glMatrixMode(GL_MODELVIEW);
+  glPushMatrix();
+
+  glTranslatef(-1,-1,-1);
+
+  for (int iz=0; iz<l; iz++) {
+    for (int iy=0; iy<l; iy++) {
+      for (int ix=0; ix<l; ix++) {
+       glPushMatrix();
+       glTranslatef(2.0*ix/l,2.0*iy/l,2.0*iz/l);
+       glScalef(2.0/l,2.0/l,2.0/l);
+
+       /* draw links */
+       glBegin(GL_LINES);
+       glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
+                 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
+                 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
+                 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
+       glVertex3f(0,0,0); glVertex3f(1,0,0);
+       glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
+                 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
+                 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
+                 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
+       glVertex3f(0,0,0); glVertex3f(0,1,0);
+       glColor4f(link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
+                 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
+                 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
+                 link[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
+       glVertex3f(0,0,0); glVertex3f(0,0,1);
+       glEnd();
+
+       /* draw plaquettes */
+       glColor4f(1,1,1,0.5);
+       glBegin(GL_QUADS);
+       glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 0],
+                 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 1],
+                 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 2],
+                 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 2*4 + 3]);
+       glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 1, 0); glVertex3f(0, 1, 0);
+       glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 0],
+                 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 1],
+                 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 2],
+                 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 1*4 + 3]);
+       glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 0, 1); glVertex3f(0, 0, 1);
+       glColor4f(plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 0],
+                 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 1],
+                 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 2],
+                 plaq[iz*l*l*3*4 + iy*l*3*4 + ix*3*4 + 0*4 + 3]);
+       glVertex3f(0, 0, 0); glVertex3f(0, 1, 0); glVertex3f(0, 1, 1); glVertex3f(0, 0, 1);
+       glEnd();
+
+       glPopMatrix();
+      }
+    }
+  }
+    
+  glPopMatrix();
+}
+
+cube::cube(int _l)
+{
+  l = _l;
+  link = new float[l*l*l*3 * 4];
+  plaq = new float[l*l*l*3 * 4];
+  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;
+  }
+}
diff --git a/culooks_cube.h b/culooks_cube.h
new file mode 100644 (file)
index 0000000..aeaa754
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef CULOOKS_CUBE_H
+#define CULOOKS_CUBE_H
+
+class cube {
+ public:
+  cube(int l);
+  void draw();
+  int id;
+  float az, alt;
+  float zoom;
+ private:
+  void drawAll();
+  void drawBox();
+  static int allid;
+  float *plaq;
+  float *link;
+  int l;
+};
+
+#endif