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

Commit

Permalink
Fix pointer color changes before controllers are loaded (#1357)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored and bluemarvin committed Jul 3, 2019
1 parent 5048229 commit 462d0de
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions app/src/main/cpp/ControllerContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ struct ControllerContainer::State {
std::vector<GroupPtr> 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) {
Expand All @@ -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<vrb::Geometry>(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
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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<vrb::Geometry>(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);
}
}

Expand Down

0 comments on commit 462d0de

Please sign in to comment.