/* 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; } }
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; }
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; }
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; } }
bool checkInTriangle(const QRectF &rect, const QPolygonF &triangle) { return triangle.intersected(rect).boundingRect().isValid(); }
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(); }