[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - cpBody/Shape break on collision

cpBody/Shape break on collision

Official forum for the .

cpBody/Shape break on collision

Postby kosa_nostra9 » Tue Apr 03, 2012 10:56 pm

Hello all,

I'm working with chipmunk and cocos2d. My question is how to make a body/shape broke on impact. My guess was to identify the point of a collision on the shape, and then, divide the shape into two shapes accordingly in the pre-solve collision callback.
But I'm really not sure, is there any better way to do this ?
And how can I get the collision point coordinates in the shape space coordinate ? Using the cpContact array in the cpArbiter gives me coordinates of collision within the entire space.

Hope I have been clear enough.
Regards,
Kosa
kosa_nostra9
 
Posts: 17
Joined: Sun Feb 26, 2012 9:54 pm

Re: cpBody/Shape break on collision

Postby slembcke » Wed Apr 04, 2012 10:12 am

I've been meaning to make a demo of this because it sounds like a lot of fun. Haven't gotten around to it, or a ton of other things though. :(

Anyway. You can convert the contact points to body coordinates (shapes are always expressed in body coordinates) using the cpBodyWorld2Local() function. The Slice demo shows how to split up a polygon and recalculate the mass/position properties of the new shapes. Also keep in mind that you cannot add/remove shapes in a collision callback, and need to schedule a post-step callback to do it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: cpBody/Shape break on collision

Postby kosa_nostra9 » Wed Apr 04, 2012 12:40 pm

Thank you for your answer, I'll give it a try later and will le you know how it goes
kosa_nostra9
 
Posts: 17
Joined: Sun Feb 26, 2012 9:54 pm

Re: cpBody/Shape break on collision

Postby kosa_nostra9 » Wed Apr 04, 2012 6:14 pm

Hey !

So I've implemented something which works pretty well. I have a question though, when the collision occurs, I consider the arb->contacts->p point. But abr->contacts is an array of points, so why an array ? Also, what is numContacts in the cpArbiter structure ?

Thank you !
kosa_nostra9
 
Posts: 17
Joined: Sun Feb 26, 2012 9:54 pm

Re: cpBody/Shape break on collision

Postby slembcke » Thu Apr 05, 2012 8:46 am

It's an array because the collision between two objects often has more than one contact point. When you have a box sitting on the ground, each corner of the box has a contact point.

Also, don't access the members of cpArbiter directly unless you understand that is the private API. (Actually, you should only be able to access that if you specifically enabled private access.) I highly recommend using the public API for that: http://chipmunk-physics.net/release/Chi ... Properties
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: cpBody/Shape break on collision

Postby kosa_nostra9 » Thu Apr 05, 2012 2:06 pm

Hey thank you, I start to understand a bit better.
Now I have a question on the depth parameter. In my game, some collision are very violent and I end up with depth penetration of -100 sometimes. My question is how to "remove" this from the collision point in order to get the point on the edge of the body being hit. Do I have to use the normal here ?

Thank you again for your help !
kosa_nostra9
 
Posts: 17
Joined: Sun Feb 26, 2012 9:54 pm

Re: cpBody/Shape break on collision

Postby kosa_nostra9 » Thu Apr 05, 2012 2:18 pm

Well, I think I have figured this out even though I don't really understand:

cpBodyWorld2Local(b1->body, cpvadd(p, cpvmult(n, d/2)))

With p, the collision point, n the normal, and d the depth. Not sure why dividing the depth by 2 give me exactly what I was looking for...
kosa_nostra9
 
Posts: 17
Joined: Sun Feb 26, 2012 9:54 pm

Re: cpBody/Shape break on collision

Postby slembcke » Thu Apr 05, 2012 4:00 pm

Depth is the amount of overlap, but not necessarily the distance of the collision point from any particular surface. If you want the closest point on the shape, you have to calculate that yourself, sorry. It's fairly trivial to do for circles and segments, for polygons, just take the closest point to any segment on the perimiter.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 4 guests

cron