]> git.treefish.org Git - seamulator.git/blob - seamulator.cpp
Modified ignores
[seamulator.git] / seamulator.cpp
1 #include <ctime>
2 #include <cmath>
3 #include <memory>
4
5 #include <GL/glut.h>
6
7 #include "sea.h"
8 #include "seaview.h"
9 #include "watersurface.h"
10
11 const int LATTICE_SIZE{128};
12 const double LATTICE_EXTEND{10};
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_DISTANCE{LATTICE_EXTEND * 1.5};
18 const double INIT_VIEW_AZIMUTH{0};
19 const double INIT_VIEW_ALTITUDE{M_PI / 4};
20 const char WINDOW_TITLE[]{"seamulator"};
21
22 SeaPtr sea;
23 WaterSurfacePtr surface;
24 std::unique_ptr<SeaView> seaView;
25
26 void glDisplayFunc();
27 void glReshapeFunc(int width, int height);
28 void glMouseFunc(int button, int state, int x, int y);
29 void glMotionFunc(int x, int y);
30
31 int main(int argc, char** argv)
32 {
33   std::srand(std::time(0));
34
35   surface = std::make_shared<WaterSurface>(LATTICE_SIZE, LATTICE_EXTEND);
36   sea = std::make_shared<Sea>(surface);
37   seaView = std::make_unique<SeaView>(INIT_VIEW_DISTANCE, INIT_VIEW_AZIMUTH,
38                                       INIT_VIEW_ALTITUDE);
39
40   glutInit(&argc, argv);
41   glutInitDisplayMode(GLUT_DOUBLE);
42   glutInitWindowSize(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT);
43   glutInitWindowPosition(INIT_WINDOW_POS_X, INIT_WINDOW_POS_Y);
44   glutCreateWindow(WINDOW_TITLE);
45   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
46
47   glutDisplayFunc(glDisplayFunc);
48   glutReshapeFunc(glReshapeFunc);
49   glutMouseFunc(glMouseFunc);
50   glutMotionFunc(glMotionFunc);
51
52   glutMainLoop();
53
54   return 0;
55 }
56
57 void glDisplayFunc()
58 {
59   glClear(GL_COLOR_BUFFER_BIT);
60
61   seaView->setupView();
62   sea->update();
63   surface->draw();
64
65   glutSwapBuffers();
66   glutPostRedisplay();
67 }
68
69 void glReshapeFunc(int width, int height)
70 {
71   glMatrixMode(GL_PROJECTION);
72   glLoadIdentity();
73   gluPerspective(50.0, ((float)width/(float)height), 0, 1000.0);
74   glViewport(0, 0, width, height);
75 }
76
77 void glMouseFunc(int button, int state, int x, int y)
78 {
79   seaView->onMouseEvent(button, state, x, y);
80 }
81
82 void glMotionFunc(int x, int y)
83 {
84   seaView->onMouseMove(x, y);
85 }