Angular velocity limit not applied in cpBodyApplyImpulse

Discuss any Chipmunk bugs here.

Angular velocity limit not applied in cpBodyApplyImpulse

Postby dnils » Sun Aug 22, 2010 9:59 am

Hello,

I noticed that the angular velocity limit of cpBody (w_limit) is only applied in cpBodyUpdateVelocity but not in cpBodyApplyImpulse. I did a small patch:

Code: Select all
static inline void
cpBodyApplyImpulse(cpBody *body, cpVect j, cpVect r)
{
   cpFloat w_limit = body->w_limit;
   body->v = cpvadd(body->v, cpvmult(j, body->m_inv));
   body->w = cpfclamp(body->w + body->i_inv*cpvcross(r, j), -w_limit, w_limit);
}


Seems to fix the issue for me, but there might be something that I've missed (i.e. perhaps it should not be applied here for other reasons?).

Thanks a lot for creating a very useful library!
dnils
 
Posts: 2
Joined: Sun Aug 22, 2010 9:49 am

Re: Angular velocity limit not applied in cpBodyApplyImpulse

Postby slembcke » Mon Aug 23, 2010 8:57 am

It's not really a bug. That's the way it should work for the collision solver.

If you want to make a clamped one you could write a second function I guess. You really should be clamping the velocity as well if that's what you wanted.
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: Angular velocity limit not applied in cpBodyApplyImpulse

Postby dnils » Mon Aug 23, 2010 2:07 pm

Thanks for the reply!

Ah, yes, that is true, the velocity should be clamped aswell. I figured I must had misunderstood something regarding the function. Are there any dangers with doing this, perhaps with regards to numerical stability or something?
dnils
 
Posts: 2
Joined: Sun Aug 22, 2010 9:49 am

Re: Angular velocity limit not applied in cpBodyApplyImpulse

Postby slembcke » Mon Aug 23, 2010 3:57 pm

It would probably cause problems for the solver and slow it waaaaaaaay down if you modified that header before compiling Chipmunk.

The intended purpose of the velocity clamping is to impose soft limits for things like falling speed for a platformer game. If you need hard limits you probably need to make a constraint to handle that.
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 Bugs

Who is online

Users browsing this forum: No registered users and 1 guest

cron