#include "exp004reshape.h"
#include "../view/exp004state0.h"
#include <GL/glut.h>

void
exp004reshape (int w, int h)
{
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();

  /*
   * This scaling produces an odd effect when the coordinates are not
   * centered at 0,0.  When 0,0 is the lower left rather than the
   * center this reshape is a bit unnatural since the image is not
   * centered in the middle of the window.
   */

  if (w <= h)
    {      
      exp004state0.ortho.min_x = 
	exp004state0.ortho_min;
      exp004state0.ortho.max_x = 
	exp004state0.ortho_max;
      exp004state0.ortho.min_y = 
	exp004state0.ortho_min * (GLfloat) h / (GLfloat) w;
      exp004state0.ortho.max_y = 
	exp004state0.ortho_max * (GLfloat) h / (GLfloat) w;
    }
  else
    {
      exp004state0.ortho.min_x =
	exp004state0.ortho_min * (GLfloat) w / (GLfloat) h;
      exp004state0.ortho.max_x =
	exp004state0.ortho_max * (GLfloat) w / (GLfloat) h;
      exp004state0.ortho.min_y =
	exp004state0.ortho_min;
      exp004state0.ortho.max_y =
	exp004state0.ortho_max;
    }

  gluOrtho2D(exp004state0.ortho.min_x,
	     exp004state0.ortho.max_x,
	     exp004state0.ortho.min_y,
	     exp004state0.ortho.max_y);

  glMatrixMode (GL_MODELVIEW);

  // Set the viewport equal to the size of the window.
  glViewport (0, 0, (GLsizei) w, (GLsizei) h);

  exp004state0.viewport.w = w;
  exp004state0.viewport.h = h;

  return;
}