Page 1 of 1

Angular velocity limit not applied in cpBodyApplyImpulse

Posted: Sun Aug 22, 2010 9:59 am
by dnils
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!

Re: Angular velocity limit not applied in cpBodyApplyImpulse

Posted: Mon Aug 23, 2010 8:57 am
by slembcke
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.

Re: Angular velocity limit not applied in cpBodyApplyImpulse

Posted: Mon Aug 23, 2010 2:07 pm
by dnils
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?

Re: Angular velocity limit not applied in cpBodyApplyImpulse

Posted: Mon Aug 23, 2010 3:57 pm
by slembcke
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.