当前位置: 首页>>代码示例>>C++>>正文


C++ QPolygonF::intersected方法代码示例

本文整理汇总了C++中QPolygonF::intersected方法的典型用法代码示例。如果您正苦于以下问题:C++ QPolygonF::intersected方法的具体用法?C++ QPolygonF::intersected怎么用?C++ QPolygonF::intersected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QPolygonF的用法示例。


在下文中一共展示了QPolygonF::intersected方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: applyVelocity

/* applies velocity to position, currently moves past bounds */
void PlayerPhysicsComponent::applyVelocity(Player* player)
{
    //assuming body of player sprite is from 13,4 to 35, 44

    QPointF newPos = player->getPos() + player->getVelocity().toPointF();

    if (player->getPos() == newPos) {
        return;
    }

    Map* gameMap = player->getDriver()->getGameMap();
    QSet<Tile*> targetTiles = gameMap->getTiles(newPos, 2);

    QPointF upperRight;
    QPointF upperLeft;
    QPointF lowerRight;
    QPointF lowerLeft;
    QSet<Unit*> npcs;
    double angle = player->getOrientation();
    QMatrix matrix = QMatrix();
    matrix.rotate(-angle);

    upperRight = QPointF(15, -15) * matrix;
    upperLeft =  QPointF(-5, -15) * matrix;
    lowerRight = QPointF(15, 15) * matrix;
    lowerLeft =  QPointF(-5, 15) * matrix;

    upperRight += newPos;
    upperLeft += newPos;
    lowerRight += newPos;
    lowerLeft += newPos;


    QVector<QPointF> points = QVector<QPointF>();
    points.append(upperRight);
    points.append(upperLeft);
    points.append(lowerLeft);
    points.append(lowerRight);
    points.append(upperRight);
    QPolygonF polygon = QPolygonF(points);
    bool collision = false;
    foreach (Tile* targetTile ,targetTiles){

        QPolygonF otherpolygon = targetTile->getBounds();
        if(polygon.intersected(otherpolygon).count() != 0){
            collision = true;
            break;
        }
    }
开发者ID:DTRAIN,项目名称:td,代码行数:50,代码来源:PlayerPhysicsComponent.cpp

示例2: fillParams

void KisPerspectiveTransformWorker::fillParams(const QRectF &srcRect,
                                               const QRect &dstBaseClipRect,
                                               QRegion *dstRegion,
                                               QPolygonF *dstClipPolygon)
{
    QPolygonF bounds = srcRect;
    QPolygonF newBounds = m_forwardTransform.map(bounds);

    newBounds = newBounds.intersected(QRectF(dstBaseClipRect));

    QPainterPath path;
    path.addPolygon(newBounds);
    *dstRegion = KritaUtils::splitPath(path);
    *dstClipPolygon = newBounds;
}
开发者ID:TheTypoMaster,项目名称:calligra,代码行数:15,代码来源:kis_perspectivetransform_worker.cpp

示例3: mouseMoveEvent

void MapView::mouseMoveEvent(QMouseEvent *event)
{
    if (selecting_) {
        // FIXME: optimize
        //QRect rect = selectionRect().normalized();
        //foreach (QGraphicsItem *item, scene()->items(mapToScene(rect))) {
        QRectF rect = selectionRect();
        foreach (QGraphicsItem *item, scene()->items()) {
            QPolygonF itemViewportBounds = mapFromScene(item->sceneBoundingRect());
            bool intersects = !itemViewportBounds.intersected(rect).isEmpty();
            MapItem *mapItem = dynamic_cast<MapItem *>(item);
            if (mapItem)
                mapItem->setActive(intersects);
        }
        scene()->update();
        return;
    }
开发者ID:zmeyc,项目名称:mapmaker,代码行数:17,代码来源:MapView.cpp

示例4: checkCollisions

bool Engine::checkCollisions(){

  QPolygonF pl = player->getPolygon();
  bool colision = false;

  for(auto& ob : obstacles){
    colision =  !pl.intersected(ob->getPolygon()).empty() || colision;
  }
  
  if(colision){
    std::cout << "Colision!!" << std::endl;
    if(!player->ifInColision()){
      player->setColision();
      player->setVelocity(-player->getVelocity());
      player->setAcceleration(-player->getAcceleration());
    }
  } else {
    player->unsetColision();
    std::cout << "Empty!!" << std::endl;
  }
  
  

}
开发者ID:mopalka,项目名称:smokey,代码行数:24,代码来源:engine.cpp

示例5: checkInTriangle

 bool checkInTriangle(const QRectF &rect,
                      const QPolygonF &triangle)
 {
     return triangle.intersected(rect).boundingRect().isValid();
 }
开发者ID:crayonink,项目名称:calligra-2,代码行数:5,代码来源:krita_utils.cpp

示例6: draw

void QgsComposerMapOverview::draw( QPainter *painter )
{
  if ( !mEnabled || mFrameMapId == -1 || !mComposerMap || !mComposerMap->composition() )
  {
    return;
  }
  if ( !painter )
  {
    return;
  }

  const QgsComposerMap* overviewFrameMap = mComposerMap->composition()->getComposerMapById( mFrameMapId );
  if ( !overviewFrameMap )
  {
    return;
  }

  //get polygon for other overview frame map's extent (use visibleExtentPolygon as it accounts for map rotation)
  QPolygonF otherExtent = overviewFrameMap->visibleExtentPolygon();

  //get current map's extent as a QPolygonF
  QPolygonF thisExtent = mComposerMap->visibleExtentPolygon();
  //intersect the two
  QPolygonF intersectExtent = thisExtent.intersected( otherExtent );

  //setup painter scaling to dots so that raster symbology is drawn to scale
  double dotsPerMM = painter->device()->logicalDpiX() / 25.4;

  //setup render context
  QgsMapSettings ms = mComposerMap->composition()->mapSettings();
  //context units should be in dots
  ms.setOutputSize( QSizeF( mComposerMap->rect().width() * dotsPerMM, mComposerMap->rect().height() * dotsPerMM ).toSize() );
  ms.setExtent( *mComposerMap->currentMapExtent() );
  ms.setOutputDpi( painter->device()->logicalDpiX() );
  QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
  context.setForceVectorOutput( true );
  context.setPainter( painter );
  QgsExpressionContext* expressionContext = createExpressionContext();
  context.setExpressionContext( *expressionContext );
  delete expressionContext;

  painter->save();
  painter->setCompositionMode( mBlendMode );
  painter->translate( mComposerMap->mXOffset, mComposerMap->mYOffset );
  painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
  painter->setRenderHint( QPainter::Antialiasing );

  mFrameSymbol->startRender( context );

  //construct a polygon corresponding to the intersecting map extent
  //need to scale line to dots, rather then mm, since the painter has been scaled to dots
  QTransform mapTransform;
  QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, dotsPerMM * mComposerMap->rect().width(), dotsPerMM * mComposerMap->rect().height() ) );

  //workaround QT Bug #21329
  thisRectPoly.pop_back();
  thisExtent.pop_back();

  //create transform from map coordinates to painter coordinates
  QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
  QPolygonF intersectPolygon;
  intersectPolygon = mapTransform.map( intersectExtent );

  QList<QPolygonF> rings; //empty list
  if ( !mInverted )
  {
    //Render the intersecting map extent
    mFrameSymbol->renderPolygon( intersectPolygon, &rings, nullptr, context );
  }
  else
  {
    //We are inverting the overview frame (ie, shading outside the intersecting extent)
    //Construct a polygon corresponding to the overview map extent
    QPolygonF outerPolygon;
    outerPolygon << QPointF( 0, 0 )
    << QPointF( mComposerMap->rect().width() * dotsPerMM, 0 )
    << QPointF( mComposerMap->rect().width() * dotsPerMM, mComposerMap->rect().height() * dotsPerMM )
    << QPointF( 0, mComposerMap->rect().height() * dotsPerMM )
    << QPointF( 0, 0 );

    //Intersecting extent is an inner ring for the shaded area
    rings.append( intersectPolygon );
    mFrameSymbol->renderPolygon( outerPolygon, &rings, nullptr, context );
  }

  mFrameSymbol->stopRender( context );
  painter->restore();
}
开发者ID:NyakudyaA,项目名称:QGIS,代码行数:88,代码来源:qgscomposermapoverview.cpp


注:本文中的QPolygonF::intersected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。