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;
32 namespace po = boost::program_options;
35 void glReshapeFunc(int width, int height);
36 void glMouseFunc(int button, int state, int x, int y);
37 void glMotionFunc(int x, int y);
38 Settings parseArguments(int argc, char** argv, po::options_description desc);
40 int main(int argc, char** argv)
42 po::options_description desc("Available options");
44 ("help,h", "produce help message")
45 ("windspeed,w", po::value<double>()->default_value(10),
46 "wind speed given in m/s")
47 ("size,s", po::value<std::string>()->default_value("small"),
48 "lattice size (small/large)")
49 ("amplitude,a", po::value<double>()->default_value(1),
50 "amplitude multiplicator")
53 Settings settings = parseArguments(argc, argv, desc);
55 std::srand(std::time(0));
56 surface = std::make_shared<WaterSurface>(settings.latticeSize,
57 settings.latticeExtend);
58 sea = std::make_shared<Sea>(surface,
60 settings.amplitudeFactor);
61 seaView = std::make_unique<SeaView>(settings.latticeExtend * 1.5,
65 glutInit(&argc, argv);
66 glutInitDisplayMode(GLUT_DOUBLE);
67 glutInitWindowSize(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT);
68 glutInitWindowPosition(INIT_WINDOW_POS_X, INIT_WINDOW_POS_Y);
69 glutCreateWindow(WINDOW_TITLE);
70 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
72 glutDisplayFunc(glDisplayFunc);
73 glutReshapeFunc(glReshapeFunc);
74 glutMouseFunc(glMouseFunc);
75 glutMotionFunc(glMotionFunc);
82 Settings parseArguments(int argc, char** argv, po::options_description desc)
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);