azfalot / rokon

Automatically exported from code.google.com/p/rokon
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

fixtureDef.filter doesn't work #148

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.density = 1;
fixtureDef.friction = 0;
fixtureDef.filter.groupIndex = -1;
fixtureDef.restitution = 1;
createDynamicBox(fixtureDef);

What is the expected output?
my game sprites don't collide with each other

What do you see instead?
they still collide

What version of Rokon are you using?
new trunk

On which version of Android are you experiencing this?
1.5

Please provide any additional information below.
It seems that fixtureDef.filter.groupIndex = -1, I have also used c++ box2d 
before, and I confrim that negative means never collide.
Then I have tried to set categoryBits and maskBits, it doesn't work either.

Original issue reported on code.google.com by rayjun...@gmail.com on 25 Aug 2010 at 9:53

GoogleCodeExporter commented 8 years ago

Original comment by rtaylor205@gmail.com on 4 Sep 2010 at 3:20

GoogleCodeExporter commented 8 years ago
I have fixed the problem:
World.java:
private boolean contactFilter( long fixtureA, long fixtureB )
    {
        if( contactFilter != null )
            return contactFilter.shouldCollide( fixtures.get(fixtureA), fixtures.get(fixtureB));
        else
        {
            Filter filterA = fixtures.get(fixtureA).getFilterData();
            Filter filterB = fixtures.get(fixtureB).getFilterData();                    

            if (filterA.groupIndex == filterB.groupIndex && filterA.groupIndex != 0)
            {
                return filterA.groupIndex > 0;
            }

            boolean collide = (filterA.maskBits & filterB.categoryBits) != 0 && (filterA.categoryBits & filterB.maskBits) != 0;
            return collide;
        }
    }

Filter.java:
public short categoryBits = 0x0001;

public short maskBits = -1;

public short groupIndex = 0;

Original comment by rayjun...@gmail.com on 14 Sep 2010 at 1:15