Here's the relevant piece of code:
QPointF GraphicsItem::handleCollisions(const QPointF& new_pos) const {
auto collisions = collidingItems();
auto rect = mapToParent(boundingRect().translated(new_pos - pos())).boundingRect();
for(int k=0; k < collisions.count(); k++)
{
auto item = collisions[k];
if (item->parentItem() == parentItem()) {
auto rect1 = item->mapToParent(item->boundingRect()).boundingRect();
rect1 = rect1.intersected(rect);
auto v = rect1.center() - rect.center();
if (v.x() >= 0) {
if (v.y() >= 0) {
if (rect1.width() <= rect1.height())
item->setPos(item->pos() + QPointF(rect1.width(), 0) * 1.5);
else
item->setPos(item->pos() + QPointF(0, rect1.height()));
}
else {
if (rect1.width() <= rect1.height())
item->setPos(item->pos() + QPointF(rect1.width(), 0));
else
item->setPos(item->pos() + QPointF(0, -rect1.height()));
}
}
else {
if (v.y() >= 0) {
if (rect1.width() <= rect1.height())
item->setPos(item->pos() + QPointF(-rect1.width(), 0));
else
item->setPos(item->pos() + QPointF(0, rect1.height()));
}
else {
if (rect1.width() <= rect1.height())
item->setPos(item->pos() + QPointF(-rect1.width(), 0));
else
item->setPos(item->pos() + QPointF(0, -rect1.height()));
}
}
}
}
return new_pos; // return this position unchanged
}
Here's a video showing the result, which is very low quality IMHO.
I'd like the result to be smooth: Ie. the pushed box moves at precisely the same velocity as the pushing box.
Thanks for your mathematical ingenuity. It will not go unpayed. I am making this app for you: a visual diagram chaser with the ability to create new logic rules visually. It has never been done.
What you saw in the video was a a C++ application I'm writing as a port of an earlier python prototype I showed you:
Question for you: Is 10 dollars to much to ask per license on a kickstarter campaign? That would amount to 10,000 USD if I sold 1000 copies, and I'm sure I can snag at least that many of you, because this app will be the shits.
If you're interested in how I plan to implement the categorical logic, please ask. It is a way that hasn't been tried before AFAIK.