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.

Many thanks in advance &
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,

thanks for your reply! I had indeed read the iforce2d article already and found it very helpful. Also, the idea of looking into the Contact class was a very good point.

For my project of creating virtual sound-machines, however, I have in the meantime turned to Fisica, which seems to wrap JBox2D just perfectly for my needs. It makes it very simple to calculate a whole lot of details from contacts and map them to Beads-objects and midi-outputs.

However, I have now stumbled upon a new question concerning the FGearJoint class, but I guess I’ll open a new thread for that …

Thanks & all the best,
ilinx

1 Like