Sebastian Zeki
Sebastian Zeki

Reputation: 6874

How to get the list of body co-ordinates in my box2d world in Processing

I need to get the list of co-ordinates for my box2d world- I'm trying to get a wrap around effect so that particles that go off the side of the screen appear on the opposite side. box2d is not well documented for Processing and the only example I could find was in java (I know its the parent language but it needs translating). This is here.

I think the action is here:

private function updateWorld(e:Event):void {
            world.Step(1/30,10,10);
            world.ClearForces();
            for (var b:b2Body=world.GetBodyList(); b; b=b.GetNext()) {
                if (b.GetType()==b2Body.b2_dynamicBody) {
                    if (b.GetJointList()==null) {
                        if (b.GetPosition().x*worldScale>640) {
                            b.SetPosition(new b2Vec2(0,b.GetPosition().y));
                        }
                        if (b.GetPosition().x*worldScale<0) {
                            b.SetPosition(new b2Vec2(640/worldScale,b.GetPosition().y));
                        }
                    }
                }
            }
            world.DrawDebugData();
        }

So I have tried translating this although I get stuck at the point of world.GetBodyList I assume world is the instantiated box2d world I have created. I that is so, Processing doesn't seem to recognise this. Basically how to I just get an array of all the particle co-ordinates. Should be easier....

Upvotes: 0

Views: 698

Answers (1)

Kevin Workman
Kevin Workman

Reputation: 42176

Anything you can do in Java, you can do in Processing. But the code you posted is not Java. It's C++. (Edit: George pointed out that it looks like ActionScript. Either way, it's not Java!)

  • Box2D is the original library, written in C++. Your code is an example of using that library.
  • JBox2D is a Java wrapper of the C++ library, so you can write Java code that interacts with the C++ library.
  • Processing is written in Java, so you can use JBox2D in Processing.
  • Processing also has a few libraries that simplify JBox2D, like Daniel Shiffman's Box2D for Processing or BoxWrap2d.

You don't need to use these libraries in order to use JBox2D from Processing.

You can find the documentation for JBox2D here.

To answer your question, yes, the world variable would be the instance of World you created when you set up your physics environment.

If you're using one of the Processing libraries, the creation of the World instance might be hidden from you. You might have to use JBox2D directly yourself.

Upvotes: 1

Related Questions