X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/e48bdb3989c1abbf1d6b3124502299cecae0bdb6..b576d1ec1596088056cd5110f0ee24e8d3dfe913:/cubelooks.cpp?ds=sidebyside diff --git a/cubelooks.cpp b/cubelooks.cpp index ae6f4a5..f6b02ef 100644 --- a/cubelooks.cpp +++ b/cubelooks.cpp @@ -1,25 +1,140 @@ #include "cubelooks.h" -#include #include #include #include using namespace std; -/* GLOBAL */ vector< pair > Envs; +bool cubelooks::initDone = false; +GLXDrawable cubelooks::gDrawable; +Display *cubelooks::gDisplay; + int cubelooks::cube::allid = 0; +void cubelooks::cube::drawBox() +{ + glBegin(GL_LINES); + + 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(); +} + +void cubelooks::cube::drawAll() +{ + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + glTranslatef(-1,-1,-1); + + for (int iz=0; izw / Env->layout[0]); + int row = Env->layout[1] - y / ((float)Env->h / Env->layout[1]); + + return col + row*Env->layout[0]; + } static void idleFunc() { glutPostRedisplay(); } + static void motionFunc(int x, int y) + { + cubelooks::env *Env = getEnv(); + + Env->cubes.at(rotcube[0]).az += rotcube[1] - x; + Env->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) + { + cubelooks::env *Env = getEnv(); + + if (button == 0) { + rotcube[0] = getCubeFromPos(x,y); + rotcube[1] = x; + rotcube[2] = y; + } + + if (button == 4) { + Env->cubes.at(getCubeFromPos(x,y)).zoom *= 1.1; + glutPostRedisplay(); + } + else if (button == 3) { + Env->cubes.at(getCubeFromPos(x,y)).zoom *= 0.9; + glutPostRedisplay(); + } + } + static void reshapeFunc(int w, int h) { + cubelooks::env *Env = getEnv(); + int neww; int newh; - cubelooks::env *Env = getEnv(); - if ( w == Env->w ) { newh = h; neww = Env->aspect*h; @@ -92,58 +250,98 @@ namespace mygl static void* glutThread(void *_Env) { - int winsize[2]; - - cubelooks::env* Env = (cubelooks::env*)_Env; - - glutInit( ((cubelooks::env*)Env)->argc, ((cubelooks::env*)Env)->argv ); - glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); + cubelooks::env *Env = (cubelooks::env *)_Env; - if( Env->layout[0] >= Env->layout[1] ) { - winsize[0] = 640; - winsize[1] = (640.0/Env->layout[0])*Env->layout[1]; - } - else { - winsize[1] = 640; - winsize[0] = (640.0/Env->layout[1])*Env->layout[0]; - } + //glXMakeCurrent(0, glutCreateWindow("cubelooks")); - Env->w = winsize[0]; - Env->h = winsize[1]; + //glXCrateContext(0, - glutInitWindowSize(winsize[0], winsize[1]); + //cout << Env->layout[1] << endl; - glutInitWindowPosition(0,0); + glXMakeCurrent( Env->gDisplay, Env->gDrawable, Env->gContext ); - glutCreateWindow("cubelooks"); + //cout << "da" << endl; glutDisplayFunc(&displayFunc); glutReshapeFunc(&reshapeFunc); + glutMotionFunc(&motionFunc); + glutMouseFunc(&mouseFunc); //glutIdleFunc(&idleFunc); - Envs.push_back( pair(pthread_self(), (cubelooks::env*)Env) ); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable( GL_BLEND ); + + Envs.push_back( pair(pthread_self(), Env) ); glutMainLoop(); } }; -cubelooks::cube::cube() +cubelooks::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; iargc = argc; + Env->argv = argv; + Env->layout[0] = xcubes; + Env->layout[1] = ycubes; + Env->aspect = (double)xcubes/ycubes; for (int icube=0; icubecubes.push_back(newCube); + } + + if ( !initDone ) { + glutInit( Env->argc, Env->argv ); + glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); + } + + if( Env->layout[0] >= Env->layout[1] ) { + winsize[0] = 640; + winsize[1] = (640.0/Env->layout[0])*Env->layout[1]; + } + else { + winsize[1] = 640; + winsize[0] = (640.0/Env->layout[1])*Env->layout[0]; } - pthread_create(&glThreadId, 0, &mygl::glutThread, &Env); + Env->w = winsize[0]; + Env->h = winsize[1]; + + glutInitWindowSize(winsize[0], winsize[1]); + glutInitWindowPosition(0,0); + glutCreateWindow("cubelooks"); + + if ( !initDone ) { + gDisplay = glXGetCurrentDisplay(); + gDrawable = glXGetCurrentDrawable(); + initDone = true; + } + + Env->gContext = glXGetCurrentContext(); + Env->gDisplay = gDisplay; + Env->gDrawable = glXGetCurrentDrawable(); + + glXMakeCurrent(0,0,0); + + pthread_create(&glThreadId, 0, &mygl::glutThread, Env); }