Hi all,
I would think someone would have asked this by now, but I couldn't find anything in a search. Apologies if I missed something.
What is the best method for creating a curved boundary? I've attached an image illustrating some red balls in the type of space I am trying to create.
I am currently using the following code to create 4 static walls, but don't see an easy way to define a curved line.
// bottom
shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(wins.width,0), 0.0f);
shape->e = 1.0f; shape->u = 1.0f;
cpSpaceAddStaticShape(space, shape);
// top
shape = cpSegmentShapeNew(staticBody, cpv(0,wins.height), cpv(wins.width,wins.height), 0.0f);
shape->e = 1.0f; shape->u = 1.0f;
cpSpaceAddStaticShape(space, shape);
// left
shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(0,wins.height), 0.0f);
shape->e = 1.0f; shape->u = 1.0f;
cpSpaceAddStaticShape(space, shape);
// right
shape = cpSegmentShapeNew(staticBody, cpv(wins.width,0), cpv(wins.width,wins.height), 0.0f);
shape->e = 1.0f; shape->u = 1.0f;
cpSpaceAddStaticShape(space, shape);
Do I just have to make lots of lines to approximate the curves? Can I create a polygon?
-Andrew
Creating curved boundaries/lines
-
- Posts: 3
- Joined: Wed Apr 22, 2009 5:49 pm
- Contact:
-
- Posts: 157
- Joined: Mon Aug 20, 2007 12:53 pm
- Location: London, UK
- Contact:
Re: Creating curved boundaries/lines
For external (convex) corners, just use a circle shape.
The internal corners will be tricky, because polygons must be convex. Line segments would probably be easiest, perhaps with a thickness if things are moving quickly.
The internal corners will be tricky, because polygons must be convex. Line segments would probably be easiest, perhaps with a thickness if things are moving quickly.
-
- Posts: 3
- Joined: Wed Apr 22, 2009 5:49 pm
- Contact:
Re: Creating curved boundaries/lines
Does the thickness help to avoid the objects falling through the boundaries?maximile wrote:For external (convex) corners, just use a circle shape.
The internal corners will be tricky, because polygons must be convex. Line segments would probably be easiest, perhaps with a thickness if things are moving quickly.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Creating curved boundaries/lines
Just approximate the curve using short line segments. Depending on the radius you could get away with a fairly chunky collision curve and not many people are going to notice. If you want perfectly round convex sections, use a circle. That is the best you can do at the moment.
I would also recommend giving your segments at least some radius like maximile suggested. It makes the gaps in the line segments less noticeable and smoother. If you don't need an inside/outside just offset the line segments a little to compensate for the thickness.
I would also recommend giving your segments at least some radius like maximile suggested. It makes the gaps in the line segments less noticeable and smoother. If you don't need an inside/outside just offset the line segments a little to compensate for the thickness.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 24 guests