I have a cloud model and it continues to go behind the background scene (called as “wall” in code). How do i bring the cloud model to the front so that it never goes behind?
Code is as follows:
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();
}
}
Depth just means ‘the distance from the camera’.
I’m not a libgdx expert, but it looks like it’s using the X-Z plane to draw the world, and it’s treating the camera as on the ‘Y’ axis looking downward.
If that’s the case (please correct me if I’m wrong), then you need your clouds to have a Y-value greater (nearer to the camera) than your background.
Try setting the wall’s Y position to something like ‘-1’, and the cloud to something like ‘0’, and see if that works. You can layer other objects by adjusting the depth as well.