Virtual Testbed
Ship dynamics simulator for extreme conditions
GerstnerSurface.hh
1 #ifndef VTESTBED_GRAPHICS_GERSTNERSURFACE_HH
2 #define VTESTBED_GRAPHICS_GERSTNERSURFACE_HH
3 
4 #include <vtestbed/core/types.hh>
5 #include <vtestbed/graphics/GerstnerShader.hh>
6 #include <vtestbed/graphics/SurfaceShader.hh>
7 #include <vtestbed/graphics/types.hh>
8 
9 namespace vtb {
10 
11  namespace graphics {
12 
13  template <class T>
14  class GerstnerSurface: public Object3D, public Drawable3D {
15 
16  private:
17  using vec3 = vtb::core::Vector<T,3>;
18  using vec2 = vtb::core::Vector<T,2>;
19  using int2 = vtb::core::int2;
20  using vertex_matrix = vtb::core::Array<vec3,2>;
21 
22  private:
23  GerstnerShader _shader;
24  Mesh _mesh;
25  Buffer _indexBuffer, _vertexBuffer;
26  Vector2 _slicePoint;
27  bool _show = false;
28  vec2 _size;
29  int2 _gridSize;
30 
31  public:
32 
34 
35  void step(const vertex_matrix& zeta, int2 gridSize, vec2 size);
36 
37  inline void showSlice(bool show) { this->_shader.showSlice(show); }
38 
39  inline void
40  setSlice(const vec2& slice) {
41  _shader.setSlice(Vector2(slice(0), slice(1)));
42  }
43 
44  inline void show(bool b) { this->_show = b; }
45 
46  private:
47  void
48  generateSurface(
49  int2 gridSize,
50  vec2 size,
51  vtb::core::Array2<vec3> zeta
52  );
53 
54  void draw(const Matrix4& transformation, Camera3D& camera) override;
55 
56  };
57 
58  }
59 
60 }
61 
62 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9