]> git.treefish.org Git - phys/latlib.git/blobdiff - culooks.cpp
...
[phys/latlib.git] / culooks.cpp
index 8c41d236ad96aaa340629fb1e5d7bd9b5a355c44..6e7fded3e92532c154037631e999a7f49b461e50 100644 (file)
 #include "culooks.h"
 
 #include "culooks.h"
 
+#include <vector>
+
 #include <iostream>
 #include <math.h>
 
 vector< pair<int,culooks::window*> > culooks::Windows;
 pthread_t culooks::glThreadId;
 #include <iostream>
 #include <math.h>
 
 vector< pair<int,culooks::window*> > culooks::Windows;
 pthread_t culooks::glThreadId;
+culooks::comarg culooks::comArg;
 
 int culooks::windowid = 0;
 
 
 int culooks::windowid = 0;
 
-int culooks::cube::allid = 0;
-
 using namespace std;
 
 using namespace std;
 
-void culooks::cube::draw()
-{
-  glMatrixMode(GL_MODELVIEW);
-  glPushMatrix();
-
-  //cout << zoom << endl;
-
-  glScalef(zoom, zoom, zoom);
-  glRotatef(az, 0, 1, 0);
-  glRotatef(alt, 1, 0, 0);
-
-  /*
-  glBegin(GL_QUADS);
-  glVertex2f(-1, -1); glVertex2f(1, -1); glVertex2f(1, 1); glVertex2f(-1, 1);
-  glEnd();
-  */
-
-  //drawBox();
-  drawAll();
-
-  glPopMatrix();
-}
-
-void culooks::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();
-}
-
-namespace mygl 
-{
-  int rotcube[3];
-
-  culooks::window* getWin()
-  {
-    for (int iwin=0; iwin<culooks::Windows.size(); iwin++)
-      if ( culooks::Windows.at(iwin).first == glutGetWindow() ) {
-       return culooks::Windows.at(iwin).second;
-      }
-    //cerr << "Something terrible happened: Could not find window-id!" << endl;
-    exit(1);
-  }
-
-  static int getCubeFromPos(int x, int y)
-  {
-    culooks::window *Win = getWin();
-
-    int col = x / ((float)Win->w / Win->layout[0]);
-    int row = Win->layout[1] - y / ((float)Win->h / Win->layout[1]);
-
-    return col + row*Win->layout[0];
-  }
-
-
-  static void motionFunc(int x, int y)
-  {   
-    //cout << x << endl;
-    culooks::window *Win = getWin();
-   
-    Win->cubes.at(rotcube[0]).az += rotcube[1] - x;
-    Win->cubes.at(rotcube[0]).alt += rotcube[2] - y;
-
-    rotcube[1] = x;
-    rotcube[2] = y;
-   
-
-    glutPostRedisplay();
-  }
-
-  static void mouseFunc(int button, int state, int x, int y)
-  {
-    culooks::window *Win = getWin();
-
-    if (button == 0) {
-      rotcube[0] = getCubeFromPos(x,y);
-      rotcube[1] = x;
-      rotcube[2] = y;
-    }
-
-    if (button == 4) {
-      Win->cubes.at(getCubeFromPos(x,y)).zoom *= 1.1;
-      glutPostRedisplay();
-    }
-    else if (button == 3) {
-      Win->cubes.at(getCubeFromPos(x,y)).zoom *= 0.9;
-      glutPostRedisplay();
-    }
-  }
-
-
-  static void reshapeFunc(int w, int h)
-  {
-    culooks::window *Win = getWin();
-    
-    int neww;
-    int newh;
-
-    if ( w == Win->w ) {
-      newh = h;
-      neww = Win->aspect*h;
-    }
-    else if ( h == Win->h ) {
-      neww = w;
-      newh = w / Win->aspect;
-    }
-    else {
-      neww = ( pow(Win->aspect,2)*w + Win->aspect*h ) / ( pow(Win->aspect,2) + 1 );
-      newh = ( Win->aspect*w + h ) / ( pow(Win->aspect,2) + 1 );
-    }
-
-    glutReshapeWindow(neww,newh);
-    glViewport(0,0,neww,newh);
-
-    Win->w = neww;
-    Win->h = newh;
-  }
-
-  static void displayFunc()
-  {
-    //cout << ":" << glutGetWindow() << endl;
-
-    culooks::window *Win = getWin();
-    
-    glClearColor(0,0,0,0);
-    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-    
-    glMatrixMode(GL_MODELVIEW);
-    glLoadIdentity();
-    
-    glScalef(1.0/Win->layout[0],1.0/Win->layout[1],1.0);
-    glTranslatef(-Win->layout[0]+1, -Win->layout[1]+1, 0);
-    
-    for (int icube=0; icube < Win->cubes.size(); icube++) {
-      //glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0);
-      //glRotatef(2, 1, 0, 0);
-      Win->cubes.at(icube).draw();
-      if ((icube+1)%Win->layout[0] == 0) {
-       glTranslatef(-2*Win->layout[0]+2, 2, 0);
-      }
-      else {
-       glTranslatef(2, 0, 0);
-      }
-    }
-    
-    glutSwapBuffers();
-  }
-  static void initWindow(int winid)
-  {
-    glutInitWindowSize(culooks::Windows[winid].second->w, culooks::Windows[winid].second->h);
-    glutInitWindowPosition(winid*100,winid*100);
-    glutCreateWindow( ("culooks / " + culooks::Windows[winid].second->name).c_str() );
-    
-    glutDisplayFunc(&mygl::displayFunc);
-    glutReshapeFunc(&mygl::reshapeFunc);
-    glutMotionFunc(&mygl::motionFunc);
-    glutMouseFunc(&mygl::mouseFunc);
-
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
-    glEnable( GL_BLEND );
-
-    culooks::Windows[winid].first = glutGetWindow();
-
-    culooks::Windows[winid].second->initialized = true;
-  }
-
-  static void idleFunc_master()
-  {
-    for (int iwin=0; iwin < culooks::Windows.size(); iwin++)
-      if (!culooks::Windows[iwin].second->initialized)
-       initWindow(iwin);
-  }
-
-  static void* glutThread(void *leer)
-  {
-    initWindow(0);
-    glutIdleFunc(&idleFunc_master);
-    glutMainLoop();
-  }
-};
-
-
 culooks::culooks (const char* name, const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv)
 {
   window *Win = new window;
   int winsize[2];
 culooks::culooks (const char* name, const int& xcubes, const int& ycubes, const int& l, int *argc, char **argv)
 {
   window *Win = new window;
   int winsize[2];
-  wincontext wincon;
-
-  if (windowid == 0) {
-    glutInit(argc, argv);
-    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
-  }
 
   Win->layout[0] = xcubes;
   Win->layout[1] = ycubes;
 
   Win->layout[0] = xcubes;
   Win->layout[1] = ycubes;
@@ -284,30 +42,79 @@ culooks::culooks (const char* name, const int& xcubes, const int& ycubes, const
 
   Win->initialized = false;
 
 
   Win->initialized = false;
 
+  //Win->linewidth = 1;
+
   Windows.push_back( pair<int,culooks::window*>(0, Win) );
   Windows.push_back( pair<int,culooks::window*>(0, Win) );
-  
+
   if (windowid == 0) {
   if (windowid == 0) {
-    glXMakeCurrent(0,0,0);
-    pthread_create(&glThreadId, 0, &mygl::glutThread, NULL);
+    comArg.argc = argc;
+    comArg.argv = argv;
+    pthread_create(&glThreadId, 0, &drawing::glutThread, &comArg);
   }
   }
-
   mywid = windowid;
   windowid++;
 }
 
   mywid = windowid;
   windowid++;
 }
 
-culooks::cube::cube(int _l)
+void culooks::setLink (const int& cubeid, const int& posdir,
+                      const float& red, const float& green, const float& blue, const float& alpha)
+{
+  Windows[mywid].second->cubes[cubeid].setLink(posdir, red, green, blue, alpha);
+}
+
+void culooks::setPlaq (const int& cubeid, const int& posdir,
+                      const float& red, const float& green, const float& blue, const float& alpha)
 {
 {
-  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++;
+  Windows[mywid].second->cubes[cubeid].setPlaq(posdir, red, green, blue, alpha);
+}
 
 
-  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;
+void culooks::swapBuffers () {
+  for (int icube=0; icube<Windows[mywid].second->cubes.size(); icube++) {
+    Windows[mywid].second->cubes[icube].swapLinkBuffer();
+    Windows[mywid].second->cubes[icube].swapPlaqBuffer();
   }
   }
+  Windows[mywid].second->redisplay = true;
+}
+
+void culooks::hidePlaqs (const int& cubeid) {
+  Windows[mywid].second->cubes[cubeid].hidePlaqs();
+}
+
+void culooks::hidePlaqs () {
+  for (int icube=0; icube<Windows[mywid].second->cubes.size(); icube++)
+    Windows[mywid].second->cubes[icube].hidePlaqs();
+}
+
+void culooks::hideLinks (const int& cubeid) {
+  Windows[mywid].second->cubes[cubeid].hideLinks();
+}
+
+void culooks::hideLinks () {
+  for (int icube=0; icube<Windows[mywid].second->cubes.size(); icube++)
+    Windows[mywid].second->cubes[icube].hideLinks();
+}
+
+void culooks::setBgColor(const float& red, const float& green, const float& blue, const float& alpha)
+{
+  Windows[mywid].second->bgcolor[0] = red;
+  Windows[mywid].second->bgcolor[1] = green;
+  Windows[mywid].second->bgcolor[2] = blue;
+  Windows[mywid].second->bgcolor[3] = alpha;
+}
+
+void culooks::setWireColor(const float& r, const float& g, const float& b, const float& a)
+{
+  for (int icube=0; icube<Windows[mywid].second->cubes.size(); icube++)
+    Windows[mywid].second->cubes[icube].setWireColor(r, g, b, a);
+}
+
+void culooks::setFrameWidth(float width)
+{
+  for (int icube=0; icube<Windows[mywid].second->cubes.size(); icube++)
+    Windows[mywid].second->cubes[icube].setFrameWidth(width);
+}
+
+void culooks::setLinkWidth(float width)
+{
+  for (int icube=0; icube<Windows[mywid].second->cubes.size(); icube++)
+    Windows[mywid].second->cubes[icube].setLinkWidth(width);
 }
 }