Box2D-Shiva-Wrapper: First Test

May 6th, 2012 by Christian Leave a reply »

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

Features:

  • Body properties wrapped
  • Shapes wrapped: box, circle, poly, (also compound shapes are possible)
  • Optional collision callbacks per object
  • Mouse joint
  • Collision groups

Running on:

  • PC
  • 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!

3 comments

  1. xix games says:

    Hi, this looks amazing @Christian!, i’ll give it a try…
    I would like to know if you need a pixelmap (rendermap?) to use this plugin or you can use another UI elements also…
    Thanks for the effort!
    J

  2. Christian says:

    Hi,

    I’m not sure if I totally understand your question … what do you mean with pixelmap/rendermap?
    If you are talking about the editable gui like shown in the screenshot: this is the standard gui of an AI model. You basically configure e.g. the body AI model in the scene with these gui elements and then, the AI model has an onInit method which passes the Shiva-values to the Box2D plugin. I will show the onInit code for the body and shape AI in my next blog post later this week.

    The whole process is currently a little workaround. With shiva 2.0 you should be able to create your own editor (GUI) widgets … which will offer much more possibilities.

    Hope that answers your question ;)

Leave a Reply