Libgdx view frustum culling inside actor.draw()

后端 未结 1 479
感动是毒
感动是毒 2021-01-27 07:56

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

1条回答
  •  有刺的猬
    2021-01-27 08:28

    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;
    

    0 讨论(0)
提交回复
热议问题