void Stimulus3DShaderDemo::receive_json_message(const std::string& topic_name, const std::string& json_message) { json_t *root; json_error_t error; root = json_loads(json_message.c_str(), 0, &error); if(!root) { throw std::runtime_error("error in json"); } json_t *data_json = json_object_get(root, "data"); if (data_json==NULL) { throw std::runtime_error("key not in JSON"); } if(!json_is_number(data_json)){ throw std::runtime_error("error in json"); } _example_param = json_number_value( data_json ); example_param_uniform->set(_example_param); }
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { if (!unit || !dt || !intensity) return false; float i,t; intensity->get(i); dt->get(t); switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): case(osgGA::GUIEventAdapter::KEYUP): { // iteration if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F2) { unit->setNumIterations(unit->getNumIterations()+1); }else if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F1) { unit->setNumIterations(unit->getNumIterations()-1); } // intenisty if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F3) { intensity->set(i-0.1f); }else if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F4) { intensity->set(i+0.1f); } // dt if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F5) { dt->set(t-0.001f); }else if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F6) { dt->set(t+0.001f); } break; } default: break; } return false; }
void onValueChanged(Control*, float value) { _u->set( value ); }