Integrating Box2D on our framework

Hi everyone

I'm Vlad from Vortix Games and I'm in the process of integrating Box2D in our framework Bold Pixel Engine allowing easy integration of Display Objects and our in-house blit engine with physics provided by Box2D. Everything is going fine, but since I think I'll have many doubts, I decided to create an account and say hi.

I had a question already... but I forgot... so I'll be back in a bit. 🙂
Hi, some 'proper' questions.

So I have these objects (called Entity in our framework) that are managed through an object pool mostly because these Entity objects can have a bunch of objects in it, so creating and deleting these is better handled with this pattern.

If I have an Entity that has a b2Body encapsulated and if that Entity is reused, is there a way to reuse the b2Body or should I simply create a new one when I reuse my object?

Can I clone (copy) b2Body objects?

I know that if I apply a force or an impulse I'll get movement, but is it possible to do the opposite, meaning to move an object in the world and convert that movement into force?

Thanks in advance
You can re-use a body by resetting everything on it, but I wouldn't recommend it.

You can clone bodies by using body.GetDefinition() to copy properties, then looping over fixtures and using fixture.GetDefinition() too.

The opposite is not possible nor useful. Forces exist purely for the purpose of generation motion - they aren't read anywhere in the library. But generating velocities from positions is possible, and useful (e.g. for kinematic bodies). Simply set velocity to (newPos - oldPos) / timeStep.
Thanks, it makes perfect sense.

I'm going to think how I can implement what's in my head and get back. Thanks!
Hey everyone, sorry to keep posting questions almost one-by-one, but I hope that since I'm keeping everything in this thread it will be less troublesome.

What is the difference between kynematic and dynamic body types?
Assuming I would use Box2D to all my collision and movement needs, what would be the best strategy if I didn't want collision response on any body?
To answer your questions in reverse order, if you want collision detection but no collision response then use a sensor. As for difference between kinematic and dynamic; Kinematic is a static object that can be moved around by setting velocity, in effect allowing you to animated static bodies. It will produce a collision response in dynamic bodies, but will not receive forces itself.
Thanks, but my question is a bit broader than that. What if no body would have collision responses? Would it be the best practice to make all sensors? Is that it?

Thanks in advance
Hmm, if you aren't going to have collision response then it seems like box2d would be a bit overkill for you. However, if you are dead set on it then I think sensors are your only option. You can't use filter masks or groups because that won't even produce a collision detection.
If you don't need all of the joints, you could probably build a light weight integrator and broadphase for your own collision detection system and it would be more performant.
You are probably right, but the idea is, if I'm going to have Box2D completely wrapped in the framework, creating a separate collision package just to skip Box2D is even more work.

Basically I'm thinking about creating three states:
1. None: This wouldn't have a Box2D world created
2. Collision: This would have a Box2D world created but bodies (the wrapped version of it) would always be sensors since I'd basically pass a flag
3. Physics: The usual thing

Since I'm wrapping everything Box2D related in the framework, this would simply be a flag that I would pass to the created objects automatically. Maybe it's not as smart as I'm thinking it is, but not only the framework is very immature in terms of collisions (basically circle and rectangular collisions) as it also feels right.
Ok, that sounds like a decent way to do it actually. You should probably set fixedRotation to true; if they bodies aren't going to collide with anything then no reason to rotate.

Original thread: https://box2d.org/forum/viewtopic.php?t=4549