7 #include "watersurface.h"
 
   9 const int LATTICE_SIZE = 10;
 
  10 const double LATTICE_UNIT = 1;
 
  13 WaterSurfacePtr surface;
 
  17   float lookRadius = LATTICE_SIZE*LATTICE_UNIT*1.5;
 
  19   float lookAlt = M_PI/4;
 
  20   float fstMouseAngle[2], oldLookAz, oldLookAlt;
 
  24 void glReshapeFunc(int width, int height);
 
  25 void glMouseFunc(int button, int state, int x, int y);
 
  26 void glMotionFunc(int x, int y);
 
  28 int main(int argc, char** argv)
 
  30   std::srand(std::time(0));
 
  32   surface = std::make_shared<WaterSurface>(LATTICE_SIZE, LATTICE_UNIT);
 
  33   sea = std::make_shared<Sea>(surface);
 
  35   glutInit(&argc, argv);
 
  36   glutInitDisplayMode(GLUT_DOUBLE);
 
  37   glutInitWindowSize(300, 300);
 
  38   glutInitWindowPosition(100, 100);
 
  39   glutCreateWindow("seamulator");
 
  41   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
  43   glutDisplayFunc(glDisplayFunc);
 
  44   glutReshapeFunc(glReshapeFunc);
 
  45   glutMouseFunc(glMouseFunc);
 
  46   glutMotionFunc(glMotionFunc);
 
  55   glMatrixMode(GL_MODELVIEW);
 
  58   glClear(GL_COLOR_BUFFER_BIT);
 
  68 void updateView(int width, int height)
 
  70   glMatrixMode(GL_PROJECTION);
 
  73   gluPerspective(50.0, ((float)width/(float)height), 0, 1000.0);
 
  74   glViewport(0, 0, width, height);
 
  77   eyePos[0] = view.lookRadius*cos(view.lookAlt)*sin(view.lookAz);
 
  78   eyePos[1] = view.lookRadius*cos(view.lookAlt)*cos(view.lookAz);
 
  79   eyePos[2] = view.lookRadius*sin(view.lookAlt);
 
  81   gluLookAt(eyePos[0], eyePos[1], eyePos[2],
 
  88   updateView(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
 
  91 void glReshapeFunc(int width, int height)
 
  93   updateView(width, height);
 
  96 void glMouseFunc(int button, int state, int x, int y)
 
  98   if (button == 3 && state == 0)
 
 100       view.lookRadius += view.lookRadius*0.1;
 
 104   else if (button == 4 && state == 0)
 
 106       view.lookRadius -= view.lookRadius*0.1;
 
 110   else if (button == 0 && state == 0) {
 
 111     view.fstMouseAngle[0] = x;
 
 112     view.fstMouseAngle[1] = y;
 
 113     view.oldLookAz = view.lookAz;
 
 114     view.oldLookAlt = view.lookAlt;
 
 119 void glMotionFunc(int x, int y)
 
 122     fmod(view.oldLookAlt +
 
 123          (float)((y-view.fstMouseAngle[1])*2*M_PI/glutGet(GLUT_WINDOW_HEIGHT)),
 
 127     fmod(view.oldLookAz +
 
 128          (float)((x-view.fstMouseAngle[0])*2*M_PI/glutGet(GLUT_WINDOW_WIDTH)),