Sorry for my bad English, it is not my first language.
I am making a simulation with processing, using pbox2d library(it is almost same with normal box2d). It does work, but I noticed that objects are overlapping to each others. I tried to fix it by changing the restitution constant or density of objects, but nothing changed. Is there any way to stop this phenomenon-or at least decrease overlapping?
I'll show you some screenshots and source code of my projects.
Thank you for helping me!
This is my code for object class.
class Box
{
Body body;
float radius;
Box(){
BodyDef bd=new BodyDef();
bd.type=BodyType.DYNAMIC;
bd.position.set(box2d.coordPixelsToWorld((float)Math.random()*900+1,(float)Math.random()*300+1));
body=box2d.createBody(bd);
CircleShape cs=new CircleShape();
radius=10;
cs.m_radius=box2d.scalarPixelsToWorld(radius);
FixtureDef fd=new FixtureDef();
fd.shape=cs;
fd.density=10;
fd.friction=0.3;
fd.restitution=0.5;
body.createFixture(fd);
}
void display()
{
Vec2 pos=box2d.getBodyPixelCoord(body);
float a = body.getAngle();
pushMatrix();
translate(pos.x,pos.y);
rotate(-a);
fill(175);
stroke(0);
rectMode(CENTER);
ellipse(0,0,2*radius,2*radius);
popMatrix();
}
void killBody()
{
box2d.destroyBody(body);
}
}