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 "synthesizer.h"
31 #include "watersurface.h"
33 const int INIT_WINDOW_POS_X{50};
34 const int INIT_WINDOW_POS_Y{50};
35 const int INIT_WINDOW_WIDTH{800};
36 const int INIT_WINDOW_HEIGHT{600};
37 const double INIT_VIEW_AZIMUTH{0};
38 const double INIT_VIEW_ALTITUDE{M_PI / 4};
39 const char WINDOW_TITLE[]{"seamulator"};
42 WaterSurfacePtr surface;
43 std::unique_ptr<SeaView> seaView;
44 std::unique_ptr<Synthesizer> synthesizer;
50 double amplitudeFactor;
54 void glReshapeFunc(int width, int height);
55 void glMouseFunc(int button, int state, int x, int y);
56 void glMotionFunc(int x, int y);
57 Settings parseArguments(int argc, char** argv);
59 namespace po = boost::program_options;
61 int main(int argc, char** argv)
63 Settings settings = parseArguments(argc, argv);
65 std::srand(std::time(0));
66 surface = std::make_shared<WaterSurface>(settings.latticeSize,
67 settings.latticeExtend);
68 sea = std::make_shared<Sea>(surface,
70 settings.amplitudeFactor);
71 seaView = std::make_unique<SeaView>(settings.latticeExtend * 1.5,
74 synthesizer = std::make_unique<Synthesizer>(surface);
76 glutInit(&argc, argv);
77 glutInitDisplayMode(GLUT_DOUBLE);
78 glutInitWindowSize(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT);
79 glutInitWindowPosition(INIT_WINDOW_POS_X, INIT_WINDOW_POS_Y);
80 glutCreateWindow(WINDOW_TITLE);
81 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
83 glutDisplayFunc(glDisplayFunc);
84 glutReshapeFunc(glReshapeFunc);
85 glutMouseFunc(glMouseFunc);
86 glutMotionFunc(glMotionFunc);
93 Settings parseArguments(int argc, char** argv)
95 po::options_description desc("Available options");
97 ("help,h", "show this help")
98 ("windspeed,w", po::value<double>()->default_value(10),
100 ("size,s", po::value<char>()->default_value('s'),
101 "lattice size (s|l)")
102 ("amplitude,a", po::value<double>()->default_value(1),
103 "amplitude multiplicator")
106 po::variables_map vm;
107 po::store(po::parse_command_line(argc, argv, desc), vm);
110 if (vm.count("help")) {
111 std::cout << desc << "\n";
117 settings.windSpeed = vm["windspeed"].as<double>();
119 if (vm["size"].as<char>() == 'l') {
120 settings.latticeSize = 256;
121 settings.latticeExtend = 20;
122 settings.amplitudeFactor = vm["amplitude"].as<double>() * 0.00000004;
125 settings.latticeSize = 128;
126 settings.latticeExtend = 10;
127 settings.amplitudeFactor = vm["amplitude"].as<double>() * 0.0000001;
135 glClear(GL_COLOR_BUFFER_BIT);
137 seaView->setupView();
146 void glReshapeFunc(int width, int height)
148 glMatrixMode(GL_PROJECTION);
150 gluPerspective(50.0, ((float)width/(float)height), 0, 1000.0);
151 glViewport(0, 0, width, height);
154 void glMouseFunc(int button, int state, int x, int y)
156 seaView->onMouseEvent(button, state, x, y);
159 void glMotionFunc(int x, int y)
161 seaView->onMouseMove(x, y);