1 package com.badlogic.gdx.graphics.g3d.particles.influencers; 2 3 import com.badlogic.gdx.graphics.g3d.particles.ParallelArray.FloatChannel; 4 import com.badlogic.gdx.graphics.g3d.particles.ParallelArray.ObjectChannel; 5 import com.badlogic.gdx.graphics.g3d.particles.ParticleChannels; 6 import com.badlogic.gdx.graphics.g3d.particles.ParticleController; 7 import com.badlogic.gdx.utils.GdxRuntimeException; 8 9 /** It's an {@link Influencer} which updates the simulation of particles containing a {@link ParticleController}. 10 * Must be the last influencer to be updated, so it has to be placed at the end 11 * of the influencers list when creating a {@link ParticleController}. 12 * @author Inferno */ 13 public class ParticleControllerFinalizerInfluencer extends Influencer { 14 FloatChannel positionChannel, scaleChannel, rotationChannel; 15 ObjectChannel<ParticleController> controllerChannel; 16 boolean hasScale, hasRotation; 17 18 public ParticleControllerFinalizerInfluencer() {} 19 20 @Override 21 public void init () { 22 controllerChannel = controller.particles.getChannel(ParticleChannels.ParticleController); 23 if(controllerChannel == null) 24 throw new GdxRuntimeException("ParticleController channel not found, specify an influencer which will allocate it please."); 25 scaleChannel = controller.particles.getChannel(ParticleChannels.Scale); 26 rotationChannel = controller.particles.getChannel(ParticleChannels.Rotation3D); 27 hasScale = scaleChannel != null; 28 hasRotation = rotationChannel != null; 29 } 30 31 @Override 32 public void allocateChannels () { 33 positionChannel = controller.particles.addChannel(ParticleChannels.Position); 34 } 35 36 @Override 37 public void update () { 38 for(int i=0, positionOffset = 0, c = controller.particles.size; 39 i< c; 40 ++i, positionOffset += positionChannel.strideSize){ 41 ParticleController particleController = controllerChannel.data[i]; 42 float scale = hasScale ? scaleChannel.data[i] : 1; 43 float qx=0, qy=0, qz=0, qw=1; 44 if(hasRotation){ 45 int rotationOffset = i* rotationChannel.strideSize; 46 qx = rotationChannel.data[rotationOffset + ParticleChannels.XOffset]; 47 qy = rotationChannel.data[rotationOffset + ParticleChannels.YOffset]; 48 qz = rotationChannel.data[rotationOffset + ParticleChannels.ZOffset]; 49 qw = rotationChannel.data[rotationOffset + ParticleChannels.WOffset]; 50 } 51 particleController.setTransform( positionChannel.data[positionOffset + ParticleChannels.XOffset], 52 positionChannel.data[positionOffset + ParticleChannels.YOffset], 53 positionChannel.data[positionOffset + ParticleChannels.ZOffset], 54 qx,qy,qz,qw, scale); 55 particleController.update(); 56 } 57 } 58 @Override 59 public ParticleControllerFinalizerInfluencer copy () { 60 return new ParticleControllerFinalizerInfluencer(); 61 } 62 } 63