/** * @brief Rotates the tower to face the critter it is attacking * @return void */ void Tower::rotateTowardsTarget() { std::pair<float, float> collisionPath = findCollisionPath(this->_target); float facingCritterAngle = angleInDegrees(collisionPath.first, collisionPath.second); cout << "CollisionPath ("<< collisionPath.first << ", " << collisionPath.second << ")"; this->setRotation(facingCritterAngle); //this->move(this->getPosition().x + this->getSpriteSize().x/2, this->getPosition().y + this->getSpriteSize().y/2); }
void UBGraphicsCompass::updateDrawCursor() { QPixmap pix(":/images/cursors/drawCompass.png"); qreal angle = angleInDegrees(); QTransform tr; tr.rotate(- angle); mDrawCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); }
void UBGraphicsCompass::paintAngleDisplay(QPainter *painter) { qreal angle = angleInDegrees(); qreal angleValue = mDrawing ? - mSpanAngleInDegrees : angle; QString angleText = QString("%1").arg(angleValue, 0, 'f', 1) + "°"; painter->save(); painter->setFont(font()); QFontMetricsF fm(painter->font()); painter->translate(hingeRect().center()); painter->rotate(angle); painter->drawText( QRectF( - fm.width(angleText) / 2, - fm.height() / 2, fm.width(angleText), fm.height()), Qt::AlignTop, angleText); painter->restore(); }
void UBGraphicsCompass::paintRadiusDisplay(QPainter *painter) { qreal radiusInCentimeters = rect().width() / (mPixelsPerMillimeter * 10); QString format = rect().width() >= sDisplayRadiusUnitMinLength ? " %1 " : "%1"; QString radiusText = QString(format).arg(radiusInCentimeters, 0, 'f', 1); bool onPencilArm = rect().width() > sDisplayRadiusOnPencilArmMinLength; painter->save(); painter->setFont(font()); QFontMetricsF fm(painter->font()); QPointF textCenter; if (onPencilArm) textCenter = QPointF(rect().right() - sPencilBaseLength - sPencilLength - fm.width(radiusText) / 2 - 24 - 8, rect().center().y()); else textCenter = QPointF((rect().left() + sNeedleLength + sNeedleBaseLength + hingeRect().left()) / 2, rect().center().y()); painter->translate(textCenter); qreal angle = angleInDegrees(); if (angle > 180) angle -= 360; else if (angle < -180) angle += 360; if (angle <= -90 || angle > 90) painter->rotate(180); painter->drawText( QRectF( - fm.width(radiusText) / 2, - rect().height() / 2, fm.width(radiusText), rect().height()), Qt::AlignVCenter, radiusText); painter->restore(); }