Skip to content

Commit

Permalink
Add method to draw 3D label in Irrlicht. Clean up drawArrow signature
Browse files Browse the repository at this point in the history
  • Loading branch information
dariofusai93 committed Dec 12, 2024
1 parent fba6177 commit dc1db92
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
26 changes: 22 additions & 4 deletions src/chrono_irrlicht/ChIrrTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,11 +1085,11 @@ void drawCoordsys(ChVisualSystemIrrlicht* vis, const ChCoordsys<>& coord, double
// Draw a line arrow in 3D space with given color.
// -----------------------------------------------------------------------------
void drawArrow(ChVisualSystemIrrlicht* vis,
ChVector3d start,
ChVector3d end,
ChVector3d plane_normal,
const ChVector3d& start,
const ChVector3d& end,
const ChVector3d& plane_normal,
bool sharp,
ChColor col,
const ChColor& col,
bool use_Zbuffer) {
drawSegment(vis, start, end, col, use_Zbuffer); // main segment
ChVector3d dir = (end - start).GetNormalized();
Expand All @@ -1107,6 +1107,24 @@ void drawArrow(ChVisualSystemIrrlicht* vis,
drawSegment(vis, end, p2, col, use_Zbuffer); // arrow segment 2
}

// -----------------------------------------------------------------------------
// Draw a label in 3D scene at given position.
// -----------------------------------------------------------------------------
void drawLabel3D(ChVisualSystemIrrlicht* vis,
const std::string& text,
const ChVector3d& position,
const ChColor& color,
bool use_Zbuffer) {
irr::core::position2di spos =
vis->GetSceneManager()->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(
irr::core::vector3dfCH(position));
auto font = vis->GetGUIEnvironment()->getFont(GetChronoDataFile("fonts/arial8.xml").c_str());
if (font) {
font->draw(text.c_str(), irr::core::rect<irr::s32>(spos.X - 15, spos.Y, spos.X + 15, spos.Y + 10),
tools::ToIrrlichtSColor(color));
}
}

} // end namespace tools
} // end namespace irrlicht
} // end namespace chrono
21 changes: 14 additions & 7 deletions src/chrono_irrlicht/ChIrrTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,22 @@ ChApiIrr void drawCoordsys(ChVisualSystemIrrlicht* vis,
bool use_Zbuffer = false);

/// Draw a line arrow in 3D space with given color.
ChApiIrr void drawArrow(ChVisualSystemIrrlicht* vis, ///< visual system
ChVector3d start, ///< arrow start point
ChVector3d end, ///< arrow end point
ChVector3d plane_normal = VECT_Y, ///< normal to plane containing arrow segments
bool sharp = false, ///< set arrow shape as 'sharp' or 'wide'
ChColor col = ChColor(1.f, 1.f, 1.f), ///< color
bool use_Zbuffer = false ///< use Z buffer
ChApiIrr void drawArrow(ChVisualSystemIrrlicht* vis, ///< visual system
const ChVector3d& start, ///< arrow start point
const ChVector3d& end, ///< arrow end point
const ChVector3d& plane_normal = VECT_Y, ///< normal to plane containing arrow segments
bool sharp = false, ///< set arrow shape as 'sharp' or 'wide'
const ChColor& col = ChColor(1.f, 1.f, 1.f), ///< color
bool use_Zbuffer = false ///< use Z buffer
);

/// Draw a label in 3D scene at given position.
ChApiIrr void drawLabel3D(ChVisualSystemIrrlicht* vis,
const std::string& text,
const ChVector3d& position,
const ChColor& color = ChColor(0.f, 0.f, 0.f),
bool use_Zbuffer = false);

} // end namespace tools

/// @} irrlicht_module
Expand Down
2 changes: 1 addition & 1 deletion src/chrono_irrlicht/ChVisualSystemIrrlicht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ChVisualSystemIrrlicht::ChVisualSystemIrrlicht()
m_device_params.LoggingLevel = irr::ELL_INFORMATION;

// Create the GUI
m_gui = std::unique_ptr<ChIrrGUI>(new ChIrrGUI());
m_gui = std::make_unique<ChIrrGUI>();

// Create shared meshes
sphereMesh = createEllipticalMesh(1.0, 1.0, -2, +2, 0, 15, 8);
Expand Down

0 comments on commit dc1db92

Please sign in to comment.