Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgdx particle system Z coordinate

I want to render a particle effect in 3D using the Z coordinate. I've tried to implement a own ParticleEffect using Decals instead of Sprites without success.

Is there any other way to render a ParticleEffect using the Z coordinate? Maybe by manipulating the transformation Matrix of the SpriteBatch?

Update:

working code

// update projection each frame since my camera is moving
spriteBatch.setProjectionMatrix(camera3d.projection);

for (ParticleEffect effect : effects){
    spriteBatch.setTransformMatrix(camera3d.view);
    spriteBatch.getTransformMatrix().translate(x,y,z); // different for each effect
    spriteBatch.getTransformMatrix().scale(0.1f,0.1f,0.1f); //optional
    spriteBatch.begin();

    effect.draw(spriteBatch, delta);

    spriteBatch.end();
    spriteBatch.getTransformMatrix().idt();
}
like image 421
Roman K Avatar asked Jun 01 '12 09:06

Roman K


1 Answers

If your 3D effect is a parallax effect, meaning your particles face the camera perpendicularily, you can indeed set the transformation matrix of the SpriteBatch

batch.getTransformMatrix().idt().translate(0, 0, z);
batch.begin();
... do your rendering here
batch.end();
// reset the matrix, so you can use the batch for other stuff
batch.idt();

For a perspective effect you'll also have to use perspective projection. The easiest way to cope with this requirement is to use a PerspectiveCamera instead of an OrthographicCamera.

like image 80
badlogic Avatar answered Sep 28 '22 01:09

badlogic