]> git.treefish.org Git - seamulator.git/blob - seamulator.cpp
6bb51c9460df936cb0da508eadd6279ccecdc85c
[seamulator.git] / seamulator.cpp
1 #include <ctime>
2
3 #include <GL/glut.h>
4
5 #include "sea.h"
6 #include "watersurface.h"
7
8 const int LATTICE_SIZE = 10;
9 const int LATTICE_UNIT = 1;
10
11 WaterSurface surface(LATTICE_SIZE);
12 Sea sea(surface);
13
14 void drawSingleTile(int x, int y)
15 {
16   glBegin(GL_TRIANGLES);
17
18   glVertex3f(x, y, surface.at(x, y).getHeight());
19   glVertex3f(x+1, y, surface.at(x+1, y).getHeight());
20   glVertex3f(x+1, y+1, surface.at(x+1, y+1).getHeight());
21
22   glVertex3f(x, y, surface.at(x, y).getHeight());
23   glVertex3f(x, y+1, surface.at(x, y+1).getHeight());
24   glVertex3f(x+1, y+1, surface.at(x+1, y+1).getHeight());
25
26   glEnd();
27 }
28
29 void displayMe(void)
30 {
31   glMatrixMode(GL_PROJECTION); // Switch to the projection matrix so that we can manipulate how our scene is viewed  
32   glLoadIdentity(); // Reset the projection matrix to the identity matrix so that we don't get any artifacts (cleaning up)
33   gluPerspective(50, (GLfloat)300 / (GLfloat)300, 0, 1000); // Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes
34   gluLookAt(0,-10,10, 0,0,0, 0,1,0);
35   glMatrixMode(GL_MODELVIEW);
36   glLoadIdentity();
37
38   glClear(GL_COLOR_BUFFER_BIT);
39
40   sea.update();
41
42   glScalef(LATTICE_UNIT, LATTICE_UNIT, 1.0f);
43   glTranslatef(-(float)(LATTICE_SIZE-1)/2, -(float)(LATTICE_SIZE-1)/2, 0);
44   for (int y = 0; y < LATTICE_SIZE-1; ++y) {
45     for (int x = 0; x < LATTICE_SIZE-1; ++x) {
46       drawSingleTile(x, y);
47     }
48   }
49
50   glFlush();
51
52   glutPostRedisplay();
53 }
54
55 int main(int argc, char** argv)
56 {
57   std::srand(std::time(0));
58
59   glutInit(&argc, argv);
60   glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
61   glEnable(GL_DEPTH_TEST);
62   glutInitWindowSize(300, 300);
63   glutInitWindowPosition(100, 100);
64   glutCreateWindow("seamulator");
65
66   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
67
68   glutDisplayFunc(displayMe);
69   glutMainLoop();
70   return 0;
71 }