问题
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 SpriteBatch
s projection matrix to camera.combined
and my Actor
s 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