0
우리 프로젝트의 주체는 퓨전을 시뮬레이트하는 프로그램을 만들고 있습니다.복잡한 형태의 경계 사각형?
우리의 클라세 퓨전과의 충돌에 약간의 문제가 있습니다. 우리는 우리 충돌을위한 복잡한 모양을 만들고 싶습니다.
이 우리의 퓨전 클래스입니다
우리의 모양이 서로 가까운 두 개의 원이며, 우리가 경계하는 구형을 가지고 있지만 "복잡한"모양을 싶지 않는 ...
Fusion::Fusion(int x, int y)
{
this->setPos(x, y);
}
void Fusion::shape(){
//...
}
void Fusion::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
//set the color
QBrush brushColor(QColor(Qt::blue));
painter->setBrush(brushColor);
painter->setPen(QColor(Qt::blue));
painter->drawEllipse(0,0,40,40);
painter->drawEllipse(-20,-20,40,40);
}
void Fusion::doCollision()
{
// get a new position
// change the angle with randomness
if(qrand() %1)
{
setRotation(rotation() + (180 + (qrand() % 10)));
}
else
{
setRotation(rotation() + (180 + (qrand() % -10)));
}
// check if the new position is in bounds
QPointF newPoint = mapToParent(-(boundingRect().width()), -(boundingRect().width() + 2));
if(!scene()->sceneRect().contains((newPoint)))
{
// move back in bounds
newPoint = mapToParent(0,0);
}
else
{
// set the new position
setPos(newPoint);
}
}
void Fusion::advance(int step)
{
if(!step) return;
if(!scene()->collidingItems(this).isEmpty())
{
doCollision();
}
setPos(mapToParent(0, -1));
}
안녕하세요, 도움을 주셔서 감사합니다. 그러나 이것으로 우리는 스크린 버그보기입니다 -> [bugScreen] (http://i.imgur.com/P5ib3lL.png). Idk 왜냐하면 모양() ...이 버그에 대한 아이디어가 있습니까? –
그림은 boundingRect 또는 셰이프 함수가 정확하지 않거나 해당 메서드의 결과에 영향을주는 일부 작업 전에 prepareGeometryChange를 호출하지 못했음을 나타냅니다. 그런 일이 발생하면 이전 영역이 제대로 지워지지 않기 때문에 드로잉 아티팩트가 표시됩니다. – goug