Ejemplo n.º 1
0
Polyangle Polyangle::getIncircle(int definition) const
{
    float pi = 3.14159265358979323846;
    Vector2D center = getCentre();
    QVector<Vector2D> newPoints;
    float radius = std::numeric_limits<float>::max();
    for (int i = 0; i < lesPoints.size(); i++)
    {
        Vector2D segment = (lesPoints[(i+1)%lesPoints.size()]-lesPoints[i]);
        segment.normalize();
        float scalar = (center-lesPoints[i])* segment;
        Vector2D nearestPoint = segment * scalar+lesPoints[i];
        float distance = center.distanceToPoint2D(nearestPoint);
        if (distance < radius)
            radius = distance;
    }

    for (int i=0; i < definition; i++)
    {
        float x = cos(2*pi*i/definition)*radius;
        float y = sin(2*pi*i/definition)*radius;
        newPoints << center + Vector2D(x, y);
    }

    return Polyangle(newPoints);

}
Ejemplo n.º 2
0
const Displays::Display& Displays::findDisplayForPoint (Point<int> point, bool isPhysical) const noexcept
{
    auto minDistance = std::numeric_limits<int>::max();
    Display* retVal = nullptr;

    for (auto& display : displays)
    {
        auto displayArea = display.totalArea;

        if (isPhysical)
            displayArea = (displayArea.withZeroOrigin() * display.scale) + display.topLeftPhysical;

        if (displayArea.contains (point))
            return display;

        auto distance = displayArea.getCentre().getDistanceFrom (point);
        if (distance <= minDistance)
        {
            minDistance = distance;
            retVal = &display;
        }
    }

    return *retVal;
}
Ejemplo n.º 3
0
/**
 * Update all units to go to an additional group centre
 */
void UnitGroup::addGoalPosition(osg::Vec3 pos) {
	osg::Vec3 centre = getCentre();
	for (std::vector<Unit*>::iterator it = mUnits.begin(); it != mUnits.end(); it++) {
		osg::Vec3 offset = (*it)->getPosition() - centre;
		(*it)->addGoalPosition(pos + offset);
	}
}
void MultiChoicePropertyComponent::resized()
{
    auto bounds = getLookAndFeel().getPropertyComponentContentPosition (*this);

    bounds.removeFromBottom (5);

    auto buttonSlice = bounds.removeFromBottom (10);
    expandButton.setSize (10, 10);
    expandButton.setCentrePosition (buttonSlice.getCentre());

    numHidden = 0;

    for (auto* b : choiceButtons)
    {
        if (bounds.getHeight() >= 25)
        {
            b->setVisible (true);
            b->setBounds (bounds.removeFromTop (25).reduced (5, 2));
        }
        else
        {
            b->setVisible (false);
            ++numHidden;
        }
    }
}
Ejemplo n.º 5
0
void Circle::Intersect(DynamicCircle * dynamicCircle)const{
	if (getCentre().distance(dynamicCircle->getCentre()) < this->radius + dynamicCircle->getRadius()){
		//STEP 1
		Vector u1(getCentre(), dynamicCircle->getCentre());
		double a = dynamicCircle->getVelocity().dot(dynamicCircle->getVelocity());
		double b = 2 * (dynamicCircle->getVelocity().dot(Vector(getCentre(), dynamicCircle->getCentre())));
		double c = u1.dot(u1) - pow(dynamicCircle->getRadius() + this->getRadius(), 2);
		double t1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
		double t2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
		double t = (t1 < t2) ? t1 : t2;
		dynamicCircle->setCentre(dynamicCircle->getCentre() + t*dynamicCircle->getVelocity());

		//STEP 2
		Vector u2(this->getCentre(), dynamicCircle->getCentre());
		u2.normalize();
		dynamicCircle->setVelocity(dynamicCircle->getVelocity() - 2*(dynamicCircle->getVelocity().dot(u2)) * u2);
	}
		
	
}
Ejemplo n.º 6
0
	void WPN_MoveShots(World& world, float elapsedTime)
	{
		auto shot = d6Shots.begin();

		while (shot != d6Shots.end())
		{
			const Weapon& weapon = shot->getWeapon();
			shot->move(elapsedTime);

			Hit hit = WPN_ShotPlayerCollision(*shot, world.getPlayers());
			if (!hit.hit)
			{
				hit = WPN_ShotWallCollision(*shot, world.getLevel());
			}

			if (hit.hit)
			{
				WPN_Boom(*shot, world.getPlayers(), hit.player, world.getSpriteList(), world.getFireList());
				const Vector shotCentre = shot->getCentre();
				
				Sprite boom(weapon.boomAnimation, weapon.textures.boom);
				boom.setPosition(shotCentre - Vector(0.5f, 0.5f), 0.6f)
					.setSpeed(2.0f)
					.setLooping(AnimationLooping::OnceAndRemove)
					.setOrientation(shot->getOrientation())
					.setAlpha(0.6f);

				SpriteList::Iterator boomSprite = world.getSpriteList().addSprite(boom);

				if (shot->getPlayer().hasPowerfulShots())
					boomSprite->setGrow(weapon.expGrow * 1.2f);
				else
					boomSprite->setGrow(weapon.expGrow);
				weapon.boomSample.play();
				if (weapon.boom > 0)
				{
					boomSprite->setNoDepth(true);
				}
				
				shot = WPN_RemoveShot(shot, world.getSpriteList());
			}
			else
			{
				++shot;
			}
		}
	}
Ejemplo n.º 7
0
AxisSet* Circle::getSeparatingAxes(const Shape* s) const
{
	AxisSet *as =  new AxisSet();

	std::auto_ptr<OrderedPair> closestPoint(s->getClosestVertex(getCentre()));

	if (s->isVertex(*closestPoint))
	{
			std::auto_ptr<OrderedPair> closestPointToVertex(getClosestVertex(*closestPoint));
		Vector separatingAxis = Vector(*closestPointToVertex)
				- Vector(*closestPoint);
		if (!(separatingAxis == Vector(0, 0)))
		{
			as->add(separatingAxis.Normalise());
		}
	}

	return as;
}
Ejemplo n.º 8
0
//======================================================================
void HeaderComponent::resized()
{
    auto bounds = getLocalBounds();
    configLabel.setFont ({ bounds.getHeight() / 3.0f });

    //======================================================================
    {
        auto headerBounds = bounds.removeFromLeft (tabsWidth);

        const int buttonSize = 25;
        auto buttonBounds = headerBounds.removeFromRight (buttonSize);

        projectSettingsButton->setBounds (buttonBounds.removeFromBottom (buttonSize).reduced (2));

        juceIcon->setBounds (headerBounds.removeFromLeft (headerBounds.getHeight()).reduced (2));

        headerBounds.removeFromRight (5);
        projectNameLabel.setBounds (headerBounds);
    }

    //======================================================================
    auto exporterWidth = jmin (400, bounds.getWidth() / 2);
    Rectangle<int> exporterBounds (0, 0, exporterWidth, bounds.getHeight());

    exporterBounds.setCentre (bounds.getCentre());

    runAppButton->setBounds (exporterBounds.removeFromRight (exporterBounds.getHeight()).reduced (2));
    saveAndOpenInIDEButton->setBounds (exporterBounds.removeFromRight (exporterBounds.getHeight()).reduced (2));

    exporterBounds.removeFromRight (5);
    exporterBox.setBounds (exporterBounds.removeFromBottom (roundToInt (exporterBounds.getHeight() / 1.8f)));
    configLabel.setBounds (exporterBounds);

    bounds.removeFromRight (5);
    userSettingsButton->setBounds (bounds.removeFromRight (bounds.getHeight()).reduced (2));
}
void AppsPageComponent::buttonStateChanged(Button* btn) {
  auto appBtn = (AppIconButton*)btn;
  auto appIcon = (DrawableImage*)appBtn->getCurrentImage();
  auto buttonPopup = launcherComponent->focusButtonPopup.get();
  constexpr auto scale = 1.3;

  // show floating button popup if we're holding downstate and not showing the popup
  if (btn->isMouseButtonDown() &&
      btn->isMouseOver() &&
      !buttonPopup->isVisible()) {
    // copy application icon bounds in screen space
    auto boundsNext = appIcon->getScreenBounds();
    auto boundsCentre = boundsNext.getCentre();
    
    // scale and recenter
    boundsNext.setSize(boundsNext.getWidth()*scale, boundsNext.getHeight()*scale);
    boundsNext.setCentre(boundsCentre);
    
    // translate back to space local to popup parent (local bounds)
    auto parentPos = launcherComponent->getScreenPosition();
    boundsNext.setPosition(boundsNext.getPosition() - parentPos);
    
    // show popup icon, hide real button beneath
    buttonPopup->setImage(appIcon->getImage());
    buttonPopup->setBounds(boundsNext);
    buttonPopup->setVisible(true);
    appIcon->setVisible(false);
    appBtn->setColour(DrawableButton::textColourId, Colours::transparentWhite);
  }
  // set UI back to default if we can see the popup, but aren't holding the button down
  else if (btn->isVisible()) {
    appIcon->setVisible(true);
    appBtn->setColour(DrawableButton::textColourId, getLookAndFeel().findColour(DrawableButton::textColourId));
    buttonPopup->setVisible(false);
  }
}
Ejemplo n.º 10
0
//private
void CollisionWorld::Body::step(float dt)
{
    //state controls the actual force amount
    m_behaviour->update(dt);

    //then we apply whatever force there is
    //-------------------------
    auto stepSpeed = Util::Vector::length(m_velocity) * dt;
    auto stepVelocity = Util::Vector::normalise(m_velocity) * stepSpeed;

    move(stepVelocity);

    //check to see if still in world bounds
    if (!worldSize.contains(getCentre()))
    {
        setPosition({ worldSize.width / 2.f, worldSize.top + 20.f });
        m_velocity.y = 0.f;
    }

    //make sure bodies come to complete halt
    float ls = Util::Vector::lengthSquared(m_velocity);
    if (ls != 0 && ls < 1.5f)
    {
        m_velocity = {};
        //std::cout << "stopped body" << std::endl;
    }

    //update all the child bodies
    for (auto& c : m_children)
    {
        c.first->setPosition(getCentre() + (c.second - c.first->m_centre));
    }

    if (m_node)
        m_node->setWorldPosition(m_position);
    //--------------------------

    //check to see if a collision has resulted in a new state
    if (m_nextBehaviour)
    {
        m_nextBehaviour.swap(m_behaviour);
        m_nextBehaviour.reset();
    }

    //update strength value or kill if no health
    if (m_health < 0)
    {
        destroy();
    }
    else if (m_health < m_strength)
    {
        m_health += m_strength * dt;
    }


    //check for invincibility time out
    if (m_invincible)
    {
        m_invincibilityCount += dt;
        if (m_invincibilityCount > invincibilityTime)
        {
            m_invincible = false;

            //send event
            Event e;
            e.type = Event::Node;
            e.node.action = Event::NodeEvent::InvincibilityExpired;
            e.node.positionX = m_position.x;
            e.node.positionY = m_position.y;
            notify(*this, e);
        }
    }

    //check speed for any effects it may have - TODO this doesn't work amazingly, may revisit some time
    /*const float currentSpeed = getSpeed();
    if (currentSpeed > turboSpeed
        && m_lastSpeed < turboSpeed)
    {
        Event e;
        e.type = Event::Node;
        e.node.action = Event::NodeEvent::WentTurbo;
        e.node.positionX = m_position.x;
        e.node.positionY = m_position.y;
        notify(*this, e);
    }
    else if (currentSpeed < turboSpeed
        && m_lastSpeed > turboSpeed)
    {
        Event e;
        e.type = Event::Node;
        e.node.action = Event::NodeEvent::LeftTurbo;
        e.node.positionX = m_position.x;
        e.node.positionY = m_position.y;
        notify(*this, e);
    }
    m_lastSpeed = currentSpeed;*/
}
Ejemplo n.º 11
0
void GraphicsItemNode::paint(QPainter * painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    QPainterPath outlinePath = shape();

    //Fill the node's colour
    QBrush brush(m_colour);
    painter->fillPath(outlinePath, brush);

    //If the node contains a BLAST hit, draw that on top.
    if (g_settings->nodeColourScheme == BLAST_HITS_COLOUR)
    {
        std::vector<BlastHitPart> parts;

        if (g_settings->doubleMode)
        {
            if (m_deBruijnNode->thisNodeHasBlastHits())
                parts = m_deBruijnNode->getBlastHitPartsForThisNode();
        }
        else
        {
            if (m_deBruijnNode->thisNodeOrReverseComplementHasBlastHits())
                parts = m_deBruijnNode->getBlastHitPartsForThisNodeOrReverseComplement();
        }

        if (parts.size() > 0)
        {
            QPen partPen;
            partPen.setWidthF(m_width);
            partPen.setCapStyle(Qt::FlatCap);
            partPen.setJoinStyle(Qt::BevelJoin);

            for (size_t i = 0; i < parts.size(); ++i)
            {
                partPen.setColor(parts[i].m_colour);
                painter->setPen(partPen);

                painter->drawPath(makePartialPath(parts[i].m_nodeFractionStart, parts[i].m_nodeFractionEnd));
            }
        }
    }

    //Draw the node outline
    QColor outlineColour = g_settings->outlineColour;
    double outlineThickness = g_settings->outlineThickness;
    if (isSelected())
    {
        outlineColour = g_settings->selectionColour;
        outlineThickness = g_settings->selectionThickness;
    }
    if (outlineThickness > 0.0)
    {
        outlinePath = outlinePath.simplified();
        QPen outlinePen(QBrush(outlineColour), outlineThickness, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin);
        painter->setPen(outlinePen);
        painter->drawPath(outlinePath);
    }


    //Draw text if there is any to display.
    if (g_settings->anyNodeDisplayText())
    {
        //The text should always be displayed upright, so
        //counter the view's rotation here.

        painter->setRenderHint(QPainter::TextAntialiasing, true);
        painter->setFont(g_settings->labelFont);
        QString displayText = getNodeText();
        QSize textSize = getNodeTextSize(displayText);

        double textWidth = textSize.width();
        double textHeight = textSize.height();

        //The text outline is made by drawing the text first in white at a slight offset
        //at many angles.  The larger the text outline, the more angles are needed to
        //make the outline look nice.
        if (g_settings->textOutline)
        {
            int offsetSteps = 8;
            if (g_settings->textOutlineThickness > 0.5)
                offsetSteps = 16;
            if (g_settings->textOutlineThickness > 1.0)
                offsetSteps = 32;

            double offsetDistance = g_settings->textOutlineThickness;

            painter->translate(getCentre());
            painter->rotate(-g_graphicsView->m_rotation);

            for (int i = 0; i < offsetSteps; ++i)
            {
                double offsetAngle = 6.2832 * (double(i) / offsetSteps);
                double xOffset = offsetDistance * cos(offsetAngle);
                double yOffset = offsetDistance * sin(offsetAngle);
                QRectF shadowTextRectangle(-textWidth / 2.0 + xOffset,
                                           -textHeight / 2.0 + yOffset,
                                           textWidth, textHeight);
                painter->setPen(Qt::white);
                painter->drawText(shadowTextRectangle, Qt::AlignCenter, displayText);
            }

            painter->rotate(g_graphicsView->m_rotation);
            painter->translate(-1.0 * getCentre());
        }

        QRectF textRectangle(-textWidth / 2.0, -textHeight / 2.0,
                             textWidth, textHeight);
        painter->setPen(g_settings->textColour);

        painter->translate(getCentre());
        painter->rotate(-g_graphicsView->m_rotation);
        painter->drawText(textRectangle, Qt::AlignCenter, displayText);
        painter->rotate(g_graphicsView->m_rotation);
        painter->translate(-1.0 * getCentre());
    }
}