I have a libgdx game in the works with Box2d and Box2d Lights.
My questions is how do I get Bodys / Bodydefs to ignore the light source from a Box2d Light and not cast shadows?
Thanks.
PolygonShape groundBox = new PolygonShape();
groundBox.setAsBox(2f, 2f);
FixtureDef gridBox = new FixtureDef();
gridBox.shape = groundBox;
gridBox.density = 1.0f;
gridBox.filter.groupIndex = GRID_GROUP;
gridBox.filter.categoryBits = GRID_CAT;
gridBox.filter.maskBits = GRID_MASK;
bodyDefs[i][j] = new BodyDef();
bodyDefs[i][j].position.set(j*factor + factor, i*factor + factor);
bodyDefs[i][j].fixedRotation = true;
bodyDefs[i][j].type = BodyDef.BodyType.DynamicBody;
bodies[i][j] = world.createBody(bodyDefs[i][j]);
bodies[i][j].createFixture(gridBox);
handler = new RayHandler(world);
handler.setCombinedMatrix(camera.combined);
Filter filter = new Filter();
filter.groupIndex = GRID_GROUP; // GRID_GROUP = 1
filter.categoryBits = GRID_CAT; // GRID_CAT = 0x0001;
filter.maskBits = GRID_MASK; // GRID_MASK = 1;
new PointLight(handler, 1000, Color.RED, 2000, 0, height);
PointLight.setContactFilter(filter);
You can use the following method :
cone.setContactFilter(categoryBits, groupIndex, maskBits);
where cone is an object of type ConeLight. Now this light will ignore the bodies having the specified categoryBits,groupIndex and the maskBits.
You can set the categoryBits,groupIndex and the maskBits through the body's fixture in the following manner-
fixture.filter.categoryBits = your value;
(categoryBits : The collision category bits. Normally you would just set one bit.)
fixture.filter.groupIndex = your value;
( groupIndex: Collision groups allow a certain group of objects to never collide (negative) or always collide (positive). Zero means no collision group. Non-zero group filtering always wins against the mask bits.)
fixture.filter.maskBits = your value
(maskBits:The collision mask bits. This states the categories that this shape would accept for collision.)
If you wish some bodies to ignore ALL LIGHTS.then you can use the following Light.setContactFilter(categoryBits, groupIndex, maskBits)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With