Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Box2D show a collision between two objects? #144

Open
Anton19780301 opened this issue Nov 17, 2023 · 1 comment
Open

Can Box2D show a collision between two objects? #144

Anton19780301 opened this issue Nov 17, 2023 · 1 comment

Comments

@Anton19780301
Copy link

I apologize if the question is stupid, I just started learning Box2D, can this plugin help you figure out whether objects overlap each other or not?

@bjorn
Copy link
Member

bjorn commented Nov 17, 2023

Each Fixture has beginContact and endContact signals, which indicate which other fixture(s) are being touched:

qml-box2d/box2dfixture.h

Lines 99 to 100 in 0bb88a6

void beginContact(Box2DFixture *other);
void endContact(Box2DFixture *other);

There are also preSolve and postSolve signals for contacts between bodies coming in at the World instance, which are implemented using a Box2D ContactListener, they can be used to tweak the behavior:

qml-box2d/box2dworld.cpp

Lines 109 to 121 in 0bb88a6

void ContactListener::PreSolve(b2Contact *contact, const b2Manifold *oldManifold)
{
Q_UNUSED(oldManifold)
mContact.setContact(contact);
emit mWorld->preSolve(&mContact);
}
void ContactListener::PostSolve(b2Contact *contact, const b2ContactImpulse *impulse)
{
Q_UNUSED(impulse)
mContact.setContact(contact);
emit mWorld->postSolve(&mContact);
}

Finally there is a World.rayCast function, to see if you will hit something when drawing a line:

qml-box2d/box2dworld.cpp

Lines 340 to 345 in 0bb88a6

void Box2DWorld::rayCast(Box2DRayCast *rayCast,
const QPointF &point1,
const QPointF &point2)
{
mWorld.RayCast(rayCast, toMeters(point1), toMeters(point2));
}

You can find each of these functionalities used in some of the examples, especially the "contacts" example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants