2 * Copyright (C) 2016 Alexander Schmidt
4 * This file is part of Seamulator.
6 * Seamulator is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Seamulator is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
20 #include "watersurface.h"
24 WaterSurface::WaterSurface(int size, double extend) :
28 m_points.resize(size*size);
31 SurfacePoint& WaterSurface::at(int x, int y)
33 return m_points.at(x + m_size*y);
36 const SurfacePoint& WaterSurface::at(int x, int y) const
38 return m_points.at(x + m_size*y);
41 int WaterSurface::size() const
46 double WaterSurface::extend() const
51 void WaterSurface::draw() const
53 const double scaleFactor{m_extend / m_size};
55 glScalef(scaleFactor, scaleFactor, 1.0f);
56 glTranslatef(-(float)(m_size - 1) / 2, -(float)(m_size - 1) / 2, 0);
58 for (int y = 0; y < m_size - 1; ++y) {
59 for (int x = 0; x < m_size - 1; ++x) {
65 void WaterSurface::drawSingleTile(int x, int y) const
67 glBegin(GL_TRIANGLES);
69 glVertex3f(x, y, at(x, y).getHeight());
70 glVertex3f(x+1, y, at(x+1, y).getHeight());
71 glVertex3f(x+1, y+1, at(x+1, y+1).getHeight());
73 glVertex3f(x, y, at(x, y).getHeight());
74 glVertex3f(x, y+1, at(x, y+1).getHeight());
75 glVertex3f(x+1, y+1, at(x+1, y+1).getHeight());