X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/0e276c2770688b3cc7676ee84c8e35246621f6df..e48bdb3989c1abbf1d6b3124502299cecae0bdb6:/cubelooks.cpp diff --git a/cubelooks.cpp b/cubelooks.cpp index ca675bd..ae6f4a5 100644 --- a/cubelooks.cpp +++ b/cubelooks.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace std; @@ -36,9 +37,29 @@ namespace mygl static void reshapeFunc(int w, int h) { - glutReshapeWindow(10,10); - glViewport(0,0,w,h); - cout << w << ":" << h << endl; + int neww; + int newh; + + cubelooks::env *Env = getEnv(); + + if ( w == Env->w ) { + newh = h; + neww = Env->aspect*h; + } + else if ( h == Env->h ) { + neww = w; + newh = w / Env->aspect; + } + else { + neww = ( pow(Env->aspect,2)*w + Env->aspect*h ) / ( pow(Env->aspect,2) + 1 ); + newh = ( Env->aspect*w + h ) / ( pow(Env->aspect,2) + 1 ); + } + + glutReshapeWindow(neww,newh); + glViewport(0,0,neww,newh); + + Env->w = neww; + Env->h = newh; } static void displayFunc() @@ -51,10 +72,19 @@ namespace mygl glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0); + glTranslatef(-Env->layout[0]+1, -Env->layout[1]+1, 0); + for (int icube=0; icube < Env->cubes.size(); icube++) { - glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0); + //glScalef(1.0/Env->layout[0],1.0/Env->layout[1],1.0); //glRotatef(2, 1, 0, 0); Env->cubes.at(icube).draw(); + if ((icube+1)%Env->layout[0] == 0) { + glTranslatef(-2*Env->layout[0]+2, 2, 0); + } + else { + glTranslatef(2, 0, 0); + } } glutSwapBuffers(); @@ -78,6 +108,9 @@ namespace mygl winsize[0] = (640.0/Env->layout[1])*Env->layout[0]; } + Env->w = winsize[0]; + Env->h = winsize[1]; + glutInitWindowSize(winsize[0], winsize[1]); glutInitWindowPosition(0,0); @@ -106,6 +139,7 @@ cubelooks::cubelooks(const int& xcubes, const int& ycubes, int *argc, char **arg Env.argv = argv; Env.layout[0] = xcubes; Env.layout[1] = ycubes; + Env.aspect = (double)xcubes/ycubes; for (int icube=0; icube