2  * Copyright (C) 2016  Alexander Schmidt
 
   4  * This file is part of Seamulator.
 
   6  * Seamulator is free software: you can redistribute it and/or modify
 
   7  * it under the terms of the GNU General Public License as published by
 
   8  * the Free Software Foundation, either version 3 of the License, or
 
   9  * (at your option) any later version.
 
  11  * Seamulator is distributed in the hope that it will be useful,
 
  12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  14  * GNU General Public License for more details.
 
  16  * You should have received a copy of the GNU General Public License
 
  17  * along with Seamulator.  If not, see <http://www.gnu.org/licenses/>.
 
  25 #include <boost/program_options.hpp>
 
  30 #include "watersurface.h"
 
  32 const int INIT_WINDOW_POS_X{50};
 
  33 const int INIT_WINDOW_POS_Y{50};
 
  34 const int INIT_WINDOW_WIDTH{800};
 
  35 const int INIT_WINDOW_HEIGHT{600};
 
  36 const double INIT_VIEW_AZIMUTH{0};
 
  37 const double INIT_VIEW_ALTITUDE{M_PI / 4};
 
  38 const char WINDOW_TITLE[]{"seamulator"};
 
  41 WaterSurfacePtr surface;
 
  42 std::unique_ptr<SeaView> seaView;
 
  48   double amplitudeFactor;
 
  52 void glReshapeFunc(int width, int height);
 
  53 void glMouseFunc(int button, int state, int x, int y);
 
  54 void glMotionFunc(int x, int y);
 
  55 Settings parseArguments(int argc, char** argv);
 
  57 namespace po = boost::program_options;
 
  59 int main(int argc, char** argv)
 
  61   Settings settings = parseArguments(argc, argv);
 
  63   std::srand(std::time(0));
 
  64   surface = std::make_shared<WaterSurface>(settings.latticeSize,
 
  65                                            settings.latticeExtend);
 
  66   sea = std::make_shared<Sea>(surface,
 
  68                               settings.amplitudeFactor);
 
  69   seaView = std::make_unique<SeaView>(settings.latticeExtend * 1.5,
 
  73   glutInit(&argc, argv);
 
  74   glutInitDisplayMode(GLUT_DOUBLE);
 
  75   glutInitWindowSize(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT);
 
  76   glutInitWindowPosition(INIT_WINDOW_POS_X, INIT_WINDOW_POS_Y);
 
  77   glutCreateWindow(WINDOW_TITLE);
 
  78   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
  80   glutDisplayFunc(glDisplayFunc);
 
  81   glutReshapeFunc(glReshapeFunc);
 
  82   glutMouseFunc(glMouseFunc);
 
  83   glutMotionFunc(glMotionFunc);
 
  90 Settings parseArguments(int argc, char** argv)
 
  92   po::options_description desc("Available options");
 
  94     ("help,h", "show this help")
 
  95     ("windspeed,w", po::value<double>()->default_value(10),
 
  97     ("size,s", po::value<char>()->default_value('s'),
 
  99     ("amplitude,a", po::value<double>()->default_value(1),
 
 100      "amplitude multiplicator")
 
 103   po::variables_map vm;
 
 104   po::store(po::parse_command_line(argc, argv, desc), vm);
 
 107   if (vm.count("help")) {
 
 108     std::cout << desc << "\n";
 
 114   settings.windSpeed = vm["windspeed"].as<double>();
 
 116   if (vm["size"].as<char>() == 'l') {
 
 117     settings.latticeSize = 256;
 
 118     settings.latticeExtend = 20;
 
 119     settings.amplitudeFactor = vm["amplitude"].as<double>() * 0.00000004;
 
 122     settings.latticeSize = 128;
 
 123     settings.latticeExtend = 10;
 
 124     settings.amplitudeFactor = vm["amplitude"].as<double>() * 0.0000001;
 
 132   glClear(GL_COLOR_BUFFER_BIT);
 
 134   seaView->setupView();
 
 142 void glReshapeFunc(int width, int height)
 
 144   glMatrixMode(GL_PROJECTION);
 
 146   gluPerspective(50.0, ((float)width/(float)height), 0, 1000.0);
 
 147   glViewport(0, 0, width, height);
 
 150 void glMouseFunc(int button, int state, int x, int y)
 
 152   seaView->onMouseEvent(button, state, x, y);
 
 155 void glMotionFunc(int x, int y)
 
 157   seaView->onMouseMove(x, y);