From: Alex Schmidt Date: Thu, 20 Dec 2012 14:23:53 +0000 (+0100) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/79dada2bcf873731ed4e78cfed64d8274fb5c587?ds=sidebyside ... --- diff --git a/cubelooks.cpp b/cubelooks.cpp index ae6f4a5..6584383 100644 --- a/cubelooks.cpp +++ b/cubelooks.cpp @@ -6,28 +6,138 @@ using namespace std; -/* GLOBAL */ -vector< pair > Envs; +cubelooks::env *Env; 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() @@ -35,13 +145,40 @@ namespace mygl glutPostRedisplay(); } + static void motionFunc(int x, int y) + { + 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) + { + 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) { int neww; int newh; - cubelooks::env *Env = getEnv(); - if ( w == Env->w ) { newh = h; neww = Env->aspect*h; @@ -64,8 +201,6 @@ namespace mygl static void displayFunc() { - cubelooks::env *Env = getEnv(); - glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); @@ -94,8 +229,6 @@ namespace mygl { 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); @@ -119,31 +252,49 @@ namespace mygl 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 ); 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; i