示例#1
0
void RigGeometry::updateGeomToSkelMatrix(const osg::NodePath& nodePath)
{
    bool foundSkel = false;
    osg::ref_ptr<osg::RefMatrix> geomToSkelMatrix;
    for (osg::NodePath::const_iterator it = nodePath.begin(); it != nodePath.end(); ++it)
    {
        osg::Node* node = *it;
        if (!foundSkel)
        {
            if (node == mSkeleton)
                foundSkel = true;
        }
        else
        {
            if (osg::Transform* trans = node->asTransform())
            {
                if (!geomToSkelMatrix)
                    geomToSkelMatrix = new osg::RefMatrix;
                trans->computeWorldToLocalMatrix(*geomToSkelMatrix, nullptr);
            }
        }
    }
    if (geomToSkelMatrix && !geomToSkelMatrix->isIdentity())
        mGeomToSkelMatrix = geomToSkelMatrix;
}
示例#2
0
void osgManipulator::computeNodePathToRoot(osg::Node& node, osg::NodePath& np)
{
    np.clear();
    osg::ref_ptr<FindNodePathToRootVisitor> visitor = new FindNodePathToRootVisitor(np);
    node.accept(*visitor);
    np.pop_back();
    std::reverse(np.begin(), np.end());
}
ImageOverlayEditor::EditPoint
ImageOverlayEditor::getEditPoint(const osg::NodePath &nodePath)
{
    for (osg::NodePath::const_iterator itr = nodePath.begin(); itr != nodePath.end(); ++itr)
    {
        if ((*itr)->getName() == "LOWER_LEFT") return EDITPOINT_LOWER_LEFT;
        if ((*itr)->getName() == "LOWER_RIGHT") return EDITPOINT_LOWER_RIGHT;
        if ((*itr)->getName() == "UPPER_LEFT") return EDITPOINT_UPPER_LEFT;
        if ((*itr)->getName() == "UPPER_RIGHT") return EDITPOINT_UPPER_RIGHT;
        if ((*itr)->getName() == "CENTER") return EDITPOINT_CENTER;
    }
    return EDITPOINT_NONE;
}
/** Compute intersections between a ray through the specified master cameras window/eye coords and a specified nodePath's subgraph. */
bool ossimPlanetViewer::computeIntersections(float x,
                                                     float y, 
                                                     const osg::NodePath& nodePath, 
                                                     osgUtil::LineSegmentIntersector::Intersections& intersections,
                                                     osg::Node::NodeMask traversalMask)
{
   if (!_camera.valid() || nodePath.empty()) return false;
   
   float local_x, local_y = 0.0;    
   const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
   if (!camera)
   {
      if(theIntersectWithMasterIfNotWithinAnyViewFlag)
      {
         camera = forceAdjustToMasterCamera(x, y, local_x, local_y);
         if(!camera) return false;
      }
      else
      {
         return false;
      }
   }
   
   osg::Matrixd matrix;
   if (nodePath.size()>1)
   {
      osg::NodePath prunedNodePath(nodePath.begin(),nodePath.end()-1);
      matrix = osg::computeLocalToWorld(prunedNodePath);
   }
   
   matrix.postMult(camera->getViewMatrix());
   matrix.postMult(camera->getProjectionMatrix());
   
   double zNear = -1.0;
   double zFar = 1.0;
   if (camera->getViewport())
   {
      matrix.postMult(camera->getViewport()->computeWindowMatrix());
      zNear = 0.0;
      zFar = 1.0;
   }
   
   osg::Matrixd inverse;
   inverse.invert(matrix);
   
   osg::Vec3d startVertex = osg::Vec3d(local_x,local_y,zNear) * inverse;
   osg::Vec3d endVertex = osg::Vec3d(local_x,local_y,zFar) * inverse;
   
   osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::MODEL, startVertex, endVertex);
   
   osgUtil::IntersectionVisitor iv(picker.get());
   iv.setTraversalMask(traversalMask);
   nodePath.back()->accept(iv);
   
   if (picker->containsIntersections())
   {
      intersections = picker->getIntersections();
      return true;
   }
   else
   {
      intersections.clear();
      return false;
   }
}