Virtual Testbed
Ship dynamics simulator for extreme conditions
WavySurfaceSlice.hh
1 #ifndef VTESTBED_GRAPHICS_WAVYSURFACESLICE_HH
2 #define VTESTBED_GRAPHICS_WAVYSURFACESLICE_HH
3 
4 #include <functional>
5 
6 #include <Magnum/GL/Buffer.h>
7 #include <Magnum/GL/Mesh.h>
8 #include <Magnum/GL/Texture.h>
9 
10 #include <vtestbed/core/types.hh>
11 #include <vtestbed/graphics/SliceShader.hh>
12 #include <vtestbed/graphics/types.hh>
13 
14 namespace vtb {
15 
16  namespace graphics {
17 
18  template <class T>
19  class WavySurfaceSlice: public Object3D, public Drawable3D {
20 
21  public:
22  using array2 = vtb::core::Array<T,2>;
23  using array3 = vtb::core::Array<T,3>;
24  using vec3 = vtb::core::Vector<T,3>;
25  using vec2 = vtb::core::Vector<T,2>;
26  using int2 = vtb::core::int2;
30 
31  public:
32  struct GridVertex {
33  vec3 position;
34  vec2 text;
35  GridVertex() = default;
36  GridVertex(vec3 p, vec2 t): position(p), text(t) {}
37  };
39  using vertex_matrix = vtb::core::Array<vec3,2>;
40  using vertex_field = vtb::core::Array<vec3,3>;
41  using interpolate_2d = std::function<T(const vec2&)>;
42  using interpolate_3d = std::function<T(const vec3&)>;
43 
44  private:
45  SliceShader _shader;
46  Mesh _mesh;
47  Buffer _indexBuffer, _vertexBuffer;
48  Texture2D _texture;
49  vec2 _slice{T{}};
50  int _axis = 0;
51  bool _show = false;
52 
53  public:
54 
55  inline explicit
56  WavySurfaceSlice(int axis): Drawable3D{*this, nullptr}, _axis(axis) {}
57 
58  void step(const testbed_type& testbed);
59  void step_regular(const testbed_type& testbed);
60  void step_irregular(const testbed_type& testbed);
61 
62  inline void show(bool b) { this->_show = b; }
63  inline void setSlice(const vec2& rhs) { this->_slice = rhs; }
64 
65  private:
66 
67  void draw(const Matrix4& transformation, Camera3D& camera) override;
68 
71  grid2 slice_grid(const grid3& gridZXY, int numPoints);
72 
73  void updateMesh(const grid_vertex_array& data, int numPoints);
74  void updateTexture(const vertex_matrix& texture, const int2& size);
75 
76  void generateMesh(
77  interpolate_2d zeta,
78  Float z_min,
79  const grid2& grid_xy
80  );
81 
82  void generateTexture(
83  interpolate_3d phi,
84  Float phi_max,
85  const grid3& phi_grid,
86  const grid2& grid_xy
87  );
88 
89  static array3 to_scalar_field(const vertex_field& field);
90 
91  };
92 
93  }
94 
95 }
96 
97 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9