Virtual Testbed
Ship dynamics simulator for extreme conditions
ShipCompartmentObject.hh
1 #ifndef VTESTBED_GRAPHICS_SHIPCOMPARTMENTOBJECT_HH
2 #define VTESTBED_GRAPHICS_SHIPCOMPARTMENTOBJECT_HH
3 
4 #include <Magnum/GL/Buffer.h>
5 #include <Magnum/GL/Mesh.h>
6 #include <Magnum/Shaders/Flat.h>
7 
8 #include <vtestbed/core/compartment.hh>
9 #include <vtestbed/core/types.hh>
10 #include <vtestbed/graphics/IndexBuffer.hh>
11 #include <vtestbed/graphics/VertexBuffer.hh>
12 #include <vtestbed/graphics/types.hh>
13 
14 namespace vtb {
15 
16  namespace graphics {
17 
18  template <class T>
19  class ShipCompartmentObject: public Object3D, public Drawable3D {
20 
21  public:
23 
24  private:
25  Magnum::GL::Mesh _mesh{Magnum::GL::MeshPrimitive::Triangles};
26  Magnum::Shaders::Flat3D _shader;
27  VertexBuffer _vertices;
28  IndexBuffer _indices;
29  Vector3 _color {T{0.f}, T{1.f}, T{0.f}};
30  Float _alpha {0.3f};
31  std::string _name;
32  bool _show = true;
33  bool _fire = false;
34  bool _flooding = false;
35 
36  public:
37 
38  ShipCompartmentObject() = default;
39  explicit ShipCompartmentObject(const compartment_type& compartment);
40 
41  void draw(const Matrix4& m, Camera3D& camera) override;
42 
43  inline void show(bool b) { this->_show = b; }
44  inline const Vector3& color() const { return this->_color; }
45  inline void color(Vector3 v) { this->_color = v; }
46  inline void alpha(Float a) { this->_alpha = a; }
47 
48  inline const std::string& name() const { return this->_name; }
49  inline bool fire() const { return this->_fire; }
50  inline void fire(bool rhs) { this->_fire = rhs; update_color(); }
51  inline bool flooding() const { return this->_flooding; }
52  inline void flooding(bool rhs) { this->_flooding = rhs; update_color(); }
53 
54  private:
55  void update_color();
56 
57  };
58 
59  }
60 
61 }
62 
63 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9