I'm writing a program in Java using JBox2D. I need to find the exact point of collision between two textures, if and when they collide.
I have the code to determine if a collision happens, and can obviously just call the collision object ID to determine which textures are colliding.
What I can't seem to figure out is how to grab the actual coordinates of the collision itself. I read the documentation, but it is very complicated and does not address this issue directly.
Here's my code:
import org.jbox2d.callbacks.ContactImpulse;
import org.jbox2d.callbacks.ContactListener;
import org.jbox2d.collision.Manifold;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Fixture;
import org.jbox2d.dynamics.contacts.Contact;
public class MyContactListener implements ContactListener{
//When they start to collide
public void beginContact(Contact c) {
System.out.println("CONTACT");
Fixture fa = c.getFixtureA();
Fixture fb = c.getFixtureB();
Vec2 posA = fa.getBody().getPosition();
Vec2 posB = fb.getBody().getPosition();
}
public void endContact(Contact c) {
}
public void preSolve(Contact c, Manifold m) {}
public void postSolve(Contact c, ContactImpulse ci){}
}