Virtual Testbed
Ship dynamics simulator for extreme conditions
ShipHullObject.hh
1 #ifndef VTESTBED_GRAPHICS_SHIPHULLOBJECT_HH
2 #define VTESTBED_GRAPHICS_SHIPHULLOBJECT_HH
3 
4 #include <Magnum/GL/Buffer.h>
5 #include <Magnum/GL/Mesh.h>
6 #include <Magnum/Shaders/Phong.h>
7 
8 #include <vtestbed/core/types.hh>
9 #include <vtestbed/core/testbed.hh>
10 #include <vtestbed/geometry/polyhedron.hh>
11 #include <vtestbed/graphics/IndexBuffer.hh>
12 #include <vtestbed/graphics/ShipShader.hh>
13 #include <vtestbed/graphics/VertexBuffer.hh>
14 #include <vtestbed/graphics/types.hh>
15 
16 namespace vtb {
17 
18  namespace graphics {
19 
20  template <class T>
21  class ShipHullObject: public Object3D, public Drawable3D {
22 
23  public:
24  using vec3 = vtb::core::Vector3<T>;
28 
29  private:
30  struct Spherlet {
31  union {
32  Vector3 position;
33  vec3 position0;
34  };
35  union {
36  Vector3 color;
37  vec3 color0;
38  };
39  inline explicit Spherlet(Vector3 p, Vector3 c): position(p), color(c) {}
40  inline explicit Spherlet(vec3 p, vec3 c): position0(p), color0(c) {}
41  inline Spherlet(const Spherlet& rhs): position(rhs.position), color(rhs.color) {}
42  inline Spherlet() = default;
43  inline ~Spherlet() {}
44  };
45 
46  private:
47  Magnum::GL::Mesh _mesh{Magnum::GL::MeshPrimitive::Triangles};
48  Mesh _mesh_center;
49  ShipShader _shader;
50  Magnum::Shaders::Phong _phongShader;
51  VertexBuffer _vertices;
52  VertexBuffer _normals;
53  VertexBuffer _wet;
54  IndexBuffer _indices;
55  VertexBuffer _verticies_center;
56  IndexBuffer _indicies_center;;
57  Vector3 _ambientColor{0.2f, 0.2f, 0.2f};
58  Vector3 _diffuseColor{0.184, 0.513, 0.8};
59  Vector3 _specularColor{0.517333f, 0.142002f, 0.0818566f};
60  Float _shininess{80.0f};
61  bool _show = true;
62  bool _transparency = true;
63  std::vector<Spherlet> _centres;
64 
65  public:
66 
68 
69  void draw(const Matrix4& m, Camera3D& camera) override;
70 
71  void setWettedPanels(const mask_array& mask);
72  void setHull(const polyhedron_type& hull);
73  void clear();
74  void step(const testbed_type& testbed);
75  void init(const testbed_type& testbed);
76 
77  inline void
78  setColor(const vec3& color) {
79  this->_diffuseColor[0] = color(0);
80  this->_diffuseColor[1] = color(1);
81  this->_diffuseColor[2] = color(2);
82  }
83 
84  inline void
85  show(bool b) {
86  this->_show = b;
87  }
88 
89  inline void
90  transparency(bool b) {
91  this->_transparency = b;
92  }
93 
94  inline void
95  addCenter() {
96  _centres.emplace_back(Vector3{0.0f, 0.0f, 0.0f}, Color3{0.0f, 0.0f, 0.0f});
97  }
98 
99  inline void
100  setCenter(Vector3& pos, int num) {
101  _centres[num].position = pos;
102  }
103 
104  inline void
105  setColor(Color3& color, int num) {
106  _centres[num].color = color;
107  }
108 
109  inline Vector3&
110  diffuseColor() {
111  return this->_diffuseColor;
112  }
113 
114  };
115 
116  }
117 
118 }
119 
120 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9