Page 1 of 1

Replacement for old functions?

Posted: Tue May 10, 2016 2:16 am
by Hexasoft
Hello, again me porting some old pieces of code to Chipmunk 7.

I have some functions that are no more present in v7, and I can't find in the doc a way to replace them (I still found that "Vel" or "Pos" were replaced by "Velocity" and "Position").
- cpShapeSetLayers(body-pointer, NOT_GRABABLE_MASK); → I can't remember why this was in my code but this function don't exists anymore
- body limits : cpBodySetVelLimit(…) and cpBodySetAngVelLimit(…) → I found useful to limit that values to reasonable stuff (i.e. in a "ball" game). I guess I can get/modify these values according to the limits I decided during process but maybe a better way exists

Thanks!

Regards,
--
Hexasoft

Re: Replacement for old functions?

Posted: Tue May 10, 2016 9:56 am
by slembcke
Layers were replaced by categories and category masks which are more powerful. Both are a value on cpShapeFilter, and you can set it using cpShapeSetFilter(). You can emulate the layer functionality exactly by setting both the category and mask to your old layer value.

The velocity limits were removed because they were so basic as to be useless for many. For instance, you might want to limit downward velocity, but not upwards or horizontal velocity. They are pretty easy to implement on your own using a velocity update function.

Code: Select all

void MyVelocityUpdate(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt){
  // Have Chipmunk do the regular velocity update.
  cpBodySetVelocityUpdateFunc(body, gravity, damping, dt);

  // Then apply your own extra sauce.
  // Clamp the velocity, etc.
}

// Then somewhere set the function on your body.
cpBodyUpdateVelocity(body, MyVelocityUpdate);

Re: Replacement for old functions?

Posted: Wed May 11, 2016 2:14 am
by Hexasoft
Thanks for these informations. I will try this in my code.

Regards,
--
Hexasoft