Exemplo n.º 1
0
bool CircleCollider::CollisionCheck(CircleCollider& a_oOtherCircle)
{
	float lhs = (m_fRadius * m_fRadius) + (a_oOtherCircle.GetRadius() * a_oOtherCircle.GetRadius());
	float rhsX = (a_oOtherCircle.GetCenter().GetX() - m_vCenter.GetX());
	float rhsY = (a_oOtherCircle.GetCenter().GetY() - m_vCenter.GetY());

	if(lhs > ((rhsX*rhsX)+(rhsY*rhsY)))
		return true;
	return false;
}
Exemplo n.º 2
0
void manCol()
{
	circ.getParent()->setPosition(Vec2{ getMouseX(), getMouseY() });

	color = clr_MAGENTA;
	drawCollider(circ);
	color = clr_CYAN;
	drawCollider(pent);

	CollisionData blerg = pent.collided(circ);

	if (blerg.collided)
	{
		color = clr_GREEN;
		cout << blerg.depth << endl;
	}
	else { color = clr_RED; }


	drawVector(circ.getClosestPointTo(pent.getParent()), circ.getParent()->getPosition());
}
Exemplo n.º 3
0
void autoCol()
{
	for (float x = 200; x < 300; x++)
	{
		for (float y = 200; y < 300; y++)
		{
			circ.getParent()->setPosition(Vec2{ x, y });
			if (pent.collided(circ).collided)
			{
				color = clr_WHITE;
				drawVector(Vec2{ x, y }, Vec2{ x - 1, y - 1 });
			}
		}
	}

	color = clr_RED;
	drawCollider(pent);
}
Exemplo n.º 4
0
bool PointCollider::collidesWith (CircleCollider const & other) const
{
  return other.collidesWith(*this);
}
Exemplo n.º 5
0
void drawCollider(CircleCollider &c)
{
	Vec2 blerg = c.getParent()->getPosition();
	drawCircle(blerg.x, blerg.y, c.getRadius(), 15, color);
}
Exemplo n.º 6
0
void ItemElement::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{

    QGraphicsPixmapItem::paint(painter,option,widget);
    if(qobject_cast<MainScene*>(scene())){
        showColliders = qobject_cast<MainScene*>(scene())->showColliders();
        if(this->isSelected()){
           mRotateEnabled = qobject_cast<MainScene*>(scene())->rotate();
        }
    } else {
        mRotateEnabled = false;
     }

    if(qobject_cast<SplitScene*>(scene())){
        showColliders = true;
    }

    if(showColliders){
        QRectF tmpRect;
       QList<QGraphicsItem*> colliders = mTemplate->getColliderRoot()->childItems();


       foreach(QGraphicsItem* col, colliders){
           if(col->type() == QGraphicsItem::UserType+1){

               BoxCollider* boxCol = static_cast<BoxCollider*>(col);
               tmpRect = tmpRect.united(boxCol->getRectToDraw().boundingRect());

               QPen pen(QColor(Qt::cyan));
               pen.setWidth (1);
               painter->setPen (pen);

               painter->drawPolygon(boxCol->getRectToDraw());

               painter->setBrush (QColor(Qt::green));
               painter->setOpacity (0.3);
               painter->drawPolygon(boxCol->getRectToDraw());
           }
           if(col->type() == QGraphicsItem::UserType+2){

               MeshCollider* meshCol = static_cast<MeshCollider*>(col);
               tmpRect = tmpRect.united(meshCol->getPolyToDraw().boundingRect());

               QPen pen(QColor(Qt::cyan));
               pen.setWidth (1);
               painter->setPen (pen);

               painter->drawPolygon(meshCol->getPolyToDraw());

               painter->setBrush (QColor(Qt::green));
               painter->setOpacity (0.3);
               painter->drawPolygon(meshCol->getPolyToDraw());
           }
           if(col->type() == QGraphicsItem::UserType+3){

               CircleCollider* cirCol = static_cast<CircleCollider*>(col);
               int rad = (int)cirCol->getRadius();
               QPointF center = cirCol->getCenter();

               QPointF topLeft = QPointF(center.x() - rad,center.y() - rad);
                QPointF bottomRight = QPointF((center.x() + rad),(center.y() + rad));

               tmpRect = tmpRect.united(QRectF(topLeft,bottomRight));

               QPen pen(QColor(Qt::cyan));
               pen.setWidth (1);
               painter->setPen (pen);

               painter->drawEllipse(center,rad,rad);

               painter->setBrush (QColor(Qt::green));
               painter->setOpacity (0.3);
               painter->drawEllipse(center,rad,rad);
           }


           updateColliderRect(tmpRect);

       }
       if(mRotateEnabled){
          painter->drawEllipse(boundingRect().center(),50,50);
          if(mItemDragged){
              painter->setPen(QColor(Qt::darkGreen));
              painter->setBrush(QColor(Qt::darkGreen));
             // painter->drawPie(QRectF(boundingRect().center()-QPointF(50,-50),boundingRect().center()+QPointF(50,-50)),mRotationStartAngle*16,mRotationSpanAngle*16);
          }
       }
    }
}