Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx Make Lights Ignore Bodies

Tags:

java

libgdx

box2d

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);
like image 868
Oonej Avatar asked Dec 15 '22 06:12

Oonej


1 Answers

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)

like image 57
aug13 Avatar answered Dec 31 '22 13:12

aug13