]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/SGPickAnimation.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / model / SGPickAnimation.cxx
index da3921f40057db08d2098d40a23d7fa0e5b193e4..3c6a2da0e38c1e67c2915fbab5dc26e4685bedc9 100644 (file)
@@ -54,17 +54,17 @@ static void readOptionalBindingList(const SGPropertyNode* aNode, SGPropertyNode*
 }
 
 
-osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter* ea)
+osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter& ea)
 {
     using namespace osg;
-    const GraphicsContext* gc = ea->getGraphicsContext();
+    const GraphicsContext* gc = ea.getGraphicsContext();
     const GraphicsContext::Traits* traits = gc->getTraits() ;
     // Scale x, y to the dimensions of the window
-    double x = (((ea->getX() - ea->getXmin()) / (ea->getXmax() - ea->getXmin()))
+    double x = (((ea.getX() - ea.getXmin()) / (ea.getXmax() - ea.getXmin()))
          * (double)traits->width);
-    double y = (((ea->getY() - ea->getYmin()) / (ea->getYmax() - ea->getYmin()))
+    double y = (((ea.getY() - ea.getYmin()) / (ea.getYmax() - ea.getYmin()))
          * (double)traits->height);
-    if (ea->getMouseYOrientation() == osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS)
+    if (ea.getMouseYOrientation() == osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS)
         y = (double)traits->height - y;
     
     return osg::Vec2d(x, y);
@@ -100,7 +100,9 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter* ea)
          _hover = readBindingList(hoverNode->getChildren("binding"), modelRoot);
      }
      
-   virtual bool buttonPressed(int button, const osgGA::GUIEventAdapter* ea, const Info&)
+   virtual bool buttonPressed( int button,
+                               const osgGA::GUIEventAdapter&,
+                               const Info& )
    {
        if (_buttons.find(button) == _buttons.end()) {
            return false;
@@ -110,7 +112,9 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter* ea)
      _repeatTime = -_repeatInterval;    // anti-bobble: delay start of repeat
      return true;
    }
-   virtual void buttonReleased(int keyModState)
+   virtual void buttonReleased( int keyModState,
+                                const osgGA::GUIEventAdapter&,
+                                const Info* )
    {
        SG_UNUSED(keyModState);
        fireBindingList(_bindingsUp);
@@ -129,7 +133,8 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter* ea)
      }
    }
    
-   virtual bool hover(const osg::Vec2d& windowPos, const Info& info)
+   virtual bool hover( const osg::Vec2d& windowPos,
+                       const Info& )
    {
        if (_hover.empty()) {
            return false;
@@ -256,7 +261,9 @@ public:
    _squaredDown = dot(_toDown, _toDown);
  }
 
- virtual bool buttonPressed(int button, const osgGA::GUIEventAdapter* ea, const Info& info)
+ virtual bool buttonPressed( int button,
+                             const osgGA::GUIEventAdapter&,
+                             const Info& info )
  {
    SGVec3d loc(info.local);
    SG_LOG(SG_INPUT, SG_DEBUG, "VNC pressed " << button << ": " << loc);
@@ -270,7 +277,9 @@ public:
    return vv.wasSuccessful();
 
  }
- virtual void buttonReleased(int keyModState)
+ virtual void buttonReleased( int keyModState,
+                              const osgGA::GUIEventAdapter&,
+                              const Info* )
  {
    SG_UNUSED(keyModState);
    SG_LOG(SG_INPUT, SG_DEBUG, "VNC release");
@@ -361,13 +370,11 @@ osg::StateSet* sharedHighlightStateSet()
 void
 SGPickAnimation::apply(osg::Group& group)
 {
-  if (_objectNames.empty()) {
+  if (_objectNames.empty() && _proxyNames.empty()) {
     return;
   }
   
-  osg::ref_ptr<osg::Group> renderGroup, proxyGroup, pickGroup;
   group.traverse(*this);
-  SGSceneUserData* ud = NULL;
   
   // iterate over all group children
   int i = group.getNumChildren() - 1;
@@ -379,40 +386,29 @@ SGPickAnimation::apply(osg::Group& group)
       
     std::list<std::string>::iterator it = std::find(_objectNames.begin(), _objectNames.end(), child->getName());
     if (it != _objectNames.end()) {
-      _objectNames.erase(it);
+      //_objectNames.erase(it);
       install(*child);
       
-//////
-      if (!pickGroup) {
-        osg::Group* mainGroup = createMainGroup(&group);
-        mainGroup->setName(child->getName());
-        
-        if (getConfig()->getBoolValue("visible", true)) {
-            renderGroup = new osg::Group;
-            renderGroup->setName("pick render group");
-            mainGroup->addChild(renderGroup);
-        }
-        
-        pickGroup = new osg::Group;
-        pickGroup->setName("pick highlight group");
-        pickGroup->setNodeMask(simgear::PICK_BIT);
-        pickGroup->setStateSet(sharedHighlightStateSet());
-        mainGroup->addChild(pickGroup);
-          
-        if (!ud) {
-          ud = SGSceneUserData::getOrCreateSceneUserData(pickGroup);
-          setupCallbacks(ud, &group);
-        } else {
-          pickGroup->setUserData(ud);
-        }
-      } // of pick group setup
+      osg::ref_ptr<osg::Group> renderGroup, pickGroup;      
+      osg::Group* mainGroup = createMainGroup(&group);
+      mainGroup->setName(child->getName());
+      child->setName(""); // don't apply other animations twice
       
-////////
-      child->setName("");
-      if (renderGroup.valid()) {
-        renderGroup->addChild(child);
+      if (getConfig()->getBoolValue("visible", true)) {
+          renderGroup = new osg::Group;
+          renderGroup->setName("pick render group");
+          renderGroup->addChild(child);
+          mainGroup->addChild(renderGroup);
       }
       
+      pickGroup = new osg::Group;
+      pickGroup->setName("pick highlight group");
+      pickGroup->setNodeMask(simgear::PICK_BIT);
+      pickGroup->setStateSet(sharedHighlightStateSet());
+      mainGroup->addChild(pickGroup);
+      
+      setupCallbacks(SGSceneUserData::getOrCreateSceneUserData(mainGroup), mainGroup);
+
       pickGroup->addChild(child);
       group.removeChild(child);
       continue;
@@ -424,20 +420,12 @@ SGPickAnimation::apply(osg::Group& group)
     }
     
     _proxyNames.erase(j);
-    if (!proxyGroup) {
-      proxyGroup = new osg::Group;
-      group.addChild(proxyGroup);
-      proxyGroup->setStateSet(sharedHighlightStateSet());
-      proxyGroup->setNodeMask(simgear::PICK_BIT);
+    osg::ref_ptr<osg::Group> proxyGroup = new osg::Group;
+    group.addChild(proxyGroup);
+    proxyGroup->setStateSet(sharedHighlightStateSet());
+    proxyGroup->setNodeMask(simgear::PICK_BIT);
       
-      if (!ud) {
-        ud = SGSceneUserData::getOrCreateSceneUserData(proxyGroup);
-        setupCallbacks(ud, &group);
-      } else {
-        proxyGroup->setUserData(ud);
-      }
-    } // of proxy group setup
-
+    setupCallbacks(SGSceneUserData::getOrCreateSceneUserData(proxyGroup), proxyGroup);
     proxyGroup->addChild(child);
     group.removeChild(child);
   } // of group children iteration
@@ -565,11 +553,13 @@ public:
         }
     }
     
-    virtual bool buttonPressed(int button, const osgGA::GUIEventAdapter* ea, const Info&)
+    virtual bool buttonPressed( int button,
+                                const osgGA::GUIEventAdapter& ea,
+                                const Info& )
     {        
         // the 'be nice to Mac / laptop' users option; alt-clicking spins the
         // opposite direction. Should make this configurable
-        if ((button == 0) && (ea->getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_ALT)) {
+        if ((button == 0) && (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_ALT)) {
             button = 1;
         }
         
@@ -592,7 +582,9 @@ public:
         return true;
     }
     
-    virtual void buttonReleased(int keyModState)
+    virtual void buttonReleased( int keyModState,
+                                 const osgGA::GUIEventAdapter&,
+                                 const Info* )
     {
         // for *clicks*, we only fire on button release
         if (!_hasDragged) {
@@ -613,7 +605,8 @@ public:
       return _dragDirection;
   }
   
-    virtual void mouseMoved(const osgGA::GUIEventAdapter* ea)
+    virtual void mouseMoved( const osgGA::GUIEventAdapter& ea,
+                             const Info* )
     {
         _mousePos = eventToWindowCoords(ea);
         osg::Vec2d deltaMouse = _mousePos - _lastFirePos;
@@ -639,7 +632,7 @@ public:
         if (fabs(delta) >= 1.0) {
             // determine direction from sign of delta
             Direction dir = (delta > 0.0) ? DIRECTION_INCREASE : DIRECTION_DECREASE;
-            fire(ea->getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_SHIFT, dir);
+            fire(ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_SHIFT, dir);
             _lastFirePos = _mousePos;
         }
     }
@@ -657,7 +650,8 @@ public:
         } // of repeat iteration
     }
 
-    virtual bool hover(const osg::Vec2d& windowPos, const Info& info)
+    virtual bool hover( const osg::Vec2d& windowPos,
+                        const Info& )
     {
         if (_hover.empty()) {
             return false;
@@ -748,7 +742,7 @@ SGKnobAnimation::SGKnobAnimation(const SGPropertyNode* configNode,
     _animationValue = value->simplify();
     
     
-    readRotationCenterAndAxis(configNode, _center, _axis);
+    readRotationCenterAndAxis(_center, _axis);
 }
 
 osg::Group*