6 #include <boost/program_options.hpp>
11 #include "watersurface.h"
13 const int INIT_WINDOW_POS_X{50};
14 const int INIT_WINDOW_POS_Y{50};
15 const int INIT_WINDOW_WIDTH{800};
16 const int INIT_WINDOW_HEIGHT{600};
17 const double INIT_VIEW_AZIMUTH{0};
18 const double INIT_VIEW_ALTITUDE{M_PI / 4};
19 const char WINDOW_TITLE[]{"seamulator"};
22 WaterSurfacePtr surface;
23 std::unique_ptr<SeaView> seaView;
29 double amplitudeFactor;
33 void glReshapeFunc(int width, int height);
34 void glMouseFunc(int button, int state, int x, int y);
35 void glMotionFunc(int x, int y);
36 Settings parseArguments(int argc, char** argv);
38 namespace po = boost::program_options;
40 int main(int argc, char** argv)
42 Settings settings = parseArguments(argc, argv);
44 std::srand(std::time(0));
45 surface = std::make_shared<WaterSurface>(settings.latticeSize,
46 settings.latticeExtend);
47 sea = std::make_shared<Sea>(surface,
49 settings.amplitudeFactor);
50 seaView = std::make_unique<SeaView>(settings.latticeExtend * 1.5,
54 glutInit(&argc, argv);
55 glutInitDisplayMode(GLUT_DOUBLE);
56 glutInitWindowSize(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT);
57 glutInitWindowPosition(INIT_WINDOW_POS_X, INIT_WINDOW_POS_Y);
58 glutCreateWindow(WINDOW_TITLE);
59 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
61 glutDisplayFunc(glDisplayFunc);
62 glutReshapeFunc(glReshapeFunc);
63 glutMouseFunc(glMouseFunc);
64 glutMotionFunc(glMotionFunc);
71 Settings parseArguments(int argc, char** argv)
73 po::options_description desc("Available options");
75 ("help,h", "produce help message")
76 ("windspeed,w", po::value<double>()->default_value(10),
77 "wind speed given in m/s")
78 ("size,s", po::value<std::string>()->default_value("small"),
79 "lattice size (small/large)")
80 ("amplitude,a", po::value<double>()->default_value(1),
81 "amplitude multiplicator")
85 po::store(po::parse_command_line(argc, argv, desc), vm);
88 if (vm.count("help")) {
89 std::cout << desc << "\n";
95 settings.windSpeed = vm["windspeed"].as<double>();
97 if (vm["size"].as<std::string>() == "large") {
98 settings.latticeSize = 256;
99 settings.latticeExtend = 20;
100 settings.amplitudeFactor = vm["amplitude"].as<double>() * 0.00000004;
103 settings.latticeSize = 128;
104 settings.latticeExtend = 10;
105 settings.amplitudeFactor = vm["amplitude"].as<double>() * 0.0000001;
113 glClear(GL_COLOR_BUFFER_BIT);
115 seaView->setupView();
123 void glReshapeFunc(int width, int height)
125 glMatrixMode(GL_PROJECTION);
127 gluPerspective(50.0, ((float)width/(float)height), 0, 1000.0);
128 glViewport(0, 0, width, height);
131 void glMouseFunc(int button, int state, int x, int y)
133 seaView->onMouseEvent(button, state, x, y);
136 void glMotionFunc(int x, int y)
138 seaView->onMouseMove(x, y);