1 #include "watersurface.h"
5 WaterSurface::WaterSurface(int size, double unitLength) :
7 m_unitLength{unitLength}
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 void WaterSurface::draw() const
29 glScalef(m_unitLength, m_unitLength, 1.0f);
30 glTranslatef(-(float)(m_size - 1) / 2, -(float)(m_size - 1) / 2, 0);
32 for (int y = 0; y < m_size - 1; ++y) {
33 for (int x = 0; x < m_size - 1; ++x) {
39 void WaterSurface::drawSingleTile(int x, int y) const
41 glBegin(GL_TRIANGLES);
43 glVertex3f(x, y, at(x, y).getHeight());
44 glVertex3f(x+1, y, at(x+1, y).getHeight());
45 glVertex3f(x+1, y+1, at(x+1, y+1).getHeight());
47 glVertex3f(x, y, at(x, y).getHeight());
48 glVertex3f(x, y+1, at(x, y+1).getHeight());
49 glVertex3f(x+1, y+1, at(x+1, y+1).getHeight());