1

I'm writing game similar to Don't Starve using Libgdx and Box2Dlights. I have a flat-surface world with some billboarded objects on this surface. So the perspective camera is used. The angle between the normal to the screen and the normal to the surface(ground) is 45°. Some of these objects emit light to all directions (campfires). So RayHandler class is used to deal with those. The method which sets the combined matrix of the RayHandler requires the viewport width and hight. When the viewport of the perspective camera is passed to this method the rendered light disappears once its center is off the screen. What should be done to achieve the light disappearing only when it's completely off the screen(not just the center) so that the user doesn't see the moment it disappears? Thank you.

UPDATE:

Method rayHandler.setCombinedMatrix(camera); requires OrthographicCamera. The camera I use is perspective. That's why it's impossible for me to use rayHandler.setCombinedMatrix(camera). The only option left for me is using setCombinedMatrix(Matrix4 combined, float x, float y, float viewPortWidth, float viewPortHeight). I can pass the combined matrix of the PerspectiveCamera with its position and viewport here, however it doesn't give the desired result as it still gives an incorrect viewport (probably since it doesn't consider the fact that the camera is in 3D space and is inclined).

1 Answers1

0

As you didn't provide any code just some background that may help you: The rayhandler uses culling to safe performance: It doesn't render lights that are of the screen. The screen bounds are calculated by the input of

rayHandler.setCombinedMatrix(camera);

which you have to keep up-to-date by calling it in your render() method just before rayHandler.updateAndRender().

https://github.com/libgdx/box2dlights/wiki/How-To

Sebastian
  • 5,721
  • 3
  • 43
  • 69
  • That's right, but this method requires **OrthographicCamera**. The camera I use is perspective. That's why it's impossible for me to use `rayHandler.setCombinedMatrix(camera)` The only option left for me is using `setCombinedMatrix(Matrix4 combined, float x, float y, float viewPortWidth, float viewPortHeight)` I can pass the combined matrix of the **PerspectiveCamera** with its position and viewport here, however it doesn't give the desired result – Aleksei Rozhnov Aug 26 '16 at 15:17