[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/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/bbcode.php on line 112: 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 - Resizing cpShape

Resizing cpShape

Official forum for the .

Resizing cpShape

Postby Ben » Fri Jan 30, 2009 7:34 am

Hi all,

I've been happily muddling along with Chipmunk (and cocos2d as well) and have hit a bit of a wall.

In my application, I have a rectangle made of four cpShape segments. I'd like to be able to resize this rectangle (so that it gives the appearance of growing), but can't for the life of me figure out how to do that because I keep getting lost in a maze of shape struct definitions. Does anyone have any suggestions on how best do achieve this?
Ben
 
Posts: 5
Joined: Fri Jan 30, 2009 6:36 am

Re: Resizing cpShape

Postby ker » Fri Jan 30, 2009 9:35 am

So far modifying any chipmunk objects in an undocumented way has been discouraged in this forum. I don't think that's gonna change.

A few month ago someone had a similar request (i think with circles). The suggestion was to remove the shape and create a new one every frame (if I remember correctly).

If your rectangle is supposed to be static (not movable by other objects) and if you don't want to resize your rectangle for more than twice it's original size, there's a way to "cheat". You could create two segments for each side of the rectangle (same length, same everything, just not colliding with each other) and move them in opposite directions. That way it will look like that side is growing. Every side-segment would need it's own body then (or you could combine left-top right-top2 right2-bottom bottom2-left2).

If you really really want to mess with the internal data structure I could still give you some tips, but I don't recommend it at all.
ker
 
Posts: 56
Joined: Tue Jul 15, 2008 4:13 am

Re: Resizing cpShape

Postby Ben » Fri Jan 30, 2009 1:23 pm

Thanks for your reply there ker, that's pretty much what i was afraid of. Your reply has actually made me think this through a bit further though.

It's not essential for the rectangle to be static, as the space it's in has no gravity, and it will be set to ignore all collisions. So, probably the next easiest thing to do would be to make the rectangle be a cpPolyShape, and modify the vertexes on each step. I know that's reaching inside the object still, but it's a lot simpler than what I was thinking before. Does this perhaps seem a better way than recreating the object on each step?
Ben
 
Posts: 5
Joined: Fri Jan 30, 2009 6:36 am

Re: Resizing cpShape

Postby ker » Fri Jan 30, 2009 1:49 pm

if you don't want collisions, why create a chipmunk-shape at all?

Yea, I'd use a cpPolyShape.. fewer stuff to update. Even thou I think it's harder to manually update than cpSegmentShape is.

You could attempt to reinitialize your shape using cpPolyShapeInit. I'm not sure thou if that will cause memory leaks. You might also destroy some important data set by cpSpaceAddShape. You'd also need to reset your normal cpShape data like elasticity and friction.

If you modify directly, remember that there are values that you'll have to calculate and set (some precalculated data which cpPolyShapeInit generates for your input data).

You could look at the source of cpPolyShapeInit and create something that only initializes the data you want to be initialized. If that works very well others here might be interested in that, too.

Be careful with any of these methods, they might go mad if you update chipmunk to a newer version.
ker
 
Posts: 56
Joined: Tue Jul 15, 2008 4:13 am

Re: Resizing cpShape

Postby Ben » Fri Jan 30, 2009 2:30 pm

Ben
 
Posts: 5
Joined: Fri Jan 30, 2009 6:36 am

Re: Resizing cpShape

Postby slembcke » Fri Jan 30, 2009 4:06 pm

Yeah, Chipmunk doesn't really let you modify shapes on the fly in a way that would be physically realistic as if the surface was actually moving. This is actually a pretty hard thing to do in general. I'm mostly opposed to changing shapes on the fly in Chipmunk because it can't resolve new overlaps using real physics. Overlaps are solved by moving the objects apart, but not giving them a real velocity. Abusing this can lead to some odd looking behavior.

On the other hand, it often times does look just fine because the use wasn't to have "realistic" physics in the first place. Maybe they only wanted collision detection like you. I've considered adding an "unsafe" API (in a separate header and with a big disclaimer) that would allow people to do things like change shapes on the fly.

I would recommend going the route where you recreate the shape each time it changes. That is at least following the API and won't break if I change the data structures. It won't make the physics be accurate though (which you don't seem to care about anyway).
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: Resizing cpShape

Postby Ben » Mon Feb 02, 2009 8:24 am

Thanks again for the suggestions. The method I've chosen is to recreate a cpPolyShape on each step, it's fast enough and the array of vertices is easy to store (outside the shape) and modify. I'm not sure why you say the physics will not be accurate though, as they seem fine so far.
Ben
 
Posts: 5
Joined: Fri Jan 30, 2009 6:36 am

Re: Resizing cpShape

Postby slembcke » Mon Feb 02, 2009 2:25 pm

The physics do not act accurately because changing an object carries no information about the velocity of the surface of the object. Other things will get pushed away because Chipmunk solves overlaps by directly modifying the positions of objects, but does not use a real persistent velocity 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: Resizing cpShape

Postby pabloruiz55 » Wed Mar 31, 2010 1:00 pm

If i use this method of removing / re-adding the shape every step, or at some point, is it possible for the app to crash at a given momment? For example if the shape was removed just when a collision was about to be triggered?

Thanks
pabloruiz55
 
Posts: 22
Joined: Mon May 18, 2009 7:31 pm

Re: Resizing cpShape

Postby slembcke » Wed Mar 31, 2010 4:45 pm

Shapes are added and removed outside of the simulation step, so it shouldn't matter.
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 5 guests

cron