]> git.treefish.org Git - phys/latlib.git/commitdiff
...
authorAlex Schmidt <alex@treefish.org>
Wed, 19 Dec 2012 16:14:53 +0000 (17:14 +0100)
committerAlex Schmidt <alex@treefish.org>
Wed, 19 Dec 2012 16:14:53 +0000 (17:14 +0100)
cubelooks.cpp
cubelooks.h
cubelooks_test.cpp

index ca675bd6a227db01ca4eaa93c9b80429880ace05..ae6f4a5b7f165d2ace649e3b9cb1478a77d05d47 100644 (file)
@@ -2,6 +2,7 @@
 #include <GL/glut.h>
 #include <iostream>
 #include <string>
 #include <GL/glut.h>
 #include <iostream>
 #include <string>
+#include <math.h>
 
 using namespace std;
 
 
 using namespace std;
 
@@ -36,9 +37,29 @@ namespace mygl
 
   static void reshapeFunc(int w, int h)
   {
 
   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()
   }
 
   static void displayFunc()
@@ -51,10 +72,19 @@ namespace mygl
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
 
     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++) {
     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();
       //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();
     }
 
     glutSwapBuffers();
@@ -78,6 +108,9 @@ namespace mygl
       winsize[0] = (640.0/Env->layout[1])*Env->layout[0];
     }
 
       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);
     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.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);
   for (int icube=0; icube<xcubes*ycubes; icube++) {
     cube newCube;
     Env.cubes.push_back(newCube);
index 6e8faffea8038c592755d2109a7534b845b166c9..6ee63f89662da4422fd6547ed1add731f02fe8a8 100644 (file)
@@ -22,7 +22,9 @@ class cubelooks
     int *argc;
     char **argv;
     int layout[2];
     int *argc;
     char **argv;
     int layout[2];
+    double aspect;
     vector<cube> cubes;
     vector<cube> cubes;
+    int w, h;
   };
 
   cubelooks(const int& xcubes, const int& ycubes, int *argc, char **argv);
   };
 
   cubelooks(const int& xcubes, const int& ycubes, int *argc, char **argv);
index f3ea2da9f9a85c3676ac526c4afbd5d98607146c..f065120cf6eb376614cbb1336d8f2299c462b834 100644 (file)
@@ -7,7 +7,7 @@ using namespace std;
 int main(int argc, char **argv)
 {
 
 int main(int argc, char **argv)
 {
 
-  cubelooks clooks(2,1, &argc, argv);
+  cubelooks clooks(5,4, &argc, argv);