+ const SGPropertyNode* upNode = configNode->getChild("mod-up");
+ if (!upNode)
+ return;
+ bindings = upNode->getChildren("binding");
+ for (unsigned int i = 0; i < bindings.size(); ++i) {
+ _bindingsUp.push_back(new SGBinding(bindings[i], modelRoot));
+ }
+ }
+ virtual bool buttonPressed(int button, const Info&)
+ {
+ bool found = false;
+ for( std::vector<int>::iterator it = _buttons.begin(); it != _buttons.end(); it++ ) {
+ if( *it == button ) {
+ found = true;
+ break;
+ }
+ }
+ if (!found )
+ return false;
+ SGBindingList::const_iterator i;
+ for (i = _bindingsDown.begin(); i != _bindingsDown.end(); ++i)
+ (*i)->fire();
+ _repeatTime = -_repeatInterval; // anti-bobble: delay start of repeat
+ return true;
+ }
+ virtual void buttonReleased(void)
+ {
+ SGBindingList::const_iterator i;
+ for (i = _bindingsUp.begin(); i != _bindingsUp.end(); ++i)
+ (*i)->fire();
+ }
+ virtual void update(double dt)
+ {
+ if (!_repeatable)
+ return;
+
+ _repeatTime += dt;
+ while (_repeatInterval < _repeatTime) {
+ _repeatTime -= _repeatInterval;
+ SGBindingList::const_iterator i;
+ for (i = _bindingsDown.begin(); i != _bindingsDown.end(); ++i)
+ (*i)->fire();
+ }
+ }
+private:
+ SGBindingList _bindingsDown;
+ SGBindingList _bindingsUp;
+ std::vector<int> _buttons;
+ bool _repeatable;
+ double _repeatInterval;
+ double _repeatTime;
+};
+
+SGPickAnimation::SGPickAnimation(const SGPropertyNode* configNode,
+ SGPropertyNode* modelRoot) :
+ SGAnimation(configNode, modelRoot)
+{
+}
+
+osg::Group*
+SGPickAnimation::createAnimationGroup(osg::Group& parent)
+{
+ osg::Group* commonGroup = new osg::Group;
+
+ // Contains the normal geometry that is interactive
+ osg::ref_ptr<osg::Group> normalGroup = new osg::Group;
+ normalGroup->setName("pick normal group");
+ normalGroup->addChild(commonGroup);
+
+ // Used to render the geometry with just yellow edges
+ osg::Group* highlightGroup = new osg::Group;
+ highlightGroup->setName("pick highlight group");
+ highlightGroup->setNodeMask(SG_NODEMASK_PICK_BIT);
+ highlightGroup->addChild(commonGroup);
+ SGSceneUserData* ud;
+ ud = SGSceneUserData::getOrCreateSceneUserData(commonGroup);
+ std::vector<SGPropertyNode_ptr> actions;
+ actions = getConfig()->getChildren("action");
+ for (unsigned int i = 0; i < actions.size(); ++i)
+ ud->addPickCallback(new PickCallback(actions[i], getModelRoot()));
+
+ // prepare a state set that paints the edges of this object yellow
+ osg::StateSet* stateSet = highlightGroup->getOrCreateStateSet();
+ stateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
+
+ osg::PolygonOffset* polygonOffset = new osg::PolygonOffset;
+ polygonOffset->setFactor(-1);
+ polygonOffset->setUnits(-1);
+ stateSet->setAttribute(polygonOffset, osg::StateAttribute::OVERRIDE);
+ stateSet->setMode(GL_POLYGON_OFFSET_LINE, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
+
+ osg::PolygonMode* polygonMode = new osg::PolygonMode;
+ polygonMode->setMode(osg::PolygonMode::FRONT_AND_BACK,
+ osg::PolygonMode::LINE);
+ stateSet->setAttribute(polygonMode, osg::StateAttribute::OVERRIDE);
+
+ osg::Material* material = new osg::Material;
+ material->setColorMode(osg::Material::OFF);
+ material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(1, 1, 0, 1));
+ material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1, 1, 0, 1));
+ material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4f(1, 1, 0, 1));
+ material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0, 0, 0, 0));
+ stateSet->setAttribute(material, osg::StateAttribute::OVERRIDE);
+
+ // Only add normal geometry if configured
+ if (getConfig()->getBoolValue("visible", true))
+ parent.addChild(normalGroup.get());
+ parent.addChild(highlightGroup);
+
+ return commonGroup;