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 double WaterSurface::unitLength() const
32 void WaterSurface::draw() const
34 glScalef(m_unitLength, m_unitLength, 1.0f);
35 glTranslatef(-(float)(m_size - 1) / 2, -(float)(m_size - 1) / 2, 0);
37 for (int y = 0; y < m_size - 1; ++y) {
38 for (int x = 0; x < m_size - 1; ++x) {
44 void WaterSurface::drawSingleTile(int x, int y) const
46 glBegin(GL_TRIANGLES);
48 glVertex3f(x, y, at(x, y).getHeight());
49 glVertex3f(x+1, y, at(x+1, y).getHeight());
50 glVertex3f(x+1, y+1, at(x+1, y+1).getHeight());
52 glVertex3f(x, y, at(x, y).getHeight());
53 glVertex3f(x, y+1, at(x, y+1).getHeight());
54 glVertex3f(x+1, y+1, at(x+1, y+1).getHeight());