Maybe you can use edges (like very thin boxes). Here's a code that allows the user to draw static edges on the screen (using Cocos2D):
Code:
- (void)ccTouchMoved:(UITouch*)touch withEvent:(UIEvent *)event
{
CGPoint start = [touch locationInView: [touch view]];
start = [[CCDirector sharedDirector] convertToGL: start];
CGPoint end = [touch previousLocationInView:[touch view]];
end = [[CCDirector sharedDirector] convertToGL:end];
float distance = ccpDistance(start, end);
if (distance > 1)
{
int d = (int)distance;
b2Vec2 s(start.x/PTM_RATIO, start.y/PTM_RATIO);
b2Vec2 e(end.x/PTM_RATIO, end.y/PTM_RATIO);
b2BodyDef bd;
bd.type = b2_staticBody;
bd.position.Set(0, 0);
b2Body* body = world->CreateBody(&bd);
for (int i = 0; i < d; i++)
{
b2PolygonShape shape;
shape.SetAsEdge(b2Vec2(s.x, s.y), b2Vec2(e.x, e.y));
body->CreateFixture(&shape, 0.0f);
}
}
}
If you want the user to draw dynamic bodies you'll need to keep the coordinates in an array and draw the body when the touch ends.
As for your second question, I think it has already been discussed before:
viewtopic.php?f=3&t=6790