Libgdx Particles 3D为什么翻译会分离粒子?

时间:2014-11-27 21:07:18

标签: 3d libgdx particle-system

我正在为我的船做一个反应堆,一切都很好,因为我不做翻译。 例如:更多我将右转与我的船更多的反应堆颗粒分离(见截图)。问题是什么?

我是3D游戏开发的初学者,我对火箭飞船也有同样的问题(截图上的红色粒子)我想知道粒子3D是否是制作激光器Fx或其他的合适技术。有人有想法吗?

屏幕截图:

Small right translation enter image description here

Big Right translation enter image description here

我的翻译功能:

public void translate(ParticleEffect effect, Vector3 position){
    Matrix4 targetMatrix = new Matrix4();
    targetMatrix.idt();
    targetMatrix.setToTranslation(new Vector3(position));
    effect.setTransform(targetMatrix);
}

我的测试效果.p

{unique:{pointSpriteBatch:{class:com.badlogic.gdx.graphics.g3d.particles.ResourceData$SaveData,data:{},indices:[0]}},data:[],assets:[{filename:"/home/julio/Eclipse workspace/SpaceInvaders3d/android/assets/particles/pre_particle.png",type:com.badlogic.gdx.graphics.Texture}],resource:{class:com.badlogic.gdx.graphics.g3d.particles.ParticleEffect,controllers:[{name:"PointSprite Controller",emitter:{class:com.badlogic.gdx.graphics.g3d.particles.emitters.RegularEmitter,minParticleCount:0,maxParticleCount:200,continous:true,emission:{active:true,lowMin:250,lowMax:250,highMin:250,highMax:250,relative:false,scaling:[1],timeline:[0]},delay:{active:false,lowMin:0,lowMax:0},duration:{active:true,lowMin:3000,lowMax:3000},life:{active:true,lowMin:250,lowMax:250,highMin:250,highMax:250,relative:false,scaling:[1,1,1],timeline:[0,0.66,1]},lifeOffset:{active:false,lowMin:0,lowMax:0,highMin:0,highMax:0,relative:false,scaling:[1],timeline:[0]}},influencers:[{class:com.badlogic.gdx.graphics.g3d.particles.influencers.RegionInfluencer$Single,regions:[{halfInvAspectRatio:0.5,v2:1,u2:1}]},{class:com.badlogic.gdx.graphics.g3d.particles.influencers.SpawnInfluencer,spawnShape:{class:com.badlogic.gdx.graphics.g3d.particles.values.PointSpawnShapeValue,active:false,xOffsetValue:{active:false,lowMin:0,lowMax:0},yOffsetValue:{active:false,lowMin:0,lowMax:0},zOffsetValue:{active:false,lowMin:0,lowMax:0},spawnWidthValue:{active:false,lowMin:0,lowMax:0,highMin:0,highMax:0,relative:false,scaling:[1],timeline:[0]},spawnHeightValue:{active:false,lowMin:0,lowMax:0,highMin:0,highMax:0,relative:false,scaling:[1],timeline:[0]},spawnDepthValue:{active:false,lowMin:0,lowMax:0,highMin:0,highMax:0,relative:false,scaling:[1],timeline:[0]},edges:false}},{class:com.badlogic.gdx.graphics.g3d.particles.influencers.ScaleInfluencer,value:{active:false,lowMin:0,lowMax:0,highMin:1,highMax:1,relative:false,scaling:[0.0056179776,0.050561797,0.12921348,0.31460676],timeline:[0,0.3408,0.6928,0.9904]}},{class:com.badlogic.gdx.graphics.g3d.particles.influencers.ColorInfluencer$Single,alpha:{active:false,lowMin:0,lowMax:0,highMin:1,highMax:1,relative:false,scaling:[0,0.15,0.2982456,0],timeline:[0,0.5,0.82191783,1]},color:{active:false,colors:[0.23137255,1,0.047058824,0,0,0],timeline:[0,1]}},{class:com.badlogic.gdx.graphics.g3d.particles.influencers.DynamicsInfluencer,velocities:[{class:com.badlogic.gdx.graphics.g3d.particles.influencers.DynamicsModifier$PolarAcceleration,isGlobal:true,strengthValue:{active:false,lowMin:0,lowMax:10,highMin:0,highMax:10,relative:true,scaling:[1,1,1],timeline:[0,0.14383562,0.4041096]},thetaValue:{active:false,lowMin:90,lowMax:90,highMin:90,highMax:90,relative:false,scaling:[1],timeline:[0]},phiValue:{active:false,lowMin:90,lowMax:90,highMin:90,highMax:90,relative:false,scaling:[1],timeline:[0]}}]}],renderer:{class:com.badlogic.gdx.graphics.g3d.particles.renderers.PointSpriteRenderer}}]}}

谢谢,对不起我的小英语。

1 个答案:

答案 0 :(得分:2)

这是3d粒子编辑器的众多缺陷之一。如果您使用了2d等效项,则可以检查附加选项,但3d编辑器没有这样的功能。您可以破解代码并更改ParticleController类的更新方法。我这样做了,效果很好。

    public boolean attached = true;
private float deltaX, deltaY, deltaZ;

public void update(){

        this.transform.getTranslation(pos);
        if(firstUpdate){
            firstUpdate=false;
            oldPos.set(pos);
        }

        emitter.update();

        if (attached) {
            deltaX = pos.x - oldPos.x;
            deltaY = pos.y - oldPos.y;
            deltaZ = pos.z - oldPos.z;
            for (int i = 0; i < ((FloatChannel)particles.getChannel(ParticleChannels.Position)).data.length; i += ((FloatChannel)particles
                .getChannel(ParticleChannels.Position)).strideSize) {
                ((FloatChannel)particles.getChannel(ParticleChannels.Position)).data[i + ParticleChannels.XOffset] += deltaX;
                ((FloatChannel)particles.getChannel(ParticleChannels.Position)).data[i + ParticleChannels.YOffset] += deltaY;
                ((FloatChannel)particles.getChannel(ParticleChannels.Position)).data[i + ParticleChannels.ZOffset] += deltaZ;
                if (particles.getChannel(ParticleChannels.PreviousPosition) != null) {
                    ((FloatChannel)particles.getChannel(ParticleChannels.PreviousPosition)).data[i + ParticleChannels.XOffset] += deltaX;
                    ((FloatChannel)particles.getChannel(ParticleChannels.PreviousPosition)).data[i + ParticleChannels.YOffset] += deltaY;
                    ((FloatChannel)particles.getChannel(ParticleChannels.PreviousPosition)).data[i + ParticleChannels.ZOffset] += deltaZ;
                }
            }
            oldPos.set(pos);
        }

        for(Influencer influencer : influencers)
            influencer.update();

    }