Przeglądaj źródła

First work towards selection

Johannes Kreutz 3 lat temu
rodzic
commit
651345cd00

+ 1 - 0
trackpoint-app/include/PickHandler.hpp

@@ -34,4 +34,5 @@ private:
   void removeAllShapes();
   void setVisibility(bool mode);
   void addPoint(osg::Vec3 point, osg::Vec3 normal);
+  void invalidateTrackPointColors();
 };

+ 2 - 0
trackpoint-app/include/PointShape.hpp

@@ -22,6 +22,7 @@ public:
   void setVisibility(bool mode);
   void setColor(osg::Vec4 color);
   void setupOptiTrack(OptiTrackSettings optiTrackSettings);
+  osg::ref_ptr<osg::Geode> getMesh();
 
 private:
   osg::ref_ptr<osg::Switch> _selectionSwitch;
@@ -30,6 +31,7 @@ private:
   osg::ref_ptr<osg::MatrixTransform> _selectionMoveToEndGroup;
   osg::ref_ptr<osg::Group> _renderRoot;
   osg::ref_ptr<osg::ShapeDrawable> _shape;
+  osg::ref_ptr<osg::Geode> _geode;
   osg::Vec3f _normalModifier;
   double _optiTrackSteamVRLength;
   ActiveTrackingSystem _activeTrackingSystem;

+ 1 - 0
trackpoint-app/include/TrackPointRenderer.hpp

@@ -13,6 +13,7 @@ public:
   TrackPointRenderer(OSGWidget* osgWidget, osg::ref_ptr<osg::Group> renderRoot);
   ~TrackPointRenderer();
   void render(ActiveTrackingSystem activeTrackingSystem);
+  std::vector<PointShape*> getShapes();
 
 private:
   OSGWidget* _osgWidget;

+ 19 - 1
trackpoint-app/src/PickHandler.cpp

@@ -75,6 +75,9 @@ bool PickHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapt
               addPoint(result.localIntersectionPoint, result.localIntersectionNormal);
               break;
             }
+            /*for () {
+
+            }*/
           }
         }
       }
@@ -88,6 +91,7 @@ bool PickHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapt
       osgUtil::IntersectionVisitor iv(intersector.get());
       iv.setTraversalMask(~0x1);
       viewer->getCamera()->accept(iv);
+      invalidateTrackPointColors();
       if (intersector->containsIntersections()) {
         if (_addNewPoints) {
           for (const osgUtil::LineSegmentIntersector::Intersection result: intersector->getIntersections()) {
@@ -99,8 +103,16 @@ bool PickHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapt
             }
           }
         } else {
+          bool found = false;
           for (const osgUtil::LineSegmentIntersector::Intersection result: intersector->getIntersections()) {
-            // TODO
+            if (found) break;
+            for (PointShape* shape: _osgWidget->getPointRenderer()->getShapes()) {
+              if (std::find(result.nodePath.begin(), result.nodePath.end(), shape->getMesh()) != result.nodePath.end()) {
+                shape->setColor(osg::Vec4(0.0f, 0.0f, 1.0f, 0.2f));
+                found = true;
+                break;
+              }
+            }
           }
         }
       } else {
@@ -185,3 +197,9 @@ void PickHandler::addPoint(osg::Vec3 point, osg::Vec3 normal) {
     }
   }
 }
+
+void PickHandler::invalidateTrackPointColors() {
+  for (PointShape* shape: _osgWidget->getPointRenderer()->getShapes()) {
+    shape->setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 0.2f));
+  }
+}

+ 8 - 4
trackpoint-app/src/PointShape.cpp

@@ -57,12 +57,16 @@ void PointShape::setColor(osg::Vec4 color) {
 void PointShape::setupOptiTrack(OptiTrackSettings optiTrackSettings) {
   if (_activeTrackingSystem == OptiTrack) {
     _optiTrackSteamVRLength = optiTrackSettings.length;
-    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
+    _geode = new osg::Geode;
     _shape = new osg::ShapeDrawable();
     _shape->setShape(new osg::Cylinder(osg::Vec3(0.0f, 0.0f, 0.0f), optiTrackSettings.radius, optiTrackSettings.length));
     _shape->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 0.2f));
-    geode->addDrawable(_shape.get());
-    OSGWidget::fixMaterialState(geode);
-    _selectionRotateGroup->addChild(geode.get());
+    _geode->addDrawable(_shape.get());
+    OSGWidget::fixMaterialState(_geode);
+    _selectionRotateGroup->addChild(_geode.get());
   }
 }
+
+osg::ref_ptr<osg::Geode> PointShape::getMesh() {
+  return _geode;
+}

+ 4 - 0
trackpoint-app/src/TrackPointRenderer.cpp

@@ -38,3 +38,7 @@ void TrackPointRenderer::render(ActiveTrackingSystem activeTrackingSystem) {
     }
   }
 }
+
+std::vector<PointShape*> TrackPointRenderer::getShapes() {
+  return _shapes;
+}