Angular velocity limit not applied in cpBodyApplyImpulse

Discuss any Chipmunk bugs here.
Post Reply
dnils
Posts: 2
Joined: Sun Aug 22, 2010 9:49 am
Contact:

Angular velocity limit not applied in cpBodyApplyImpulse

Post 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!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Angular velocity limit not applied in cpBodyApplyImpulse

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dnils
Posts: 2
Joined: Sun Aug 22, 2010 9:49 am
Contact:

Re: Angular velocity limit not applied in cpBodyApplyImpulse

Post 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?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Angular velocity limit not applied in cpBodyApplyImpulse

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests