#include <GL/glut.h>
#include <iostream>
#include <string>
+#include <math.h>
using namespace std;
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()
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();
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);
Env.argv = argv;
Env.layout[0] = xcubes;
Env.layout[1] = ycubes;
+ Env.aspect = (double)xcubes/ycubes;
for (int icube=0; icube<xcubes*ycubes; icube++) {
cube newCube;
Env.cubes.push_back(newCube);