Libgdx 视锥体剔除在 actor.draw() 中

Libgdx view frustum culling inside actor.draw()(Libgdx 视锥体剔除在 actor.draw() 中)

本文介绍了Libgdx 视锥体剔除在 actor.draw() 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 libgdx 开发一个小游戏.这是一个 2D 自上而下的游戏,上面有一些大地图和许多对象.所以我只想在我的视锥中渲染东西.我见过 camera.frustum.***inFrustum(Paramter... p).但我使用的是scene2d,我在Stage中设置了相机,将SpriteBatch的投影矩阵设置为camera.combined和我的Actor 在重写的 draw(SpriteBatch batch) 方法中绘制自己.如何访问 camera 或那里的视锥?有没有办法从 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()

以下是如何从舞台内的相机中获取截锥体:

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;

这篇关于Libgdx 视锥体剔除在 actor.draw() 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Libgdx 视锥体剔除在 actor.draw() 中

基础教程推荐