How to make two bodies after a collision?

I am really stuck on this, I can successfully detect a collision, but I can not get two bodies to participate in a collision.

Here is my ContactListener

world.setContactListener(listener);

    listener = new ContactListener() {

        @Override
        public void preSolve(Contact contact, Manifold oldManifold) {

        }


        @Override
        public void postSolve(Contact contact, ContactImpulse impulse) {

        }

        //called when two fixtures cease to touch
        @Override
        public void endContact(Contact contact) {
            Fixture fixtureA = contact.getFixtureA();
            Fixture fixtureB = contact.getFixtureB();
            Gdx.app.log("beginContact", "between" + fixtureA.toString() + "and" + fixtureB.toString());
        }

        //called when two fixtures begin to touch
        @Override
        public void beginContact(Contact contact) {
            Fixture fixtureA = contact.getFixtureA();
            Fixture fixtureB = contact.getFixtureB();
            Gdx.app.log("beginContact", "between" + fixtureA.toString() + "and" + fixtureB.toString());
        }
    };

Also this is what I put in render () right after the line world.step ()

int numContacts = world.getContactCount();

    if(numContacts > 0)
    {
        Gdx.app.log("contact", "start of contact list");
        for(Contact contact: world.getContactList())
        {
            Fixture fixtureA = contact.getFixtureA();
            Fixture fixtureB = contact.getFixtureB();
            Gdx.app.log("contact", "between" + fixtureA.toString() + "and" + fixtureB.toString());
        }
        Gdx.app.log("contact", "end of contact list");
    }

I am extremely fixated on the fact that putting on a post to solve or pre-solving is really confused. I followed sticky shells iforce2d http://www.iforce2d.net/b2dtut/sticky-projectiles , but I don't understand C ++ and get a lot of syntax errors when working in eclipse. Please can someone show me an example of a working collision code where bodies stick together after a collision in java, please.

+4
1

WeldJoint libgdx:

WeldJointDef wd = new WeldJointDef();
wd.bodyA = body1;
wd.bodyB = body2;
wd.referenceAngle = wd.bodyB.getAngle() - wd.bodyA.getAngle();
world.createJoint( wd );

ContactListener. , , world.step.

EDIT:

, iforce2d, , :

public class StickyInfo{
    Body bodyA;
    Body bodyB;
    public StickyInfo(Body bodyA, Body bodyB){
        this.bodyA = bodyA;
        this.bodyB = bodyB;
    }
};

libgdx StickyInfo

Array<StickyInfo> collisionsToMakeSticky = new Array<StickyInfo>();

(, ), :

collisionsToMakeSticky.add(new StickyInfo(body1, body2))

world.step, . WeldJoints:

while(collisionsToMakeSticky.size>0){
    StickyInfo si = collisionsToMakeSticky.removeIndex(0);
    //Make the WeldJoint with the bodies si.bodyA and si.bodyB
}
+5

All Articles