From e48bdb3989c1abbf1d6b3124502299cecae0bdb6 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Wed, 19 Dec 2012 17:14:53 +0100 Subject: [PATCH] ... --- cubelooks.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- cubelooks.h | 2 ++ cubelooks_test.cpp | 2 +- 3 files changed, 41 insertions(+), 5 deletions(-) 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 cubes; + int w, h; }; cubelooks(const int& xcubes, const int& ycubes, int *argc, char **argv); diff --git a/cubelooks_test.cpp b/cubelooks_test.cpp index f3ea2da..f065120 100644 --- a/cubelooks_test.cpp +++ b/cubelooks_test.cpp @@ -7,7 +7,7 @@ using namespace std; int main(int argc, char **argv) { - cubelooks clooks(2,1, &argc, argv); + cubelooks clooks(5,4, &argc, argv); -- 2.39.5