[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 - Understanding applyImpulse

Understanding applyImpulse

Official forum for the .

Understanding applyImpulse

Postby kendric » Sun Mar 22, 2009 1:59 pm

I am trying to understand applyImpulse. I have circle shapes and I want to push them without adding any angular velocity. I thought if I just applied an impluse directly at their center, with the force vector being the direction I want them to move , they would do so. But they start spinning. On reading the boards, I see people talking about the force vector being in world co-ordinates vs object co-ordinates. My question is, how is the force vector in a co-ordinate system? Isn't it just X=horizontal component of the force and y=vertical, ie a force vector of 5,5 would be a northeast(in opengl) pushing force of strength 5?
Clearly I don't have this down quite right.
I also tried applying the impulse at a position which is shifted from the center by a inverse of the force vector * my radius but that didnt do it either.

Thoughts?

Updated, Ok I figured out what I was misunderstanding here I think. If somebody can correct me, the 2 vectors you pass are the start and end point of a line that represents the push on the object. The longer the line the bigger, and the point of impact of the line with the shape determines what happens as far as rotation vs velocity etc.

So the only question I have left now is whats the correct force to apply to a circle to make it rotate without making it move. I was trying vertical forces along the circles edge, kinda like a hand hitting a wheel to spin it, but it still gets bumped forward. Should I just hard set the angular momentum variable instead or is that not a good way to use this engine?

Great engine btw, thanks !
kendric
 
Posts: 2
Joined: Sun Mar 22, 2009 1:55 pm

Re: Understanding applyImpulse

Postby slembcke » Sun Mar 22, 2009 3:46 pm

Hmm. Sounds like you are still very confused.

I apologize for using the same shorthand that the underlying physics equations use. That was a markedly bad idea on my part. People often use physics libraries so they don't have to learn that sort of stuff... <.<

cpBodyApplyImpulse(cpBody *body, cpVect j, cpVect r)

j is the impulse vector. In world space coordinates (see below) and r is the offset from the center of gravity (also in world space coordinates). If you don't want the body to rotate, use cpv(0,0) for the r (offset) parameter.

Now what are world space and body space coordinates? World space coordinates are the absolute coordinates that you probably normally just think of as "coordinates" in general. Body space coordinates are relative to a body (rotation and position. This means that (0,0) will always be at the center of gravity of the body and everything else rotates around the center of gravity as the body rotates. You can convert between the two using the cpBodyLocal2World() and cpBodyWorld2Local() functions.

Put in another way, it depends on what you want the force to be relative to. World space coordinates make more sense in a platformer game where "left" means to make the character move to the left side of the screen. Body relative coordinates make more sense in space games were you have thrusters attached to your ship. The position of the thruster and the direction of it's force is relative to the body. You would have to convert both values in order to use them with the cpBodyApplyImpulse() function.
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: Understanding applyImpulse

Postby kendric » Sun Mar 22, 2009 6:46 pm

Hey. I think your using world space co-ordinates wording in a way thats confusing. If you want to give offset from center of gravity, and you say you want it in world space co-ordinates, then the value that would mean right in the center would be body->p. Anything in worldspace co-ordinates in other gui framworks means relative to 0,0 (ie absolute). Relative co-ordinates would be relative to body. So a 0,0 center of gravity would be relative to the body if its at its center. Does that help? So for the force vector, this is where my confusion came in. If you say the force vector is in world space co-ordinates, then if my body is at 150, 150 and you give a 5,5 vector in world space co-ordinates it means that the vector represents the offset of 5,5 from the axis, which is 145 units away from the body.

I got the no rotation push working, how would i do a rotation only push? Ie spin a circle without moving it?
Thanks again.
kendric
 
Posts: 2
Joined: Sun Mar 22, 2009 1:55 pm

Re: Understanding applyImpulse

Postby ker » Mon Mar 23, 2009 6:44 am

ker
 
Posts: 56
Joined: Tue Jul 15, 2008 4:13 am

Re: Understanding applyImpulse

Postby maximile » Tue Mar 24, 2009 1:04 pm

Chipmunk's use of world-space and object-space is standard with other frameworks. But IIRC some versions of the documentation had them the wrong way round on that function. Perhaps that's the problem here.
maximile
 
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 3 guests

cron