Libgdx view frustum culling inside actor.draw() [英] Libgdx view frustum culling inside actor.draw()

查看:267
本文介绍了Libgdx view frustum culling inside actor.draw()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用libgdx开发一个小游戏。它是一个2d自上而下的游戏,一些大地图和许多对象在他们。所以我只是想在我的视野中渲染东西。我看到 camera.frustum。*** inFrustum(Paramter ... p)。但我使用scene2d和我在 Stage 中设置相机,将 SpriteBatch 的投影矩阵设置为 camera.combined 和我的 Actor 绘制自己在重写的绘制(SpriteBatch批)方法。如何访问摄像机或视锥体?有没有办法让它从spritebatch?

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?

推荐答案

你不需要自己做这件事。如果你使用带有摄像头的舞台,它只是自动地绘制视图内的演员。

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.

如果您想从舞台上访问相机,只需从舞台上取得。 stage.getCamera()

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

以下是如何从舞台上的相机获得平截头体: p>

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; 
... 
...

在一个演员的内部你可以得到舞台和舞台,你可以得到上面显示的一切。

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

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

这篇关于Libgdx view frustum culling inside actor.draw()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆