[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 - Scale or create cpShape base on cocos2d CCScaleTo action?

Scale or create cpShape base on cocos2d CCScaleTo action?

Official forum for the .

Scale or create cpShape base on cocos2d CCScaleTo action?

Postby rainyday » Mon Mar 18, 2013 12:34 pm

can we scale or create new cpShape base on cocos2d CCScaleTo action for a Sprite?

id scaleUp=[CCScaleTo actionWithDuration:0.5 scale:1.50];
id scaleDown=[CCScaleTo actionWithDuration:0.5 scale:0.50];

[sprite runAction:scaleUp];
[sprite runAction:scaleDown];
rainyday
 
Posts: 5
Joined: Wed Mar 06, 2013 7:45 am

Re: Scale or create cpShape base on cocos2d CCScaleTo action

Postby slembcke » Mon Mar 18, 2013 12:59 pm

Chipmunk shapes cannot be trivially changed. Chipmunk is a rigid body physics engine (rigid meaning that shapes do not deform).

You can use the functions in chipmunk_unsafe.h to modify an existing shape, but make sure to read and understand the comments in 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: Scale or create cpShape base on cocos2d CCScaleTo action

Postby rainyday » Mon Mar 18, 2013 2:03 pm

so the safe way is to keep remove all the shape and create new cpShape with new size to the cpBody when schedule update?

the scenario is the bullet increasing size while moving.
will it be heavy resources consuming?
rainyday
 
Posts: 5
Joined: Wed Mar 06, 2013 7:45 am

Re: Scale or create cpShape base on cocos2d CCScaleTo action

Postby slembcke » Mon Mar 18, 2013 2:25 pm

You don't want to replace the shape. That is going to make things slightly worse. It resets the contact cache when you replace a shape and has to do a bunch of other work it wouldn't normally need to. I'm not sure if it would noticeably worse if that's really an easier solution for you though. I have a hard time believing that it's not easier to just resize the existing shape though.

Performance isn't going to be a problem unless there are hundreds of them I would guess.
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: Scale or create cpShape base on cocos2d CCScaleTo action

Postby rainyday » Mon Mar 18, 2013 2:58 pm

so your suggestion is better to change the shape than creating a new one,right?
i just thinking is there a better way since changing the shape is define as unsafe.

/// Chipmunk does not have any way to get velocity information on changing shapes
may i know what does this mean?

cpShape isnt just use for collision detection?
it would affect the velocity of the cpBody?
rainyday
 
Posts: 5
Joined: Wed Mar 06, 2013 7:45 am

Re: Scale or create cpShape base on cocos2d CCScaleTo action

Postby slembcke » Mon Mar 18, 2013 4:10 pm

Replacing a shape with a different sized/shaped one has the exact same problems.

Think of an expanding ballon. It's center is not moving so its velocity is 0. It's surface, which is colliding with other objects, is moving outwards though. What those collisions need to know is that things should be getting pushed away from the center of the balloon. Instead, each frame they find that they are overlapping the balloon by some amount. Chipmunk will push them out of the balloon to fix, but not in a way that looks correct because it doesn't have any information on how the surface is moving. It only knows that the balloon's center is not moving.
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: Scale or create cpShape base on cocos2d CCScaleTo action

Postby rainyday » Tue Mar 19, 2013 4:24 am

let me see whether i understand correctly

a force apply to the balloon center
cpBodyApplyForce(balloon, force, CGPointZero);

as normal, the balloon should expand evenly in every direction
but chipmunk wont because it dont know which direction to apply force and how many force should apply
so we cant use chipmunk to simulate the expanding balloon


for my case, i just want the bullet increasing size in sprite and collision area while moving with a constant velocity

so is safe to use this?
cpPolyShapeSetVerts(bullet, numVerts, newVerts, CGPointZerooffset);

for constant velocity, i should use body->v instead of cpBodyApplyForce,right?
rainyday
 
Posts: 5
Joined: Wed Mar 06, 2013 7:45 am

Re: Scale or create cpShape base on cocos2d CCScaleTo action

Postby slembcke » Tue Mar 19, 2013 9:02 am

No, if you apply a force to the center of an object it will move in the direction of the force with no rotation.

Chipmunk is a rigid body physics engine and *only* supports rigid transformations (translation + rotation). It simply doesn't know what to do if you scale the object or do anything else beyond that. Your expanding bullet is no different than the ballon. cpPolyShapeVerts() is one of the "unsafe" functions and will have the same problems.

This only applies to the collision response though. The collisions will be caught just fine, it just might give you a strange collision response. It might work out just fine for your bullet. You really just have to try it and find out.
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: Scale or create cpShape base on cocos2d CCScaleTo action

Postby rainyday » Tue Mar 19, 2013 9:32 am

i have try using remove shape and create new one, it work fine when collision with enemy
but if i use cpPolyShapeVerts(), i cant see the red shape under debug mode

there is a strange thing when the bullet bound some times after hitting wall without hitting enemy,
the shape will scale down or scale up even the sprite stop scaling
rainyday
 
Posts: 5
Joined: Wed Mar 06, 2013 7:45 am


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests

cron