And now with restitution added. Resititution can be though of as 'bounciness', more restitution, more like made out of rubber it becomes. So the boxes now bounce.
box2 = b_CreateBox(1, 0.5 , 0.0, 347,20,32,32) // No restitution
box2 = b_CreateBox(1, 0.5 , 0.5, 347,20,32,32) // Half restitution
box2 = b_CreateBox(1, 0.5 , 1.0, 347,20,32,32) // Full restitution
FUNCTION b_CreateCircle: mass, friction, rest, x, y, radius
INLINE
b2BodyDef def;
def.position.Set(x,y);
b2Body* pBody = bWorld->CreateBody( &def );
b2CircleDef poly;
poly.radius = radius;
poly.friction = friction;
poly.restitution = rest;
if(mass>0.0) poly.density = mass;
pBody->CreateShape( &poly);
if(mass>0.0) pBody->SetMassFromShapes();
return b_NewObject(pBody, bBody);
ENDINLINE
ENDFUNCTION
FUNCTION b_CreateBox: mass, friction, rest, x, y, w, h
INLINE
b2BodyDef def;
def.position.Set(x,y);
b2Body* pBody = bWorld->CreateBody( &def );
b2PolygonDef poly;
poly.friction = friction;
poly.restitution = rest;
poly.density = 1;
if(mass>0.0) poly.density = mass;
poly.SetAsBox(w*.5, h*.5);
pBody->CreateShape( &poly);
if(mass>0.0) pBody->SetMassFromShapes();
return b_NewObject(pBody, bBody);
ENDINLINE
ENDFUNCTION
//! Create a polygonal shaped object. The pts[] is a 2D array
//! that has the polygon points. The last point must not equal the first point.
//! pts[] must be clockwise points.
FUNCTION b_CreatePoly: mass, friction, rest, x, y, pts[]
INLINE
b2BodyDef def;
def.position.Set(x,y);
b2Body* pBody = bWorld->CreateBody( &def );
b2PolygonDef poly;
poly.friction = friction;
poly.restitution = rest;
poly.vertexCount = LEN(pts);
for(int i=0; i<LEN(pts); ++i)
{
poly.vertices[i] = b2Vec2(pts(i,0), pts(i,1));
}
if(mass>0.0) poly.density = mass;
pBody->CreateShape( &poly);
if(mass>0.0) pBody->SetMassFromShapes();
return b_NewObject(pBody, bBody);
ENDINLINE
ENDFUNCTION