MVSim
Lightweight simulator for 2.5D vehicles and robots
VerticalPlane.h
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2026 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/img/TColor.h>
13 #include <mrpt/opengl/CSetOfObjects.h>
14 #include <mrpt/opengl/CSetOfTexturedTriangles.h>
15 #include <mrpt/opengl/CTexturedPlane.h>
16 #include <mvsim/WorldElements/WorldElementBase.h>
17 
18 namespace mvsim
19 {
26 {
27  DECLARES_REGISTER_WORLD_ELEMENT(VerticalPlane)
28  public:
29  VerticalPlane(World* parent, const rapidxml::xml_node<char>* root);
30 
31  virtual void loadConfigFrom(const rapidxml::xml_node<char>* root) override;
32  // ------- Interface with "World" ------
33  void simul_pre_timestep(const TSimulContext& context) override;
34  void simul_post_timestep(const TSimulContext& context) override;
35 
37  struct Opening
38  {
39  enum class Type
40  {
41  DOOR, // No collision, allows passage
42  WINDOW // Has collision, but visible opening
43  };
44 
45  Type type = Type::DOOR;
46  float position = 0.0f;
47  float width = 1.0f;
48  float z_min = 0.0f;
49  float z_max = 2.1f;
50  std::string name;
51 
53  bool overlaps(float pos_start, float pos_end) const;
54  };
55 
56  protected:
57  virtual void internalGuiUpdate(
58  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& viz,
59  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& physical, bool childrenOnly) override;
60 
63 
66  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& viz,
67  const mrpt::optional_ref<mrpt::opengl::COpenGLScene>& physical);
68 
71  const mrpt::math::TPoint2Df& p0, const mrpt::math::TPoint2Df& p1,
72  const mrpt::math::TPoint2Df& normal_offset, bool is_front_face,
73  const mrpt::img::CImage* texture = nullptr);
74 
77  const mrpt::math::TPoint2Df& p0, const mrpt::math::TPoint2Df& p1,
78  const mrpt::math::TPoint2Df& w_inner, const mrpt::math::TPoint2Df& w_outer,
79  const mrpt::img::CImage* texture = nullptr);
80 
83  const mrpt::math::TPoint2Df& p0, const mrpt::math::TPoint2Df& p1,
84  const mrpt::math::TPoint2Df& dir, const mrpt::math::TPoint2Df& w_inner,
85  const mrpt::math::TPoint2Df& w_outer, float wall_length,
86  const mrpt::img::CImage* texture = nullptr);
87 
88  float x0_ = -10, x1_ = -10, y0_ = -10, y1_ = 10;
89  mrpt::img::TColor color_ = {0xa0, 0xa0, 0xa0, 0xff};
90  bool enableShadows_ = true;
91 
93  float thickness_ = 0.02f;
94 
96  std::string textureFileName_;
97  double textureSizeX_ = 1.0;
98  double textureSizeY_ = 1.0;
99 
100  float z_ = .0f, height_ = 3.0f;
101  std::string cull_faces_ = "NONE";
102 
103  mrpt::opengl::CTexturedPlane::Ptr gl_plane_;
104  mrpt::opengl::CSetOfTexturedTriangles::Ptr gl_plane_text_;
105  mrpt::opengl::CSetOfObjects::Ptr glGroup_;
106 
108  b2Body* b2dBody_ = nullptr;
109  double restitution_ = 0.01;
110 
112  std::vector<b2Fixture*> fixtures_;
113 
115  std::vector<Opening> openings_;
116 };
117 } // namespace mvsim
Definition: VerticalPlane.h:26
b2Body * b2dBody_
Definition: VerticalPlane.h:108
void createVisualRepresentation(const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &viz, const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &physical)
void simul_post_timestep(const TSimulContext &context) override
void renderWallFace(const mrpt::math::TPoint2Df &p0, const mrpt::math::TPoint2Df &p1, const mrpt::math::TPoint2Df &normal_offset, bool is_front_face, const mrpt::img::CImage *texture=nullptr)
std::vector< b2Fixture * > fixtures_
Definition: VerticalPlane.h:112
void renderWallEdges(const mrpt::math::TPoint2Df &p0, const mrpt::math::TPoint2Df &p1, const mrpt::math::TPoint2Df &w_inner, const mrpt::math::TPoint2Df &w_outer, const mrpt::img::CImage *texture=nullptr)
std::string textureFileName_
Definition: VerticalPlane.h:96
double restitution_
Default: 0.01.
Definition: VerticalPlane.h:109
void simul_pre_timestep(const TSimulContext &context) override
std::vector< Opening > openings_
Definition: VerticalPlane.h:115
void renderOpeningReveals(const mrpt::math::TPoint2Df &p0, const mrpt::math::TPoint2Df &p1, const mrpt::math::TPoint2Df &dir, const mrpt::math::TPoint2Df &w_inner, const mrpt::math::TPoint2Df &w_outer, float wall_length, const mrpt::img::CImage *texture=nullptr)
float thickness_
Definition: VerticalPlane.h:93
Definition: WorldElementBase.h:28
Definition: World.h:132
Definition: basic_types.h:58
Definition: VerticalPlane.h:38
float position
Position along wall length [0,1] (0=start, 1=end)
Definition: VerticalPlane.h:46
float width
Width of opening in meters.
Definition: VerticalPlane.h:47
bool overlaps(float pos_start, float pos_end) const
float z_max
Top height of opening (meters)
Definition: VerticalPlane.h:49
std::string name
Optional name for the opening.
Definition: VerticalPlane.h:50
float z_min
Bottom height of opening (meters)
Definition: VerticalPlane.h:48