Updating body verts

Official forum for the Chipmunk2D Physics Library.
Post Reply
Slaine
Posts: 3
Joined: Fri Feb 01, 2008 5:32 am
Contact:

Updating body verts

Post by Slaine »

Hi, is there an efficent method of updating the body's vertexes? I have create a function to addVerts to the body but I'm not sure how to update on every loop :roll: So it adds a vert when the mouse clicks.

Thanks ;)
ker
Posts: 56
Joined: Tue Jul 15, 2008 4:13 am
Contact:

Re: Updating body verts

Post by ker »

what do you mean by "body's vertexes"?
A body can have shapes, and polygon-shapes can have vertexes. It is quite evil to modify polygons on the fly. Are you sure you need that? Or did I misunderstand what you wanted?
Slaine
Posts: 3
Joined: Fri Feb 01, 2008 5:32 am
Contact:

Re: Updating body verts

Post by Slaine »

I'm basically after a method of say creating a ship editor, or car editor where you can setup the collisions in an editor, so it's dynamic, all the samples I see with this engine are fixed, as in

Code: Select all

int num = 4;
cpVect verts[] = {
cpv(-15,-15),
cpv(-15, 15),
cpv( 15, 15),
cpv( 15,-15),
};

// Create a cube
m_body = cpBodyNew(1.0, cpMomentForPoly(1.0, num, verts, cpvzero));
I need it to be more object oriented if that's the right term, so verts or vects can be modified.
Michael Buckley
Posts: 46
Joined: Tue Aug 21, 2007 10:30 am
Contact:

Re: Updating body verts

Post by Michael Buckley »

If you're looking to setup the collisions in an editor, you probably don't want the editing process to use Chipmunk. What you're going to want is to create an editor which stores the vertices however you want, and then creates a cpPolyShape after you are finished editing. Of course, there are a couple of gotchas when you create the cpPolyShape. First, the vertices must be specified in a counterclockwise order, which may be different from the order that they were created in the editor, and second, they must be convex, so you may have to break the polygon from your editor into multiple cpPolyShapes. You also won't be able to edit the cpPolyShapes once they are created. If you need to change the shape, you'll need to remove the current shape and create a new one.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Updating body verts

Post by slembcke »

As was said, if you want to change the shape, you have to delete the old shape and make a new one. Chipmunk does not currently support deformable collision shapes. Doing so would be very difficult and would probably require a rewrite of much of the library.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests