Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 462d0de

Browse files
MortimerGorobluemarvin
authored andcommitted
Fix pointer color changes before controllers are loaded (#1357)
1 parent 5048229 commit 462d0de

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

‎app/src/main/cpp/ControllerContainer.cpp‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ struct ControllerContainer::State {
3131
std::vector<GroupPtr> models;
3232
GeometryPtr beamModel;
3333
bool visible = false;
34+
vrb::Color pointerColor;
3435

3536
void Initialize(vrb::CreationContextPtr& aContext) {
3637
context = aContext;
3738
root = Toggle::Create(aContext);
3839
visible = true;
40+
pointerColor = vrb::Color(1.0f, 1.0f, 1.0f, 1.0f);
3941
}
4042

4143
bool Contains(const int32_t aControllerIndex) {
@@ -51,6 +53,18 @@ struct ControllerContainer::State {
5153
models[aModelIndex] = std::move(Group::Create(create));
5254
}
5355
}
56+
57+
void updatePointerColor(Controller& aController) {
58+
if (aController.beamParent) {
59+
GeometryPtr geometry = std::dynamic_pointer_cast<vrb::Geometry>(aController.beamParent->GetNode(0));
60+
if (geometry) {
61+
geometry->GetRenderState()->SetMaterial(pointerColor, pointerColor, vrb::Color(0.0f, 0.0f, 0.0f), 0.0f);
62+
}
63+
}
64+
if (aController.pointer) {
65+
aController.pointer->SetPointerColor(pointerColor);
66+
}
67+
}
5468
};
5569

5670
ControllerContainerPtr
@@ -205,6 +219,7 @@ ControllerContainer::CreateController(const int32_t aControllerIndex, const int3
205219
if (m.pointerContainer) {
206220
m.pointerContainer->AddNode(controller.pointer->GetRoot());
207221
}
222+
m.updatePointerColor(controller);
208223
} else {
209224
VRB_ERROR("Failed to add controller model");
210225
}
@@ -365,16 +380,9 @@ ControllerContainer::SetScrolledDelta(const int32_t aControllerIndex, const floa
365380
}
366381

367382
void ControllerContainer::SetPointerColor(const vrb::Color& aColor) const {
383+
m.pointerColor = aColor;
368384
for (Controller& controller: m.list) {
369-
if (controller.beamParent) {
370-
GeometryPtr geometry = std::dynamic_pointer_cast<vrb::Geometry>(controller.beamParent->GetNode(0));
371-
if (geometry) {
372-
geometry->GetRenderState()->SetMaterial(aColor, aColor, vrb::Color(0.0f, 0.0f, 0.0f), 0.0f);
373-
}
374-
}
375-
if (controller.pointer) {
376-
controller.pointer->SetPointerColor(aColor);
377-
}
385+
m.updatePointerColor(controller);
378386
}
379387
}
380388

0 commit comments

Comments
 (0)