From bc800236a20eb6c8b0203b306b7dfba418d025d3 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 19 May 2020 19:53:06 -0700 Subject: [PATCH 1/9] add ogre2 arrow and axis visual Signed-off-by: Ian Chen --- Changelog.md | 3 + examples/simple_demo/GlutWindow.cc | 8 +- examples/simple_demo/Main.cc | 26 ++++- .../rendering/ogre2/Ogre2ArrowVisual.hh | 45 ++++++++ .../rendering/ogre2/Ogre2AxisVisual.hh | 45 ++++++++ .../rendering/ogre2/Ogre2RenderTypes.hh | 4 + ogre2/src/Ogre2ArrowVisual.cc | 30 +++++ ogre2/src/Ogre2AxisVisual.cc | 30 +++++ ogre2/src/Ogre2Scene.cc | 20 ++-- src/ArrowVisual_TEST.cc | 98 ++++++++++++++++ src/AxisVisual_TEST.cc | 105 ++++++++++++++++++ tutorials/18_simple_demo_tutorial.md | 2 +- 12 files changed, 404 insertions(+), 12 deletions(-) create mode 100644 ogre2/include/ignition/rendering/ogre2/Ogre2ArrowVisual.hh create mode 100644 ogre2/include/ignition/rendering/ogre2/Ogre2AxisVisual.hh create mode 100644 ogre2/src/Ogre2ArrowVisual.cc create mode 100644 ogre2/src/Ogre2AxisVisual.cc create mode 100644 src/ArrowVisual_TEST.cc create mode 100644 src/AxisVisual_TEST.cc diff --git a/Changelog.md b/Changelog.md index 877712471..4823c145c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,9 @@ ### Ignition Rendering 4.0.0 +1. Add ogre2 implementation of AxisVisual and ArrowVisual + * [Pull request ]() + 1. Support setting skeleton node weights * [BitBucket pull request 256](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-rendering/pull-requests/256) diff --git a/examples/simple_demo/GlutWindow.cc b/examples/simple_demo/GlutWindow.cc index a30df8c34..93caf3816 100644 --- a/examples/simple_demo/GlutWindow.cc +++ b/examples/simple_demo/GlutWindow.cc @@ -71,13 +71,17 @@ double g_offset = 0.0; ////////////////////////////////////////////////// //! [update camera] void updateCameras() + { + double angle = g_offset / 2 * M_PI; + double x = sin(angle) * 3.0 + 3.0; + double y = cos(angle) * 3.0; for (ir::CameraPtr camera : g_cameras) { - camera->SetLocalPosition(g_offset, g_offset, g_offset); + camera->SetLocalPosition(x, y, 0.0); } - g_offset+= 0.001; + g_offset += 0.0005; } //! [update camera] diff --git a/examples/simple_demo/Main.cc b/examples/simple_demo/Main.cc index 09358186e..1867d3f71 100644 --- a/examples/simple_demo/Main.cc +++ b/examples/simple_demo/Main.cc @@ -131,6 +131,19 @@ void buildScene(ScenePtr _scene) plane->SetMaterial(white); root->AddChild(plane); + // create axis visual + VisualPtr axis = _scene->CreateAxisVisual(); + axis->SetLocalPosition(4.0, 0.5, -0.4); + root->AddChild(axis); + + // create arrow visual + // VisualPtr arrow = _scene->CreateArrowVisual(); + // arrow->SetLocalPosition(2, -1, -0.3); + // arrow->SetLocalScale(2, -1, 2); + // arrow->SetLocalRotation(-IGN_PI / 3, -IGN_PI / 3, 0); + // arrow->SetMaterial(green); + // root->AddChild(arrow); + // create camera CameraPtr camera = _scene->CreateCamera("camera"); camera->SetLocalPosition(0.0, 0.0, 0.0); @@ -141,6 +154,8 @@ void buildScene(ScenePtr _scene) camera->SetAspectRatio(1.333); camera->SetHFOV(IGN_PI / 2); root->AddChild(camera); + + camera->SetTrackTarget(box); } ////////////////////////////////////////////////// @@ -167,12 +182,21 @@ int main(int _argc, char** _argv) { glutInit(&_argc, _argv); + // Expose engine name to command line because we can't instantiate both + // ogre and ogre2 at the same time + std::string engine("ogre"); + if (_argc > 1) + { + engine = _argv[1]; + } + common::Console::SetVerbosity(4); std::vector engineNames; std::vector cameras; - engineNames.push_back("ogre"); + engineNames.push_back(engine); engineNames.push_back("optix"); + for (auto engineName : engineNames) { try diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2ArrowVisual.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2ArrowVisual.hh new file mode 100644 index 000000000..60dbd73c0 --- /dev/null +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2ArrowVisual.hh @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef IGNITION_RENDERING_OGRE2_OGRE2ARROWVISUAL_HH_ +#define IGNITION_RENDERING_OGRE2_OGRE2ARROWVISUAL_HH_ + +#include "ignition/rendering/base/BaseArrowVisual.hh" +#include "ignition/rendering/ogre2/Ogre2Visual.hh" + +namespace ignition +{ + namespace rendering + { + inline namespace IGNITION_RENDERING_VERSION_NAMESPACE { + // + /// \brief Ogre2.x implementation of the arrow visual class + class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2ArrowVisual : + public BaseArrowVisual + { + /// \brief Constructor + protected: Ogre2ArrowVisual(); + + /// \brief Destructor + public: virtual ~Ogre2ArrowVisual(); + + /// \brief Only scene can instantiate an arrow visual + private: friend class Ogre2Scene; + }; + } + } +} +#endif diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2AxisVisual.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2AxisVisual.hh new file mode 100644 index 000000000..e76bde5b8 --- /dev/null +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2AxisVisual.hh @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef IGNITION_RENDERING_OGRE2_OGRE2AXISVISUAL_HH_ +#define IGNITION_RENDERING_OGRE2_OGRE2AXISVISUAL_HH_ + +#include "ignition/rendering/base/BaseAxisVisual.hh" +#include "ignition/rendering/ogre2/Ogre2Visual.hh" + +namespace ignition +{ + namespace rendering + { + inline namespace IGNITION_RENDERING_VERSION_NAMESPACE { + // + /// \brief Ogre2.x implementation of the axis visual class + class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2AxisVisual : + public BaseAxisVisual + { + /// \brief Constructor + protected: Ogre2AxisVisual(); + + /// \brief Destructor + public: virtual ~Ogre2AxisVisual(); + + /// \brief Only scene can instantiate an axis visual + private: friend class Ogre2Scene; + }; + } + } +} +#endif diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh index 30588baf4..91b94d326 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh @@ -28,6 +28,8 @@ namespace ignition { inline namespace IGNITION_RENDERING_VERSION_NAMESPACE { // + class Ogre2ArrowVisual; + class Ogre2AxisVisual; class Ogre2Camera; class Ogre2DepthCamera; class Ogre2DirectionalLight; @@ -67,6 +69,8 @@ namespace ignition typedef BaseMaterialMap Ogre2MaterialMap; + typedef shared_ptr Ogre2ArrowVisualPtr; + typedef shared_ptr Ogre2AxisVisualPtr; typedef shared_ptr Ogre2CameraPtr; typedef shared_ptr Ogre2DepthCameraPtr; typedef shared_ptr Ogre2DirectionalLightPtr; diff --git a/ogre2/src/Ogre2ArrowVisual.cc b/ogre2/src/Ogre2ArrowVisual.cc new file mode 100644 index 000000000..1b5eb9e52 --- /dev/null +++ b/ogre2/src/Ogre2ArrowVisual.cc @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "ignition/rendering/ogre2/Ogre2ArrowVisual.hh" + +using namespace ignition; +using namespace rendering; + +////////////////////////////////////////////////// +Ogre2ArrowVisual::Ogre2ArrowVisual() +{ +} + +////////////////////////////////////////////////// +Ogre2ArrowVisual::~Ogre2ArrowVisual() +{ +} diff --git a/ogre2/src/Ogre2AxisVisual.cc b/ogre2/src/Ogre2AxisVisual.cc new file mode 100644 index 000000000..d78d66879 --- /dev/null +++ b/ogre2/src/Ogre2AxisVisual.cc @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "ignition/rendering/ogre2/Ogre2AxisVisual.hh" + +using namespace ignition; +using namespace rendering; + +////////////////////////////////////////////////// +Ogre2AxisVisual::Ogre2AxisVisual() +{ +} + +////////////////////////////////////////////////// +Ogre2AxisVisual::~Ogre2AxisVisual() +{ +} diff --git a/ogre2/src/Ogre2Scene.cc b/ogre2/src/Ogre2Scene.cc index b62ce8678..eb4347281 100644 --- a/ogre2/src/Ogre2Scene.cc +++ b/ogre2/src/Ogre2Scene.cc @@ -18,6 +18,8 @@ #include #include "ignition/rendering/RenderTypes.hh" +#include "ignition/rendering/ogre2/Ogre2ArrowVisual.hh" +#include "ignition/rendering/ogre2/Ogre2AxisVisual.hh" #include "ignition/rendering/ogre2/Ogre2Camera.hh" #include "ignition/rendering/ogre2/Ogre2Conversions.hh" #include "ignition/rendering/ogre2/Ogre2DepthCamera.hh" @@ -279,19 +281,21 @@ VisualPtr Ogre2Scene::CreateVisualImpl(unsigned int _id, } ////////////////////////////////////////////////// -ArrowVisualPtr Ogre2Scene::CreateArrowVisualImpl(unsigned int /*_id*/, - const std::string &/*_name*/) +ArrowVisualPtr Ogre2Scene::CreateArrowVisualImpl(unsigned int _id, + const std::string &_name) { - // TODO(anyone) - return ArrowVisualPtr(); + Ogre2ArrowVisualPtr visual(new Ogre2ArrowVisual); + bool result = this->InitObject(visual, _id, _name); + return (result) ? visual : nullptr; } ////////////////////////////////////////////////// -AxisVisualPtr Ogre2Scene::CreateAxisVisualImpl(unsigned int /*_id*/, - const std::string &/*_name*/) +AxisVisualPtr Ogre2Scene::CreateAxisVisualImpl(unsigned int _id, + const std::string &_name) { - // TODO(anyone) - return AxisVisualPtr(); + Ogre2AxisVisualPtr visual(new Ogre2AxisVisual); + bool result = this->InitObject(visual, _id, _name); + return (result) ? visual : nullptr; } ////////////////////////////////////////////////// diff --git a/src/ArrowVisual_TEST.cc b/src/ArrowVisual_TEST.cc new file mode 100644 index 000000000..b98b70ed8 --- /dev/null +++ b/src/ArrowVisual_TEST.cc @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +#include +#include + +#include + +#include "test_config.h" // NOLINT(build/include) + +#include "ignition/rendering/ArrowVisual.hh" +#include "ignition/rendering/RenderEngine.hh" +#include "ignition/rendering/RenderingIface.hh" +#include "ignition/rendering/Scene.hh" +#include "ignition/rendering/Visual.hh" + +using namespace ignition; +using namespace rendering; + +class ArrowVisualTest : public testing::Test, + public testing::WithParamInterface +{ + /// \brief Test adding removing children + public: void ArrowVisual(const std::string &_renderEngine); +}; + +///////////////////////////////////////////////// +void ArrowVisualTest::ArrowVisual(const std::string &_renderEngine) +{ + RenderEngine *engine = rendering::engine(_renderEngine); + if (!engine) + { + igndbg << "Engine '" << _renderEngine + << "' is not supported" << std::endl; + return; + } + + ScenePtr scene = engine->CreateScene("scene"); + + // create arrow visual + ArrowVisualPtr visual = scene->CreateArrowVisual(); + ASSERT_NE(nullptr, visual); + + // check scale + EXPECT_TRUE(visual->InheritScale()); + EXPECT_EQ(math::Vector3d::One, visual->LocalScale()); + EXPECT_EQ(math::Vector3d::One, visual->WorldScale()); + + visual->SetLocalScale(0.2, 0.3, 0.4); + EXPECT_EQ(math::Vector3d(0.2, 0.3, 0.4), visual->LocalScale()); + + // check children and geometry + EXPECT_EQ(2u, visual->ChildCount()); + + NodePtr node = visual->ChildByIndex(0u); + VisualPtr child = std::dynamic_pointer_cast(node); + ASSERT_NE(nullptr, child); + EXPECT_EQ(1u, child->GeometryCount()); + + node = visual->ChildByIndex(1u); + child = std::dynamic_pointer_cast(node); + ASSERT_NE(nullptr, child); + EXPECT_EQ(1u, child->GeometryCount()); + + // Clean up + engine->DestroyScene(scene); + rendering::unloadEngine(engine->Name()); +} + +///////////////////////////////////////////////// +TEST_P(ArrowVisualTest, ArrowVisual) +{ + ArrowVisual(GetParam()); +} + +INSTANTIATE_TEST_CASE_P(ArrowVisual, ArrowVisualTest, + RENDER_ENGINE_VALUES, + ignition::rendering::PrintToStringParam()); + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/src/AxisVisual_TEST.cc b/src/AxisVisual_TEST.cc new file mode 100644 index 000000000..5e89e5dd3 --- /dev/null +++ b/src/AxisVisual_TEST.cc @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +#include +#include + +#include + +#include "test_config.h" // NOLINT(build/include) + +#include "ignition/rendering/ArrowVisual.hh" +#include "ignition/rendering/AxisVisual.hh" +#include "ignition/rendering/RenderEngine.hh" +#include "ignition/rendering/RenderingIface.hh" +#include "ignition/rendering/Scene.hh" +#include "ignition/rendering/Visual.hh" + +using namespace ignition; +using namespace rendering; + +class AxisVisualTest : public testing::Test, + public testing::WithParamInterface +{ + /// \brief Test adding removing children + public: void AxisVisual(const std::string &_renderEngine); +}; + +///////////////////////////////////////////////// +void AxisVisualTest::AxisVisual(const std::string &_renderEngine) +{ + RenderEngine *engine = rendering::engine(_renderEngine); + if (!engine) + { + igndbg << "Engine '" << _renderEngine + << "' is not supported" << std::endl; + return; + } + + ScenePtr scene = engine->CreateScene("scene"); + + // create axis visual + AxisVisualPtr visual = scene->CreateAxisVisual(); + ASSERT_NE(nullptr, visual); + + // check scale + EXPECT_TRUE(visual->InheritScale()); + EXPECT_EQ(math::Vector3d::One, visual->LocalScale()); + EXPECT_EQ(math::Vector3d::One, visual->WorldScale()); + + visual->SetLocalScale(0.2, 0.3, 0.4); + EXPECT_EQ(math::Vector3d(0.2, 0.3, 0.4), visual->LocalScale()); + + // check children and geometry + EXPECT_EQ(3u, visual->ChildCount()); + + for (unsigned int i = 0; i < 3u; ++i) + { + NodePtr node = visual->ChildByIndex(i); + ArrowVisualPtr arrow = std::dynamic_pointer_cast(node); + ASSERT_NE(nullptr, arrow); + + EXPECT_EQ(2u, arrow->ChildCount()); + NodePtr childNode = arrow->ChildByIndex(0u); + VisualPtr child = std::dynamic_pointer_cast(childNode); + EXPECT_EQ(1u, child->GeometryCount()); + + childNode = arrow->ChildByIndex(1u); + child = std::dynamic_pointer_cast(childNode); + EXPECT_EQ(1u, child->GeometryCount()); + } + + // Clean up + engine->DestroyScene(scene); + rendering::unloadEngine(engine->Name()); +} + +///////////////////////////////////////////////// +TEST_P(AxisVisualTest, AxisVisual) +{ + AxisVisual(GetParam()); +} + +INSTANTIATE_TEST_CASE_P(AxisVisual, AxisVisualTest, + RENDER_ENGINE_VALUES, + ignition::rendering::PrintToStringParam()); + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tutorials/18_simple_demo_tutorial.md b/tutorials/18_simple_demo_tutorial.md index 054b7404e..8cc448f25 100644 --- a/tutorials/18_simple_demo_tutorial.md +++ b/tutorials/18_simple_demo_tutorial.md @@ -29,6 +29,6 @@ Engine 'optix' is not supported ## Code -The function `updateCameras()` is called each time the `DisplayCB` function runs. Using the method `SetLocalPosition` from the `Camera` class we can locate the camera in the world: +The function `updateCameras()` is called each time the `DisplayCB` function runs. Using the method `SetLocalPosition` from the `Camera` class we can move the camera in the world: \snippet examples/simple_demo/GlutWindow.cc update camera From 2a7c5543fad1d13a58f27fe6da18a269ed3a59cb Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 19 May 2020 20:04:17 -0700 Subject: [PATCH 2/9] changelog and remove unused code Signed-off-by: Ian Chen --- Changelog.md | 4 ++-- examples/simple_demo/Main.cc | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Changelog.md b/Changelog.md index 4823c145c..7f0d20787 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,8 +6,8 @@ ### Ignition Rendering 4.0.0 -1. Add ogre2 implementation of AxisVisual and ArrowVisual - * [Pull request ]() +1. Add ogre2 AxisVisual and ArrowVisual + * [Pull request ](https://github.com/ignitionrobotics/ign-rendering/pull/87) 1. Support setting skeleton node weights * [BitBucket pull request 256](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-rendering/pull-requests/256) diff --git a/examples/simple_demo/Main.cc b/examples/simple_demo/Main.cc index 1867d3f71..36f09cf4c 100644 --- a/examples/simple_demo/Main.cc +++ b/examples/simple_demo/Main.cc @@ -136,14 +136,6 @@ void buildScene(ScenePtr _scene) axis->SetLocalPosition(4.0, 0.5, -0.4); root->AddChild(axis); - // create arrow visual - // VisualPtr arrow = _scene->CreateArrowVisual(); - // arrow->SetLocalPosition(2, -1, -0.3); - // arrow->SetLocalScale(2, -1, 2); - // arrow->SetLocalRotation(-IGN_PI / 3, -IGN_PI / 3, 0); - // arrow->SetMaterial(green); - // root->AddChild(arrow); - // create camera CameraPtr camera = _scene->CreateCamera("camera"); camera->SetLocalPosition(0.0, 0.0, 0.0); @@ -155,6 +147,7 @@ void buildScene(ScenePtr _scene) camera->SetHFOV(IGN_PI / 2); root->AddChild(camera); + // track target camera->SetTrackTarget(box); } From ff5d5dde9b29e2f2f7b7b372c325082c8a310d03 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Wed, 20 May 2020 16:53:46 -0700 Subject: [PATCH 3/9] changelog Signed-off-by: Ian Chen --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 7f0d20787..cfb4b7417 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,7 +7,7 @@ ### Ignition Rendering 4.0.0 1. Add ogre2 AxisVisual and ArrowVisual - * [Pull request ](https://github.com/ignitionrobotics/ign-rendering/pull/87) + * [Pull request 87](https://github.com/ignitionrobotics/ign-rendering/pull/87) 1. Support setting skeleton node weights * [BitBucket pull request 256](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-rendering/pull-requests/256) From bb91a44b008cabb6f2a7339f6941c720ac4acb5f Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 22 May 2020 12:10:01 +0200 Subject: [PATCH 4/9] Scale BaseAxis properly Signed-off-by: ahcorde --- .../ignition/rendering/base/BaseAxisVisual.hh | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/include/ignition/rendering/base/BaseAxisVisual.hh b/include/ignition/rendering/base/BaseAxisVisual.hh index 486971236..0223a8fdf 100644 --- a/include/ignition/rendering/base/BaseAxisVisual.hh +++ b/include/ignition/rendering/base/BaseAxisVisual.hh @@ -37,6 +37,18 @@ namespace ignition public: virtual ~BaseAxisVisual(); public: virtual void Init(); + + public: virtual void SetLocalScale(double _x, double _y, double _z) override; + + public: virtual void SetLocalScale(double _scale) override; + + public: virtual void SetLocalScale(const math::Vector3d &_scale) override; + + private: ArrowVisualPtr xArrow; + + private: ArrowVisualPtr yArrow; + + private: ArrowVisualPtr zArrow; }; ////////////////////////////////////////////////// @@ -51,25 +63,52 @@ namespace ignition { } + ////////////////////////////////////////////////// + template + void BaseAxisVisual::SetLocalScale(double _x, double _y, double _z) + { + xArrow->SetLocalScale(_x, _y, _z); + yArrow->SetLocalScale(_x, _y, _z); + zArrow->SetLocalScale(_x, _y, _z); + } + + ////////////////////////////////////////////////// + template + void BaseAxisVisual::SetLocalScale(double _scale) + { + xArrow->SetLocalScale(_scale, _scale, _scale); + yArrow->SetLocalScale(_scale, _scale, _scale); + zArrow->SetLocalScale(_scale, _scale, _scale); + } + + ////////////////////////////////////////////////// + template + void BaseAxisVisual::SetLocalScale(const math::Vector3d &_scale) + { + xArrow->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z()); + yArrow->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z()); + zArrow->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z()); + } + ////////////////////////////////////////////////// template void BaseAxisVisual::Init() { T::Init(); - ArrowVisualPtr xArrow = this->Scene()->CreateArrowVisual(); + xArrow = this->Scene()->CreateArrowVisual(); xArrow->SetLocalPosition(0, 0, 0); xArrow->SetLocalRotation(0, IGN_PI / 2, 0); xArrow->SetMaterial("Default/TransRed"); this->AddChild(xArrow); - ArrowVisualPtr yArrow = this->Scene()->CreateArrowVisual(); + yArrow = this->Scene()->CreateArrowVisual(); yArrow->SetLocalPosition(0, 0, 0); yArrow->SetLocalRotation(-IGN_PI / 2, 0, 0); yArrow->SetMaterial("Default/TransGreen"); this->AddChild(yArrow); - ArrowVisualPtr zArrow = this->Scene()->CreateArrowVisual(); + zArrow = this->Scene()->CreateArrowVisual(); zArrow->SetLocalPosition(0, 0, 0); zArrow->SetLocalRotation(0, 0, 0); zArrow->SetMaterial("Default/TransBlue"); From 20472558be964c56cea21c6d002f26bfffbc49d8 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 25 May 2020 09:03:48 +0200 Subject: [PATCH 5/9] Overwrite only SetLocalScale math::Vector3d in BaseAxisVisual and removed private declaration of arrows Signed-off-by: ahcorde --- .../ignition/rendering/base/BaseAxisVisual.hh | 39 +++---------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/include/ignition/rendering/base/BaseAxisVisual.hh b/include/ignition/rendering/base/BaseAxisVisual.hh index 0223a8fdf..e3941b226 100644 --- a/include/ignition/rendering/base/BaseAxisVisual.hh +++ b/include/ignition/rendering/base/BaseAxisVisual.hh @@ -38,17 +38,7 @@ namespace ignition public: virtual void Init(); - public: virtual void SetLocalScale(double _x, double _y, double _z) override; - - public: virtual void SetLocalScale(double _scale) override; - public: virtual void SetLocalScale(const math::Vector3d &_scale) override; - - private: ArrowVisualPtr xArrow; - - private: ArrowVisualPtr yArrow; - - private: ArrowVisualPtr zArrow; }; ////////////////////////////////////////////////// @@ -63,31 +53,12 @@ namespace ignition { } - ////////////////////////////////////////////////// - template - void BaseAxisVisual::SetLocalScale(double _x, double _y, double _z) - { - xArrow->SetLocalScale(_x, _y, _z); - yArrow->SetLocalScale(_x, _y, _z); - zArrow->SetLocalScale(_x, _y, _z); - } - - ////////////////////////////////////////////////// - template - void BaseAxisVisual::SetLocalScale(double _scale) - { - xArrow->SetLocalScale(_scale, _scale, _scale); - yArrow->SetLocalScale(_scale, _scale, _scale); - zArrow->SetLocalScale(_scale, _scale, _scale); - } - ////////////////////////////////////////////////// template void BaseAxisVisual::SetLocalScale(const math::Vector3d &_scale) { - xArrow->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z()); - yArrow->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z()); - zArrow->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z()); + for (unsigned int i = 0; i < this->ChildCount(); ++i) + this->ChildByIndex(i)->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z()); } ////////////////////////////////////////////////// @@ -96,19 +67,19 @@ namespace ignition { T::Init(); - xArrow = this->Scene()->CreateArrowVisual(); + ArrowVisualPtr xArrow = this->Scene()->CreateArrowVisual(); xArrow->SetLocalPosition(0, 0, 0); xArrow->SetLocalRotation(0, IGN_PI / 2, 0); xArrow->SetMaterial("Default/TransRed"); this->AddChild(xArrow); - yArrow = this->Scene()->CreateArrowVisual(); + ArrowVisualPtr yArrow = this->Scene()->CreateArrowVisual(); yArrow->SetLocalPosition(0, 0, 0); yArrow->SetLocalRotation(-IGN_PI / 2, 0, 0); yArrow->SetMaterial("Default/TransGreen"); this->AddChild(yArrow); - zArrow = this->Scene()->CreateArrowVisual(); + ArrowVisualPtr zArrow = this->Scene()->CreateArrowVisual(); zArrow->SetLocalPosition(0, 0, 0); zArrow->SetLocalRotation(0, 0, 0); zArrow->SetMaterial("Default/TransBlue"); From 71f4e44e81e6e44f6efa941aefe0a579e88e67b4 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 26 May 2020 11:00:23 -0700 Subject: [PATCH 6/9] changelog Signed-off-by: Ian Chen --- Changelog.md | 3 +++ include/ignition/rendering/base/BaseAxisVisual.hh | 1 + 2 files changed, 4 insertions(+) diff --git a/Changelog.md b/Changelog.md index 877712471..6b36a51fb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,9 @@ ### Ignition Rendering 4.0.0 +1. Scale BaseAxis properly + * [Pull request #88](https://github.com/ignitionrobotics/ign-rendering/pull/88) + 1. Support setting skeleton node weights * [BitBucket pull request 256](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-rendering/pull-requests/256) diff --git a/include/ignition/rendering/base/BaseAxisVisual.hh b/include/ignition/rendering/base/BaseAxisVisual.hh index e3941b226..66d410f70 100644 --- a/include/ignition/rendering/base/BaseAxisVisual.hh +++ b/include/ignition/rendering/base/BaseAxisVisual.hh @@ -38,6 +38,7 @@ namespace ignition public: virtual void Init(); + // Documentation inherited. public: virtual void SetLocalScale(const math::Vector3d &_scale) override; }; From 605242c2df8c49b924f7d4e18bfd70fcfac94c63 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 28 May 2020 15:26:41 +0200 Subject: [PATCH 7/9] Fixed UNIT_VisualAxis_TEST Signed-off-by: ahcorde --- include/ignition/rendering/base/BaseAxisVisual.hh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/ignition/rendering/base/BaseAxisVisual.hh b/include/ignition/rendering/base/BaseAxisVisual.hh index 66d410f70..5b8064b36 100644 --- a/include/ignition/rendering/base/BaseAxisVisual.hh +++ b/include/ignition/rendering/base/BaseAxisVisual.hh @@ -40,6 +40,10 @@ namespace ignition // Documentation inherited. public: virtual void SetLocalScale(const math::Vector3d &_scale) override; + + // Documentation inherited. + public: virtual math::Vector3d LocalScale() const override; + }; ////////////////////////////////////////////////// @@ -54,6 +58,16 @@ namespace ignition { } + ////////////////////////////////////////////////// + template + math::Vector3d BaseAxisVisual::LocalScale() const + { + if(this->ChildCount() > 0) { + return this->ChildByIndex(0)->LocalScale(); + } + return math::Vector3d::Zero; + } + ////////////////////////////////////////////////// template void BaseAxisVisual::SetLocalScale(const math::Vector3d &_scale) From 27a228ba07e2547992b49334bff759f9975d124f Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 28 May 2020 15:39:17 +0200 Subject: [PATCH 8/9] Fixed linters Signed-off-by: ahcorde --- include/ignition/rendering/base/BaseAxisVisual.hh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/ignition/rendering/base/BaseAxisVisual.hh b/include/ignition/rendering/base/BaseAxisVisual.hh index 5b8064b36..5c2b25edf 100644 --- a/include/ignition/rendering/base/BaseAxisVisual.hh +++ b/include/ignition/rendering/base/BaseAxisVisual.hh @@ -39,11 +39,11 @@ namespace ignition public: virtual void Init(); // Documentation inherited. - public: virtual void SetLocalScale(const math::Vector3d &_scale) override; + public: virtual void SetLocalScale( + const math::Vector3d &_scale) override; // Documentation inherited. public: virtual math::Vector3d LocalScale() const override; - }; ////////////////////////////////////////////////// @@ -62,7 +62,7 @@ namespace ignition template math::Vector3d BaseAxisVisual::LocalScale() const { - if(this->ChildCount() > 0) { + if (this->ChildCount() > 0) { return this->ChildByIndex(0)->LocalScale(); } return math::Vector3d::Zero; @@ -73,7 +73,9 @@ namespace ignition void BaseAxisVisual::SetLocalScale(const math::Vector3d &_scale) { for (unsigned int i = 0; i < this->ChildCount(); ++i) - this->ChildByIndex(i)->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z()); + this->ChildByIndex(i)->SetLocalScale(_scale.X(), + _scale.Y(), + _scale.Z()); } ////////////////////////////////////////////////// From ca745c938397d075b915686414fa9e85f82cfae2 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 28 May 2020 18:48:42 +0200 Subject: [PATCH 9/9] Remove compiler warning in BaseAxisVisual Signed-off-by: ahcorde --- include/ignition/rendering/base/BaseAxisVisual.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ignition/rendering/base/BaseAxisVisual.hh b/include/ignition/rendering/base/BaseAxisVisual.hh index 5c2b25edf..c91ecedfd 100644 --- a/include/ignition/rendering/base/BaseAxisVisual.hh +++ b/include/ignition/rendering/base/BaseAxisVisual.hh @@ -36,7 +36,7 @@ namespace ignition public: virtual ~BaseAxisVisual(); - public: virtual void Init(); + public: virtual void Init() override; // Documentation inherited. public: virtual void SetLocalScale(