Libgdx view frustum culling inside actor.draw()

我的未来我决定 提交于 2019-12-04 05:35:47

问题


I am developing a little game using libgdx. It is a 2d top down game with some big maps and many objects on them. So i just want to render things in my view frustum. I have seen the camera.frustum.***inFrustum(Paramter... p). But i am using scene2d and i set up the camera in the Stage, set the SpriteBatchs projection matrix to camera.combined and my Actors draw themself in the overridden draw(SpriteBatch batch) method. How can i access the camera or the view frustum there? Is there a way to get that out of the spritebatch? Or is there another way to realise fiew frustum culling?


回答1:


You do not need to do this yourself. If you are using a Stage with a camera it automatically just draw the actors that are inside of the view.

If you want to access the camera from the Stage simply get it from the stage. stage.getCamera()

Here is how you get the frustum from an camera inside of an stage:

Camera cam = this.stage.getCamera();
Frustum f = cam.frustum;
float h = cam.viewportHeight;
float w = cam.viewportWidth;
Matrix4 m = cam.combined; //combind projection matrix
Matrix4 m2= cam.projection; 
... 
...

From the camera you can get every projection matrix you need an so on...

Inside of an actor you can get the stage and of the stage you can get everything shown above..

actor.getStage().getCamera().frustum;


来源:https://stackoverflow.com/questions/21547391/libgdx-view-frustum-culling-inside-actor-draw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!