Transition from box2d-js to Box2DWeb

68 views
Skip to first unread message

Dimitri

unread,
Mar 25, 2011, 10:11:06 PM3/25/11
to Box2dWeb
Hi there,

First off, thanks for this. I've been trying to make the transition
from box2d-js to your port since it's based on a newer version of
box2d and as expected I've run into some hurdles. I'm not sure how
many other folks might go through the same process, but I was
surprised at how different the versions are. I pretty much had to
rewrite most of the code that interfaces with box2d. Here are some of
the issues I ran into:

- box2d-js has no concept of fixtures
- box2d-js uses prototype which does not work well with Box2dWeb
because of a similar problem with the for in loops as you posted with
ext js. I actually made a change to the Box2dWeb code to get it to
work:

I had to change this line of code in Box2dWeb (line 2498):

for (var each in __this.m_moveBuffer) {
queryProxy = __this.m_moveBuffer[each]; {

to:

for (var i = 0, len = __this.m_moveBuffer.length; i < len; i++) {
queryProxy = __this.m_moveBuffer[i]; {

- When rendering, box2d-js gives you the world positions of the
vertices of your shapes where as Box2dWeb gives you the original local
vertices and then you can apply the angle from the body, with some
trigonometry magic. Maybe I'm missing something, but I found it odd
that now this calculation needs to be done on the rendering side.

I realize most of these issues are just due to the different versions
of box2d that were ported. As far as performance, goes it's probably
still a bit early to tell since I'm still dealing with some issues,
but right now it appears to be a bit slower than box2d-js. Is that
possible? Or, is it more likely I'm doing something wrong? That's
what I'm hoping because I would much rather use this newer port so I
can take advantage of some of the newer features.

In any case, great work for getting this going!

Thanks,

Dimitri

Curious Aaron

unread,
Mar 29, 2011, 10:57:51 AM3/29/11
to Box2dWeb
Hi, Dimitri. Thanks for sharing. I'm making the transition from
Box2DFlash to Box2dWeb, so I'm trying to get familiar with the
differences, too. Right now, I'm trying to find a working example of
joints since nothing I have tried has worked so far. Have you had any
luck with joints?

fishbone

unread,
Mar 30, 2011, 10:59:40 AM3/30/11
to Box2dWeb
I can't say much about the transition, since I never really looked
into Box2d-js in detail. So, thanks for sharing your experience.

I'm currently replacing the for/each loops in trunk.

> When rendering, box2d-js gives you the world positions of the
> vertices of your shapes where as Box2dWeb gives you the original local
> vertices and then you can apply the angle from the body, with some
> trigonometry magic. Maybe I'm missing something, but I found it odd
> that now this calculation needs to be done on the rendering side.

Then I'm not the only one who had problems with drawing :) . But it
wasn't my decision - Box2dWeb is ported from Box2dFlash.

> As far as performance, goes it's probably
> still a bit early to tell since I'm still dealing with some issues,
> but right now it appears to be a bit slower than box2d-js

It's very hard to tell whether Box2dWeb is faster or slower than
Box2dJs. The first dev builds seemed to be a bit faster until I fixed
a bug which influenced behavior. Also, increasing the gravitation
makes everything "looking faster", as well as different drawing
scales.
Secondly, you cannot measure FPS in browsers, since rendering-rates
are different from timer execution rates.
I think that the physics engine performs very fast itself (thanks to
Erin Catto's great work). The actual bottle neck is always rendering.

Thanks for your compliments ;)

Cheers,
Uli

fishbone

unread,
Mar 30, 2011, 11:02:09 AM3/30/11
to Box2dWeb
I commented on your joint example on the "Basic Usage"-page, it
contains an error.
Reply all
Reply to author
Forward
0 new messages