diff --git a/include/gz/rendering/FrustumVisual.hh b/include/gz/rendering/FrustumVisual.hh index 0d49eec3f..25519a11a 100644 --- a/include/gz/rendering/FrustumVisual.hh +++ b/include/gz/rendering/FrustumVisual.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Open Source Robotics Foundation + * Copyright (C) 2025 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -128,7 +128,8 @@ namespace gz /// \brief Get a plane of the frustum. /// \param[in] _plane The plane to return. /// \return Plane of the frustum. - public: virtual gz::math::Planed Plane(const FrustumVisualPlane _plane) const = 0; + public: virtual gz::math::Planed Plane( + const FrustumVisualPlane _plane) const = 0; /// \brief Get the pose of the frustum /// \return Pose of the frustum diff --git a/include/gz/rendering/Scene.hh b/include/gz/rendering/Scene.hh index bf6b11395..71f2467da 100644 --- a/include/gz/rendering/Scene.hh +++ b/include/gz/rendering/Scene.hh @@ -1118,7 +1118,8 @@ namespace gz /// ID is already in use, NULL will be returned. /// \param[in] _id ID of the new frustum visual /// \return The created frustum visual - public: virtual FrustumVisualPtr CreateFrustumVisual(unsigned int _id) = 0; + public: virtual FrustumVisualPtr CreateFrustumVisual( + unsigned int _id) = 0; /// \brief Create new frustum visual with the given name. A unique ID /// will automatically be assigned to the frustum visual. If the given diff --git a/include/gz/rendering/base/BaseFrustumVisual.hh b/include/gz/rendering/base/BaseFrustumVisual.hh index fbacb04e9..9fef37b72 100644 --- a/include/gz/rendering/base/BaseFrustumVisual.hh +++ b/include/gz/rendering/base/BaseFrustumVisual.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Open Source Robotics Foundation + * Copyright (C) 2025 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,13 +78,8 @@ namespace gz public: virtual void SetAspectRatio(double _aspectRatio) override; // Documentation inherited - public: virtual gz::math::Planed Plane(const FrustumVisualPlane _plane) const override; - - // Documentation inherited - //public: virtual bool Contains(const gz::math::AxisAlignedBox &_b) const override; - - // Documentation inherited - //public: virtual bool Contains(const gz::math::Vector3d &_p) const override; + public: virtual gz::math::Planed Plane( + const FrustumVisualPlane _plane) const override; // Documentation inherited public: virtual gz::math::Pose3d Pose() const override; @@ -219,7 +214,8 @@ namespace gz ///////////////////////////////////////////////// template - gz::math::Planed BaseFrustumVisual::Plane(const FrustumVisualPlane _plane) const + gz::math::Planed BaseFrustumVisual::Plane( + const FrustumVisualPlane _plane) const { return this->planes[_plane]; } @@ -235,7 +231,7 @@ namespace gz template gz::math::Pose3d BaseFrustumVisual::Pose() const { - return this->pose; + return this->pose; } ///////////////////////////////////////////////// template diff --git a/include/gz/rendering/base/BaseScene.hh b/include/gz/rendering/base/BaseScene.hh index b92fd1449..7ec3b8688 100644 --- a/include/gz/rendering/base/BaseScene.hh +++ b/include/gz/rendering/base/BaseScene.hh @@ -847,8 +847,8 @@ namespace gz /// \param[in] _id unique object id. /// \param[in] _name unique object name. /// \return Pointer to a frustum visual - protected: virtual FrustumVisualPtr CreateFrustumVisualImpl(unsigned int _id, - const std::string &_name) = 0; + protected: virtual FrustumVisualPtr CreateFrustumVisualImpl( + unsigned int _id, const std::string &_name) = 0; /// \brief Implementation for creating a heightmap geometry /// \param[in] _id Unique object id. diff --git a/ogre/include/gz/rendering/ogre/OgreFrustumVisual.hh b/ogre/include/gz/rendering/ogre/OgreFrustumVisual.hh index ede578b37..3b7ea484a 100644 --- a/ogre/include/gz/rendering/ogre/OgreFrustumVisual.hh +++ b/ogre/include/gz/rendering/ogre/OgreFrustumVisual.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Open Source Robotics Foundation + * Copyright (C) 2025 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ogre/include/gz/rendering/ogre/OgreScene.hh b/ogre/include/gz/rendering/ogre/OgreScene.hh index 19f14f368..bebc39dd9 100644 --- a/ogre/include/gz/rendering/ogre/OgreScene.hh +++ b/ogre/include/gz/rendering/ogre/OgreScene.hh @@ -181,8 +181,8 @@ namespace gz const std::string &_name) override; // Documentation inherited - protected: virtual FrustumVisualPtr CreateFrustumVisualImpl(unsigned int _id, - const std::string &_name) override; + protected: virtual FrustumVisualPtr CreateFrustumVisualImpl( + unsigned int _id, const std::string &_name) override; // Documentation inherited protected: virtual WireBoxPtr CreateWireBoxImpl(unsigned int _id, diff --git a/ogre/src/OgreFrustumVisual.cc b/ogre/src/OgreFrustumVisual.cc index abe7c1b79..ed76b1067 100644 --- a/ogre/src/OgreFrustumVisual.cc +++ b/ogre/src/OgreFrustumVisual.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Open Source Robotics Foundation + * Copyright (C) 2025 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,8 @@ class gz::rendering::OgreFrustumVisualPrivate public: std::vector> rayLines; /// \brief Frustum visual type - //public: FrustumVisualPlane frustumVisPlane = - //FrustumVisualPlane::FRUSTUM_PLANE_TOP; + // public: FrustumVisualPlane frustumVisPlane = + // FrustumVisualPlane::FRUSTUM_PLANE_TOP; /// \brief The visibility of the visual public: bool visible = true; @@ -39,7 +39,8 @@ class gz::rendering::OgreFrustumVisualPrivate public: std::array points; /// \brief each edge of the frustum. - public: std::array, 12> edges; + public: std::array, 12> edges; }; using namespace gz; @@ -91,7 +92,7 @@ void OgreFrustumVisual::ClearVisualData() ////////////////////////////////////////////////// void OgreFrustumVisual::Update() { - //no ops FIX-ME + // no ops } ////////////////////////////////////////////////// diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2FrustumVisual.hh b/ogre2/include/gz/rendering/ogre2/Ogre2FrustumVisual.hh index f0c63cec0..ad67cf85b 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2FrustumVisual.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2FrustumVisual.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Open Source Robotics Foundation + * Copyright (C) 2025 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh b/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh index 4c2e5d1ef..5be78d9c1 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh @@ -344,8 +344,8 @@ namespace gz const std::string &_name) override; // Documentation inherited - protected: virtual FrustumVisualPtr CreateFrustumVisualImpl(unsigned int _id, - const std::string &_name) override; + protected: virtual FrustumVisualPtr CreateFrustumVisualImpl( + unsigned int _id, const std::string &_name) override; // Documentation inherited protected: virtual WireBoxPtr CreateWireBoxImpl(unsigned int _id, diff --git a/ogre2/src/Ogre2FrustumVisual.cc b/ogre2/src/Ogre2FrustumVisual.cc index cae4dae21..8b93d3a49 100644 --- a/ogre2/src/Ogre2FrustumVisual.cc +++ b/ogre2/src/Ogre2FrustumVisual.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Open Source Robotics Foundation + * Copyright (C) 2025 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,8 +58,8 @@ class gz::rendering::Ogre2FrustumVisualPrivate public: std::vector> rayLines; /// \brief Frustum visual type - //public: FrustumVisualPlane frustumVisPlane = - //FrustumVisualPlane::FRUSTUM_PLANE_TOP; + // public: FrustumVisualPlane frustumVisPlane = + // FrustumVisualPlane::FRUSTUM_PLANE_TOP; /// \brief The visibility of the visual public: bool visible = true; @@ -68,7 +68,8 @@ class gz::rendering::Ogre2FrustumVisualPrivate public: std::array points; /// \brief each edge of the frustum. - public: std::array, 12> edges; + public: std::array, 12> edges; }; using namespace gz; @@ -148,10 +149,9 @@ void Ogre2FrustumVisual::Update() #if (OGRE_VERSION <= ((1 << 16) | (10 << 8) | 7)) MaterialPtr mat = this->Scene()->Material("Frustum/BlueRay"); #else - //MaterialPtr mat = this->Scene()->Material(rayLineMat); //FIX-ME MaterialPtr mat = this->Scene()->Material("Frustum/BlueRay"); #endif - + renderable->SetMaterial(mat, false); renderable->SetOperationType(MT_LINE_LIST); this->dataPtr->rayLines.push_back(renderable); @@ -172,9 +172,12 @@ void Ogre2FrustumVisual::Update() double farHeight = farWidth / this->aspectRatio; // Up, right, and forward unit vectors. - gz::math::Vector3d forward = this->pose.Rot().RotateVector(gz::math::Vector3d::UnitX); - gz::math::Vector3d up = this->pose.Rot().RotateVector(gz::math::Vector3d::UnitZ); - gz::math::Vector3d right = this->pose.Rot().RotateVector(-gz::math::Vector3d::UnitY); + gz::math::Vector3d forward = + this->pose.Rot().RotateVector(gz::math::Vector3d::UnitX); + gz::math::Vector3d up = + this->pose.Rot().RotateVector(gz::math::Vector3d::UnitZ); + gz::math::Vector3d right = + this->pose.Rot().RotateVector(-gz::math::Vector3d::UnitY); // Near plane center gz::math::Vector3d nearCenter = this->pose.Pos() + forward * this->near; @@ -189,10 +192,14 @@ void Ogre2FrustumVisual::Update() gz::math::Vector3d rightFarWidth2 = right * (farWidth * 0.5); // Compute the vertices of the near plane - gz::math::Vector3d nearTopLeft = nearCenter + upNearHeight2 - rightNearWidth2; - gz::math::Vector3d nearTopRight = nearCenter + upNearHeight2 + rightNearWidth2; - gz::math::Vector3d nearBottomLeft = nearCenter - upNearHeight2 - rightNearWidth2; - gz::math::Vector3d nearBottomRight = nearCenter - upNearHeight2 + rightNearWidth2; + gz::math::Vector3d nearTopLeft = + nearCenter + upNearHeight2 - rightNearWidth2; + gz::math::Vector3d nearTopRight = + nearCenter + upNearHeight2 + rightNearWidth2; + gz::math::Vector3d nearBottomLeft = + nearCenter - upNearHeight2 - rightNearWidth2; + gz::math::Vector3d nearBottomRight = + nearCenter - upNearHeight2 + rightNearWidth2; // Compute the vertices of the far plane gz::math::Vector3d farTopLeft = farCenter + upFarHeight2 - rightFarWidth2; @@ -265,23 +272,35 @@ void Ogre2FrustumVisual::Update() // Compute plane offsets // Set the planes, where the first value is the plane normal and the // second the plane offset - gz::math::Vector3d norm = gz::math::Vector3d::Normal(nearTopLeft, nearTopRight, nearBottomLeft); - this->planes[FrustumVisualPlane::FRUSTUM_PLANE_NEAR].Set(norm, nearCenter.Dot(norm)); - - norm = gz::math::Vector3d::Normal(farTopRight, farTopLeft, farBottomLeft); - this->planes[FrustumVisualPlane::FRUSTUM_PLANE_FAR].Set(norm, farCenter.Dot(norm)); - - norm = gz::math::Vector3d::Normal(farTopLeft, nearTopLeft, nearBottomLeft); - this->planes[FrustumVisualPlane::FRUSTUM_PLANE_LEFT].Set(norm, leftCenter.Dot(norm)); - - norm = gz::math::Vector3d::Normal(nearTopRight, farTopRight, farBottomRight); - this->planes[FrustumVisualPlane::FRUSTUM_PLANE_RIGHT].Set(norm, rightCenter.Dot(norm)); - - norm = gz::math::Vector3d::Normal(nearTopLeft, farTopLeft, nearTopRight); - this->planes[FrustumVisualPlane::FRUSTUM_PLANE_TOP].Set(norm, topCenter.Dot(norm)); - - norm = gz::math::Vector3d::Normal(nearBottomLeft, nearBottomRight, farBottomRight); - this->planes[FrustumVisualPlane::FRUSTUM_PLANE_BOTTOM].Set(norm, bottomCenter.Dot(norm)); + gz::math::Vector3d norm = gz::math::Vector3d::Normal( + nearTopLeft, nearTopRight, nearBottomLeft); + this->planes[FrustumVisualPlane::FRUSTUM_PLANE_NEAR].Set( + norm, nearCenter.Dot(norm)); + + norm = gz::math::Vector3d::Normal( + farTopRight, farTopLeft, farBottomLeft); + this->planes[FrustumVisualPlane::FRUSTUM_PLANE_FAR].Set( + norm, farCenter.Dot(norm)); + + norm = gz::math::Vector3d::Normal( + farTopLeft, nearTopLeft, nearBottomLeft); + this->planes[FrustumVisualPlane::FRUSTUM_PLANE_LEFT].Set( + norm, leftCenter.Dot(norm)); + + norm = gz::math::Vector3d::Normal( + nearTopRight, farTopRight, farBottomRight); + this->planes[FrustumVisualPlane::FRUSTUM_PLANE_RIGHT].Set( + norm, rightCenter.Dot(norm)); + + norm = gz::math::Vector3d::Normal( + nearTopLeft, farTopLeft, nearTopRight); + this->planes[FrustumVisualPlane::FRUSTUM_PLANE_TOP].Set( + norm, topCenter.Dot(norm)); + + norm = gz::math::Vector3d::Normal( + nearBottomLeft, nearBottomRight, farBottomRight); + this->planes[FrustumVisualPlane::FRUSTUM_PLANE_BOTTOM].Set( + norm, bottomCenter.Dot(norm)); renderable->Update(); this->SetVisible(this->dataPtr->visible); diff --git a/src/FrustumVisual.cc b/src/FrustumVisual.cc index 825f2851f..9c057dec2 100644 --- a/src/FrustumVisual.cc +++ b/src/FrustumVisual.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Open Source Robotics Foundation + * Copyright (C) 2025 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.