NavLights::NavLights(SceneGraph::Model *model, float period) : m_time(0.f) , m_period(period) , m_enabled(false) { assert(g_initted); Graphics::Renderer *renderer = model->GetRenderer(); using SceneGraph::Node; using SceneGraph::MatrixTransform; using SceneGraph::Billboard; //This will find all matrix transforms meant for navlights. SceneGraph::FindNodeVisitor lightFinder(SceneGraph::FindNodeVisitor::MATCH_NAME_STARTSWITH, "navlight_"); model->GetRoot()->Accept(lightFinder); const std::vector<Node*> &results = lightFinder.GetResults(); //attach light billboards for (unsigned int i=0; i < results.size(); i++) { MatrixTransform *mt = dynamic_cast<MatrixTransform*>(results.at(i)); assert(mt); Billboard *bblight = new Billboard(renderer, matBlue, vector3f(0.f), BILLBOARD_SIZE); Uint32 group = 0; Uint8 mask = 0xff; //always on Uint8 color = NAVLIGHT_BLUE; if (mt->GetName().substr(9, 3) == "red") { bblight->SetMaterial(matRed); mask = 0x0f; color = NAVLIGHT_RED; } else if (mt->GetName().substr(9, 5) == "green") { mask = 0xf0; color = NAVLIGHT_GREEN; } else if (mt->GetName().substr(9, 3) == "pad") { //group by pad number // due to this problem: http://stackoverflow.com/questions/15825254/why-is-scanfhhu-char-overwriting-other-variables-when-they-are-local // where MSVC is still using a C89 compiler the format identifer %hhu is not recognised. Therefore I've switched to Uint32 for group. PiVerify(1 == sscanf(mt->GetName().c_str(), "navlight_pad%u", &group)); mask = 0xf0; } bblight->SetMaterial(get_material(color)); m_lights.push_back(LightBulb(group, mask, color, bblight)); mt->SetNodeMask(SceneGraph::NODE_TRANSPARENT); mt->AddChild(bblight); } }
NavLights::NavLights(SceneGraph::Model *model, float period) : m_time(0.f) , m_period(period) , m_enabled(false) { assert(g_initted); Graphics::Renderer *renderer = model->GetRenderer(); using SceneGraph::Node; using SceneGraph::MatrixTransform; using SceneGraph::Billboard; //This will find all matrix transforms meant for navlights. SceneGraph::FindNodeVisitor lightFinder(SceneGraph::FindNodeVisitor::MATCH_NAME_STARTSWITH, "navlight_"); model->GetRoot()->Accept(lightFinder); const std::vector<Node*> &results = lightFinder.GetResults(); //attach light billboards for (unsigned int i=0; i < results.size(); i++) { MatrixTransform *mt = dynamic_cast<MatrixTransform*>(results.at(i)); assert(mt); Billboard *bblight = new Billboard(renderer, matBlue, vector3f(0.f), BILLBOARD_SIZE); Uint8 group = 0; Uint8 mask = 0xff; //always on Uint8 color = NAVLIGHT_BLUE; if (mt->GetName().substr(9, 3) == "red") { bblight->SetMaterial(matRed); mask = 0x0f; color = NAVLIGHT_RED; } else if (mt->GetName().substr(9, 5) == "green") { mask = 0xf0; color = NAVLIGHT_GREEN; } else if (mt->GetName().substr(9, 3) == "pad") { //group by pad number group = atoi(mt->GetName().substr(12, 1).c_str()); mask = 0xf0; } bblight->SetMaterial(get_material(color)); m_lights.push_back(LightBulb(group, mask, color, bblight)); mt->SetNodeMask(SceneGraph::NODE_TRANSPARENT); mt->AddChild(bblight); } }