I recently started a little hobby project: try to get Box2D running inside ShiVa 3D with support for PC, iOS and Android.
Here is the result so far: http://www.youtube.com/watch?v=Nj4F4IvrWTw
- Body properties wrapped
- Shapes wrapped: box, circle, poly, (also compound shapes are possible)
- Optional collision callbacks per object
- Mouse joint
- Collision groups
- iOS: iPod Touch 4g (60FPS)
- Android: HTC Desire (60FPS)
Special Note: All objects are composed in the scene! No additional object creation via script required … well, sort of
A bit more detail …
My main goal is to be able to create physic game prototypes as fast as possible. This means for me, as much WYSIWYG as possible. Take that stack of crates for example: I don’t want to write a for-loop and create them via script, I want to create them inside the ShiVa-viewport. Otherwise I could simply use the Box2D-Testbed and wouldn’t need the wrapper in the first place.
This led me to the following ShiVa-model setup:
- Each model must have one Box2D-body-AI (typically a helper object).
- The model with the Box2D-body-AI can have numerous children which have Box2D-shape-AIs. This way you can also create compound shapes, like the three linked crates you also see in the video.
Here is a screenshot showing these two AI-models as well as the model hierarchy:
So for the “stack of crates”-model (image on the left), I first created a box model and set that up (the two AI models as mentioned above). Then in the “stack of crates”-model, I simply stacked multiple box models. And this can now be used in the actualy scenes anytime I want. The body/shape-AI-models expose all needed properties to setup those objects. If value changes at runtime are needed, I’ll create some scripting functions for that. I don’t have a real list yet, my plan is to create a game, and create the functions on the fly as I need them (just in time, not just in case ).
For runtime object creation, there will also probably be some factory functions, like “box2d.createSimpleBox”, but my suggested way of creating runtime objects is to create your model-templates and then just write scene.createRuntimeObject … you get what I mean
This wraps up my first post about the Box2D-ShiVa plugin. I have no eta and currently no plan how and when it will be available for public. After all, this is currently a hobby project. In my next posts, I’ll cover how the scripting API looks like to set things up and how I got Box2D to compile inside a ShiVa plugin for Android, which was a bit tricky – at least for me, as I am no build/make file guru …
Last, but definitely not least: big thanks go to NiCoX from Stonetrip, for giving me some awesome tips on how to structure the plugin. Thanks!