Skip to content

Commit

Permalink
Documentation and small tweaks
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina committed Jul 20, 2021
1 parent 1f01c22 commit 323471f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
35 changes: 21 additions & 14 deletions src/plugins/interactive_view_control/InteractiveViewControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ignition::gui::plugins::InteractiveViewControlPrivate
public: std::string cameraViewControlService;

/// \brief Ray query for mouse clicks
public: rendering::RayQueryPtr rayQuery;
public: rendering::RayQueryPtr rayQuery{nullptr};

//// \brief Pointer to the rendering scene
public: rendering::ScenePtr scene{nullptr};
Expand All @@ -114,10 +114,10 @@ void InteractiveViewControlPrivate::OnRender()
if (!this->scene)
return;

for (unsigned int i = 0; i < scene->NodeCount(); ++i)
for (unsigned int i = 0; i < this->scene->NodeCount(); ++i)
{
auto cam = std::dynamic_pointer_cast<rendering::Camera>(
scene->NodeByIndex(i));
this->scene->NodeByIndex(i));
if (cam)
{
bool isUserCamera = false;
Expand Down Expand Up @@ -156,6 +156,9 @@ void InteractiveViewControlPrivate::OnRender()
if (!this->mouseDirty)
return;

if (!this->camera)
return;

std::lock_guard<std::mutex> lock(this->mutex);

if (this->viewController == "ortho")
Expand All @@ -177,8 +180,7 @@ void InteractiveViewControlPrivate::OnRender()

if (this->mouseEvent.Type() == common::MouseEvent::SCROLL)
{
this->target =
this->ScreenToScene(this->mouseEvent.Pos());
this->target = this->ScreenToScene(this->mouseEvent.Pos());
this->viewControl->SetTarget(this->target);
double distance = this->camera->WorldPosition().Distance(
this->target);
Expand All @@ -189,8 +191,7 @@ void InteractiveViewControlPrivate::OnRender()
{
if (this->drag == math::Vector2d::Zero)
{
this->target = this->ScreenToScene(
this->mouseEvent.PressPos());
this->target = this->ScreenToScene(this->mouseEvent.PressPos());
this->viewControl->SetTarget(this->target);
}

Expand All @@ -207,13 +208,12 @@ void InteractiveViewControlPrivate::OnRender()
{
this->viewControl->Orbit(this->drag);
}
// Zoom with right button
else if (this->mouseEvent.Buttons() & common::MouseEvent::RIGHT)
{
double hfov = this->camera->HFOV().Radian();
double vfov = 2.0f * atan(tan(hfov / 2.0f) /
this->camera->AspectRatio());
double distance = this->camera->WorldPosition().Distance(
this->target);
double vfov = 2.0f * atan(tan(hfov / 2.0f) / this->camera->AspectRatio());
double distance = this->camera->WorldPosition().Distance(this->target);
double amount = ((-this->drag.Y() /
static_cast<double>(this->camera->ImageHeight()))
* distance * tan(vfov/2.0) * 6.0);
Expand Down Expand Up @@ -253,6 +253,15 @@ bool InteractiveViewControlPrivate::OnViewControl(const msgs::StringMsg &_msg,
msgs::Boolean &_res)
{
std::lock_guard<std::mutex> lock(this->mutex);

if (_msg.data() != "orbit" && _msg.data() != "ortho")
{
ignwarn << "View controller type not supported [" << _msg.data() << "]"
<< std::endl;
_res.set_data(false);
return true;
}

this->viewController = _msg.data();

// mark mouse dirty to trigger HandleMouseEvent call and
Expand All @@ -270,9 +279,7 @@ InteractiveViewControl::InteractiveViewControl()
}

/////////////////////////////////////////////////
InteractiveViewControl::~InteractiveViewControl()
{
}
InteractiveViewControl::~InteractiveViewControl() = default;

/////////////////////////////////////////////////
void InteractiveViewControl::LoadConfig(
Expand Down
21 changes: 19 additions & 2 deletions src/plugins/interactive_view_control/InteractiveViewControl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,25 @@ namespace plugins
{
class InteractiveViewControlPrivate;

/// \brief This Plugin allows to control the scene3D camera
/// with the mouse
/// \brief This Plugin allows to control a user camera with the mouse:
///
/// * Drag left button to pan
/// * Drag middle button to orbit
/// * Drag right button or scroll wheel to zoom
///
/// This plugin also supports changing between perspective and orthographic
/// projections through the `/gui/camera/view_control` service. Perspective
/// projection is used by default. For example:
///
/// ign service -s /gui/camera/view_control
/// --reqtype ignition.msgs.StringMsg
/// --reptype ignition.msgs.Boolean
/// --timeout 2000 --req 'data: "ortho"'
///
/// Supported options are:
///
/// * `orbit`: perspective projection
/// * `ortho`: orthographic projection
class InteractiveViewControl : public Plugin
{
Q_OBJECT
Expand Down

0 comments on commit 323471f

Please sign in to comment.