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