1 #include "watersurface.h"
5 WaterSurface::WaterSurface(int size, double extend) :
9 m_points.resize(size*size);
12 SurfacePoint& WaterSurface::at(int x, int y)
14 return m_points.at(x + m_size*y);
17 const SurfacePoint& WaterSurface::at(int x, int y) const
19 return m_points.at(x + m_size*y);
22 int WaterSurface::size() const
27 double WaterSurface::extend() const
32 void WaterSurface::draw() const
34 const double scaleFactor{m_extend / m_size};
36 glScalef(scaleFactor, scaleFactor, 1.0f);
37 glTranslatef(-(float)(m_size - 1) / 2, -(float)(m_size - 1) / 2, 0);
39 for (int y = 0; y < m_size - 1; ++y) {
40 for (int x = 0; x < m_size - 1; ++x) {
46 void WaterSurface::drawSingleTile(int x, int y) const
48 glBegin(GL_TRIANGLES);
50 glVertex3f(x, y, at(x, y).getHeight());
51 glVertex3f(x+1, y, at(x+1, y).getHeight());
52 glVertex3f(x+1, y+1, at(x+1, y+1).getHeight());
54 glVertex3f(x, y, at(x, y).getHeight());
55 glVertex3f(x, y+1, at(x, y+1).getHeight());
56 glVertex3f(x+1, y+1, at(x+1, y+1).getHeight());