0

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?

Robert P
  • 9,398
  • 10
  • 58
  • 100

1 Answers1

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;
bemeyer
  • 6,154
  • 4
  • 36
  • 86
  • I know how i get it inside the stage, cause i had to edit the stages camera to adjust its viewport (see my other question you answered). I wanted to access the camera inside the actors,but if the view frustum culling is done automatically i don'T need that anymore :P Thanks a lot! – Robert P Feb 04 '14 at 09:46
  • I have seen you edit. Thanks again. I don't need it anymore but well mybe i need it in future. – Robert P Feb 04 '14 at 09:47
  • Take a look into the `stage.draw` Method. it does check the actors bounds before it draws. And check if its the right thing for you. But it should be – bemeyer Feb 04 '14 at 09:48
  • Yea i was looking at it right after i saw your answer. In stage draw is called on the root group. In the root group the culling is performed. Thanks again. – Robert P Feb 04 '14 at 09:52