#include <cstdlib>
-Sea::Sea(WaterSurface& surface) : m_surface{surface}
+#include "watersurface.h"
+
+Sea::Sea(WaterSurfacePtr surface) : m_surface{surface}
{
}
void Sea::update()
{
- for (int y = 0; y < m_surface.size(); ++y) {
- for (int x = 0; x < m_surface.size(); ++x) {
- m_surface.at(x, y)
+ for (int y = 0; y < m_surface->size(); ++y) {
+ for (int x = 0; x < m_surface->size(); ++x) {
+ m_surface->at(x, y)
.setHeight(((double)std::rand()/(double)RAND_MAX));
}
}
const int LATTICE_SIZE = 10;
const int LATTICE_UNIT = 1;
-WaterSurface surface(LATTICE_SIZE);
-Sea sea(surface);
+SeaPtr sea;
+WaterSurfacePtr surface;
void drawSingleTile(int x, int y)
{
glBegin(GL_TRIANGLES);
- glVertex3f(x, y, surface.at(x, y).getHeight());
- glVertex3f(x+1, y, surface.at(x+1, y).getHeight());
- glVertex3f(x+1, y+1, surface.at(x+1, y+1).getHeight());
+ glVertex3f(x, y, surface->at(x, y).getHeight());
+ glVertex3f(x+1, y, surface->at(x+1, y).getHeight());
+ glVertex3f(x+1, y+1, surface->at(x+1, y+1).getHeight());
- glVertex3f(x, y, surface.at(x, y).getHeight());
- glVertex3f(x, y+1, surface.at(x, y+1).getHeight());
- glVertex3f(x+1, y+1, surface.at(x+1, y+1).getHeight());
+ glVertex3f(x, y, surface->at(x, y).getHeight());
+ glVertex3f(x, y+1, surface->at(x, y+1).getHeight());
+ glVertex3f(x+1, y+1, surface->at(x+1, y+1).getHeight());
glEnd();
}
glClear(GL_COLOR_BUFFER_BIT);
- sea.update();
+ sea->update();
glScalef(LATTICE_UNIT, LATTICE_UNIT, 1.0f);
glTranslatef(-(float)(LATTICE_SIZE-1)/2, -(float)(LATTICE_SIZE-1)/2, 0);
{
std::srand(std::time(0));
+ surface = std::make_shared<WaterSurface>(LATTICE_SIZE);
+ sea = std::make_shared<Sea>(surface);
+
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glEnable(GL_DEPTH_TEST);