Access rays cast by Box2D Lights

248 Views Asked by At

I am currently developing a game with the Box2D lights library and LibGDX.

Everything is currently fine, however, I'm having difficulty accessing the rays from the ConeLight.

I wish to stop rendering objects if they are not in the ray of the light. Is there any way to access the rays the library is casting so I can work out if an object is in the way of the light?

A quick search through the JavaDocs and the internet yielded no results. Maybe through reflection?
Methods like light.setContactFiltering() exist however they only stop certain objects from getting affected by the light.

I do not wish to ray cast myself to detect objects but instead, try to access the existing rays cast in order to try and save computational power.

Thank you for the help!

2

There are 2 best solutions below

0
Ryan_DS On BEST ANSWER

After some more research, I realized I skipped over a method in the Light class.

If anyone wants to check if a point is within a light, you can use light.contains(x,y)

Hope this comes in handy.

0
Andreas Toresäter On

You can use the Box2D RayCasting from the source of the light in the direction of the light and see what it hits. If circumstances is right you could also use the built in Frustum culling in libGDX Cameras