From fbc16c6a8e5b44567bea50922df6bd0afb65feda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Mon, 11 Apr 2022 17:10:57 +0200 Subject: [PATCH] Removed screenToPlane method and use rendering::screenToPlane (#1432) Signed-off-by: ahcorde --- src/gui/plugins/spawn/Spawn.cc | 45 ++-------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/src/gui/plugins/spawn/Spawn.cc b/src/gui/plugins/spawn/Spawn.cc index 6dfb2c9d58..be60287e52 100644 --- a/src/gui/plugins/spawn/Spawn.cc +++ b/src/gui/plugins/spawn/Spawn.cc @@ -80,19 +80,6 @@ namespace ignition::gazebo /// \brief Handle placement requests public: void HandlePlacement(); - /// \brief Retrieve the point on a plane at z = 0 in the 3D scene hit by a - /// ray cast from the given 2D screen coordinates. - /// \param[in] _screenPos 2D coordinates on the screen, in pixels. - /// \param[in] _camera User camera - /// \param[in] _rayQuery Ray query for mouse clicks - /// \param[in] _offset Offset along the plane normal - /// \return 3D coordinates of a point in the 3D scene. - math::Vector3d ScreenToPlane( - const math::Vector2i &_screenPos, - const rendering::CameraPtr &_camera, - const rendering::RayQueryPtr &_rayQuery, - const float offset = 0.0); - /// \brief Ignition communication node. public: transport::Node node; @@ -201,34 +188,6 @@ void Spawn::LoadConfig(const tinyxml2::XMLElement *) ()->installEventFilter(this); } - -// TODO(ahcorde): Replace this when this function is on ign-rendering6 -///////////////////////////////////////////////// -math::Vector3d SpawnPrivate::ScreenToPlane( - const math::Vector2i &_screenPos, - const rendering::CameraPtr &_camera, - const rendering::RayQueryPtr &_rayQuery, - const float offset) -{ - // Normalize point on the image - double width = _camera->ImageWidth(); - double height = _camera->ImageHeight(); - - double nx = 2.0 * _screenPos.X() / width - 1.0; - double ny = 1.0 - 2.0 * _screenPos.Y() / height; - - // Make a ray query - _rayQuery->SetFromCamera( - _camera, math::Vector2d(nx, ny)); - - math::Planed plane(math::Vector3d(0, 0, 1), offset); - - math::Vector3d origin = _rayQuery->Origin(); - math::Vector3d direction = _rayQuery->Direction(); - double distance = plane.Distance(origin, direction); - return origin + direction * distance; -} - ///////////////////////////////////////////////// void SpawnPrivate::HandlePlacement() { @@ -237,7 +196,7 @@ void SpawnPrivate::HandlePlacement() if (this->spawnPreview && this->hoverDirty) { - math::Vector3d pos = this->ScreenToPlane( + math::Vector3d pos = ignition::rendering::screenToPlane( this->mouseHoverPos, this->camera, this->rayQuery); pos.Z(this->spawnPreview->WorldPosition().Z()); this->spawnPreview->SetWorldPosition(pos); @@ -257,7 +216,7 @@ void SpawnPrivate::HandlePlacement() if (!_result) ignerr << "Error creating entity" << std::endl; }; - math::Vector3d pos = this->ScreenToPlane( + math::Vector3d pos = ignition::rendering::screenToPlane( this->mouseEvent.Pos(), this->camera, this->rayQuery); pos.Z(pose.Pos().Z()); msgs::EntityFactory req;