attaching PointDef to body and calling getShapestInContact

Discuss issues specific the Java port of Box2D
Posts: 11
Joined: Fri Oct 02, 2009 3:15 am

attaching PointDef to body and calling getShapestInContact

Postby kristianlm » Mon Oct 12, 2009 10:45 am

hi there!

I want to make quick tests around my shapes (they need to be fast so I guess point tests are the way to go) to try and get them to detect collisions beforehand and steer away, check out the steering behaviours here:, a cool guide!

Code: Select all

PointDef pd = new PointDef();
pd.localPosition = new Vec2(0, 1f);
pd.filter.categoryBits = 1;
pd.filter.maskBits = 0xFF;
pd.isSensor = true;
pd.mass = 1f;
pd.density = 1f;
testShape = body.createShape(pd);

testing against the shape:

Code: Select all

        Set<Shape> set = testShape.getShapesInContact();
       System.out.println(testShape + " touching " + set);
        for( Shape shape : set) {
           Vec2 pos = shape.getBody().getWorldCenter();
           System.out.println("userdata " + shape.getUserData());
            ToolGL.point(gl, pos);

so what I did was add a PointDef on my steering body. Then I call getShapesInContact to see if there is an overlap on the point. However, the getShapesInContact does not return correct information - it seems to be returning shapes as if ignoring the body's world position.

So I guess either, this isn't implemented, not ported, or I am using PointDef wrong? When I replace PointDef with PolygonDef and modify to make a small box, it works.

I apologize if this is not a JBox2D issue and I am posting under the wrong category.
Thanks! Kris

Posts: 356
Joined: Mon Jun 08, 2009 12:21 pm

Re: attaching PointDef to body and calling getShapestInContact

Postby toucansam » Mon Oct 12, 2009 6:07 pm

I would try using sensors, and then look for the shape (as a sensor) in your contact listener to check for contact

Return to “Java”

Who is online

Users browsing this forum: No registered users and 1 guest