# Calculating the impact of a collision in box2d for Processing

Hi all,

I’ve been searching around the internet for a while now, but couldn’t find a solution to the following problem:

In box2d for Processing, I’d like to calculate the impact of a contact in order to modify certain parameters of a sound (e.g. its level). I’ve realized that Fisica has a class named FContactResult – is there anything comparable, ready-to-go, in box2d for Processing?

The thing is, I would like both angular velocity and linear velocity to be taken into account when calculating the impact force.

I’ve posted some of my code below (it’s based on – what else – Daniel Shiffman’s fantastic tutorials). I’ve also marked the spot where I’d guess the essential lines have to go. As you’ll see, I’ve even managed to get the “manifold”, though I don’t know how to go on from there.

Any tips and/or hints to useful resources are appreciated.

all the best to everybody
ilinx

``````void beginContact(Contact cp){

Fixture f1 = cp.getFixtureA();
Fixture f2 = cp.getFixtureB();
Body b1 = f1.getBody();
Body b2 = f2.getBody();

Object o1 = b1.getUserData();
Object o2 = b2.getUserData();

if(o1.getClass() == Boundary.class && o2.getClass() == Box.class){
collisionCount++;
println("hello world! " + collisionCount);

Box b = (Box)o2;

Manifold manifold = cp.getManifold();

}
}
``````
1 Like

If you are using the Processing Box2D library, it uses JBox2D. Specifically, it looks like you are wondering about the available methods on a Contact object. Here they are:

1 Like

You might also find this Box2D tutorial relevant, particularly the part on " Collision points and the normal".

https://www.iforce2d.net/b2dtut/collision-anatomy

It is for C++, not Java, but it might be helpful for explaining the concepts of what a Box2D Contact is and how it can be used. Maybe that will be useful for understanding the Java API.

Hi Jeremy,