From 462d0de6b5ed207b1b987ed93cc1c7f1b3b0d694 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Thu, 4 Jul 2019 01:15:32 +0200 Subject: [PATCH] Fix pointer color changes before controllers are loaded (#1357) --- app/src/main/cpp/ControllerContainer.cpp | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/src/main/cpp/ControllerContainer.cpp b/app/src/main/cpp/ControllerContainer.cpp index 4fa508ed8..a2cd17355 100644 --- a/app/src/main/cpp/ControllerContainer.cpp +++ b/app/src/main/cpp/ControllerContainer.cpp @@ -31,11 +31,13 @@ struct ControllerContainer::State { std::vector models; GeometryPtr beamModel; bool visible = false; + vrb::Color pointerColor; void Initialize(vrb::CreationContextPtr& aContext) { context = aContext; root = Toggle::Create(aContext); visible = true; + pointerColor = vrb::Color(1.0f, 1.0f, 1.0f, 1.0f); } bool Contains(const int32_t aControllerIndex) { @@ -51,6 +53,18 @@ struct ControllerContainer::State { models[aModelIndex] = std::move(Group::Create(create)); } } + + void updatePointerColor(Controller& aController) { + if (aController.beamParent) { + GeometryPtr geometry = std::dynamic_pointer_cast(aController.beamParent->GetNode(0)); + if (geometry) { + geometry->GetRenderState()->SetMaterial(pointerColor, pointerColor, vrb::Color(0.0f, 0.0f, 0.0f), 0.0f); + } + } + if (aController.pointer) { + aController.pointer->SetPointerColor(pointerColor); + } + } }; ControllerContainerPtr @@ -205,6 +219,7 @@ ControllerContainer::CreateController(const int32_t aControllerIndex, const int3 if (m.pointerContainer) { m.pointerContainer->AddNode(controller.pointer->GetRoot()); } + m.updatePointerColor(controller); } else { VRB_ERROR("Failed to add controller model"); } @@ -365,16 +380,9 @@ ControllerContainer::SetScrolledDelta(const int32_t aControllerIndex, const floa } void ControllerContainer::SetPointerColor(const vrb::Color& aColor) const { + m.pointerColor = aColor; for (Controller& controller: m.list) { - if (controller.beamParent) { - GeometryPtr geometry = std::dynamic_pointer_cast(controller.beamParent->GetNode(0)); - if (geometry) { - geometry->GetRenderState()->SetMaterial(aColor, aColor, vrb::Color(0.0f, 0.0f, 0.0f), 0.0f); - } - } - if (controller.pointer) { - controller.pointer->SetPointerColor(aColor); - } + m.updatePointerColor(controller); } }