我有一个云模型,它继续在背景场景后面(在代码中称为“墙”)。我如何将云模型带到前面以便它永远不会落后?
代码如下:
public class RocketBlast extends DemoWrapper implements InputProcessor, ApplicationListener {
private static final Vector2 GRIDSIZE = new Vector2(16, 16);
FloorGrid floor;
private DecalBatch decalBatch;
private SpriteBatch spriteBatch2d;
private GroupStrategy strategy;
// private DecalSprite[] walls = new DecalSprite[5];
private DecalSprite wall;
private ArrayList<DecalSprite> walls = new ArrayList<DecalSprite>();
private MeshHelper cloud;
private DecalSprite shadow;
// camera
private Camera cam;
private GuOrthoCam oCam;
private GuPerspCam pCam;
private String camType = "ortho";
private boolean debugRender = true;
private Vector2 screenSize;
private Vector2 last = new Vector2(0, 0);
private Builder builder;
@Override
public void create() {
Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);
Gdx.gl10.glDepthFunc(GL10.GL_LESS);
builder = new Builder();
builder.addIslands();
screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
oCam = new GuOrthoCam(screenSize.x, screenSize.y, GRIDSIZE);
oCam.position.set(8, 1, -17);
oCam.setTargetObj(builder.target);
pCam = new GuPerspCam(50, 50, 50);
cam = oCam;
floor = new FloorGrid(GRIDSIZE);
String objfile = "data/volumetric_cloud_tutorial.obj";
cloud = new MeshHelper(objfile);
cloud.scale(0.5f, 0.5f, 0.5f);
cloud.setPos(1, 1f, 5);
cloud.setColor(1, 1, 0);
cloud.setMotion(1,0, 0, 0.02f);
cloud.setTexture();
addWalls();
// batches
strategy = new CameraGroupStrategy(cam);
decalBatch = new DecalBatch(strategy);
spriteBatch2d = new SpriteBatch();
spriteBatch2d.enableBlending();
Gdx.input.setInputProcessor(this);
}
private ArrayList<DecalSprite> addWalls() {
wall = new DecalSprite().build("data/i.png");
wall.sprite.rotateY(90);
wall.sprite.setPosition(GRIDSIZE.x, 1, 8);
wall.sprite.setDimensions(17, 2);
walls.add(wall);
return walls;
}
@Override
public void render() {
GL10 gl = Gdx.app.getGraphics().getGL10();
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
float delta = Gdx.graphics.getDeltaTime();
cam.update();
cam.apply(gl);
setUpLighting(gl);
gl.glColor4f(0, 1, 0, 1f);
floor.render(gl, GL10.GL_LINE_STRIP);
gl.glColor4f(1, 0, 0, 1f);
for (DecalSprite oneWall : walls) {
decalBatch.add(oneWall.sprite);
}
cloud.update(delta);
cloud.render(gl, GL10.GL_TRIANGLES);
//decalBatch.add(shadow.sprite);
decalBatch.flush();
cam.update();
cam.apply(gl);
// decalBatch.add(player.sprite);
decalBatch.flush();
cam.update();
cam.apply(gl);
// turn off lighting for 2d sprites
gl.glDisable(GL10.GL_LIGHTING);
gl.glPopMatrix();
oCam.handleKeys();
}
}
答案 0 :(得分:0)
深度仅仅意味着'与相机的距离'。
我不是libgdx专家,但看起来它正在使用X-Z平面绘制世界,它正在将相机视为向下看的“Y”轴。
如果是这种情况(如果我错了请纠正我),那么你需要你的云具有比背景更大的Y值(更接近相机)。
尝试将墙的Y位置设置为“-1”,将云设置为“0”,然后查看是否有效。您也可以通过调整深度来对其他对象进行分层。