diff --git a/Migration.md b/Migration.md index 527776ebb..e85451af1 100644 --- a/Migration.md +++ b/Migration.md @@ -5,6 +5,20 @@ Deprecated code produces compile-time warnings. These warning serve as notification to users that their code should be upgraded. The next major release will remove the deprecated code. +## Gazebo Rendering 8.x to 9.x + +### Deprecations + +1. **Ogre2SelectionBuffer** + + Deprecated: `bool ExecuteQuery(const int _x, const int _y, Ogre::Item *&_item, math::Vector3d &_point)` + + Replacement: `bool ExecuteQuery(int _x, int _y, Ogre::MovableObject *&_obj, math::Vector3d &_point)` + +### Modifications + +1. **Ogre2SelectionBuffer** + + Removed: `Ogre::OgreItem *OnSelectionClick(const int _x, const int _y)` + + Replacement: `Ogre::MovableObject *OnSelectionClick(int _x, int _y)` + ## Gazebo Rendering 7.x to 8.x ### Deprecations diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2SelectionBuffer.hh b/ogre2/include/gz/rendering/ogre2/Ogre2SelectionBuffer.hh index 610a045d3..dbe0e3abf 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2SelectionBuffer.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2SelectionBuffer.hh @@ -62,8 +62,8 @@ namespace gz /// \brief Handle on mouse click /// \param[in] _x X coordinate in pixels. /// \param[in] _y Y coordinate in pixels. - /// \return Returns the Ogre item at the coordinate. - public: Ogre::Item *OnSelectionClick(const int _x, const int _y); + /// \return Returns the Ogre movable object at the coordinate. + public: Ogre::MovableObject *OnSelectionClick(int _x, int _y); /// \brief Perform selection operation and get ogre item and /// point of intersection. @@ -72,8 +72,18 @@ namespace gz /// \param[out] _item Ogre item at the coordinate. /// \param[out] _point 3D point of intersection with the ogre item's mesh. /// \return True if an ogre item is found, false otherwise - public: bool ExecuteQuery(const int _x, const int _y, Ogre::Item *&_item, - math::Vector3d &_point); + public: bool GZ_DEPRECATED(9) ExecuteQuery(const int _x, const int _y, + Ogre::Item *&_item, math::Vector3d &_point); + + /// \brief Perform selection operation and get ogre item and + /// point of intersection. + /// \param[in] _x X coordinate in pixels. + /// \param[in] _y Y coordinate in pixels. + /// \param[out] _obj Ogre movable object at the coordinate. + /// \param[out] _point 3D point of intersection with the ogre object. + /// \return True if an ogre object is found, false otherwise + public: bool ExecuteQuery(int _x, int _y, + Ogre::MovableObject *&_obj, math::Vector3d &_point); /// \brief Set dimension of the selection buffer /// \param[in] _width X dimension in pixels. diff --git a/ogre2/src/Ogre2Camera.cc b/ogre2/src/Ogre2Camera.cc index 7cdb7c8fb..aa3024431 100644 --- a/ogre2/src/Ogre2Camera.cc +++ b/ogre2/src/Ogre2Camera.cc @@ -321,19 +321,19 @@ VisualPtr Ogre2Camera::VisualAt(const math::Vector2i &_mousePos) math::Vector2i mousePos( static_cast(std::rint(ratio * _mousePos.X())), static_cast(std::rint(ratio * _mousePos.Y()))); - Ogre::Item *ogreItem = this->selectionBuffer->OnSelectionClick( + Ogre::MovableObject *ogreObj = this->selectionBuffer->OnSelectionClick( mousePos.X(), mousePos.Y()); - if (ogreItem) + if (ogreObj) { - if (!ogreItem->getUserObjectBindings().getUserAny().isEmpty() && - ogreItem->getUserObjectBindings().getUserAny().getType() == + if (!ogreObj->getUserObjectBindings().getUserAny().isEmpty() && + ogreObj->getUserObjectBindings().getUserAny().getType() == typeid(unsigned int)) { try { result = this->scene->VisualById(Ogre::any_cast( - ogreItem->getUserObjectBindings().getUserAny())); + ogreObj->getUserObjectBindings().getUserAny())); } catch(Ogre::Exception &e) { diff --git a/ogre2/src/Ogre2RayQuery.cc b/ogre2/src/Ogre2RayQuery.cc index ae7bd3e4d..6f7b25c14 100644 --- a/ogre2/src/Ogre2RayQuery.cc +++ b/ogre2/src/Ogre2RayQuery.cc @@ -247,10 +247,10 @@ RayQueryResult Ogre2RayQuery::ClosestPointBySelectionBuffer() this->dataPtr->camera->ImageWidth(), this->dataPtr->camera->ImageHeight()); RayQueryResult result; - Ogre::Item *ogreItem = nullptr; + Ogre::MovableObject *ogreObj = nullptr; math::Vector3d point; bool success = this->dataPtr->camera->SelectionBuffer()->ExecuteQuery( - this->dataPtr->imgPos.X(), this->dataPtr->imgPos.Y(), ogreItem, point); + this->dataPtr->imgPos.X(), this->dataPtr->imgPos.Y(), ogreObj, point); result.distance = -1; if (success) @@ -258,21 +258,16 @@ RayQueryResult Ogre2RayQuery::ClosestPointBySelectionBuffer() double distance = this->dataPtr->camera->WorldPosition().Distance(point) - this->dataPtr->camera->NearClipPlane(); unsigned int objectId = 0; - if (ogreItem) + if (ogreObj) { - if (!ogreItem->getUserObjectBindings().getUserAny().isEmpty() && - ogreItem->getUserObjectBindings().getUserAny().getType() == + if (!ogreObj->getUserObjectBindings().getUserAny().isEmpty() && + ogreObj->getUserObjectBindings().getUserAny().getType() == typeid(unsigned int)) { - auto userAny = ogreItem->getUserObjectBindings().getUserAny(); + auto userAny = ogreObj->getUserObjectBindings().getUserAny(); objectId = Ogre::any_cast(userAny); } } - else - { - // \todo(anyone) Change ExecuteQuery to return Ogre::MovableObject - // in gz-rendering8 so heightmaps can be included in the result - } if (!std::isinf(distance)) { result.distance = distance; diff --git a/ogre2/src/Ogre2SelectionBuffer.cc b/ogre2/src/Ogre2SelectionBuffer.cc index e83cc768d..543ea59a5 100644 --- a/ogre2/src/Ogre2SelectionBuffer.cc +++ b/ogre2/src/Ogre2SelectionBuffer.cc @@ -413,17 +413,31 @@ void Ogre2SelectionBuffer::SetDimensions( this->CreateRTTBuffer(); } ///////////////////////////////////////////////// -Ogre::Item *Ogre2SelectionBuffer::OnSelectionClick(const int _x, const int _y) +Ogre::MovableObject *Ogre2SelectionBuffer::OnSelectionClick(int _x, int _y) { - Ogre::Item *item = nullptr; + Ogre::MovableObject *obj = nullptr; math::Vector3d point; - this->ExecuteQuery(_x, _y, item, point); - return item; + this->ExecuteQuery(_x, _y, obj, point); + return obj; } ///////////////////////////////////////////////// bool Ogre2SelectionBuffer::ExecuteQuery(const int _x, const int _y, Ogre::Item *&_item, math::Vector3d &_point) +{ + Ogre::MovableObject *obj = nullptr; + bool out = this->ExecuteQuery(_x, _y, obj, _point); + + Ogre::Item *item = dynamic_cast(obj); + if (item) + _item = item; + + return out; +} + +///////////////////////////////////////////////// +bool Ogre2SelectionBuffer::ExecuteQuery(int _x, int _y, + Ogre::MovableObject *&_obj, math::Vector3d &_point) { if (!this->dataPtr->renderTexture) return false; @@ -529,11 +543,8 @@ bool Ogre2SelectionBuffer::ExecuteQuery(const int _x, const int _y, { if (entName == heightmap->Name()) { - // \todo(anyone) change return type to MovableObject instead of item - // in gz-rendering8 so we can uncomment the line below to return a - // heightmap object - // _item = std::dynamic_pointer_cast( - // heightmap->OgreObject()); + _obj = std::dynamic_pointer_cast( + heightmap)->OgreObject(); _point = point; return true; } @@ -543,7 +554,7 @@ bool Ogre2SelectionBuffer::ExecuteQuery(const int _x, const int _y, } else { - _item = dynamic_cast(collection[0]); + _obj = dynamic_cast(collection[0]); _point = point; return true; }