com.talosvfx.talos.runtime.modules.ForceApplierModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of talos-libgdx Show documentation
Show all versions of talos-libgdx Show documentation
Talos runtime for use in LibGDX projects
The newest version!
package com.talosvfx.talos.runtime.modules;
import com.badlogic.gdx.math.Vector2;
import com.talosvfx.talos.runtime.ScopePayload;
import com.talosvfx.talos.runtime.values.NumericalValue;
public class ForceApplierModule extends AbstractModule {
public static final int SUM_FORCES = 0;
public static final int ANGLE = 0;
public static final int VELOCITY = 1;
NumericalValue sumForces;
NumericalValue angleOutput;
NumericalValue velocityOutput;
Vector2 tmp = new Vector2();
@Override
protected void defineSlots() {
sumForces = createInputSlot(SUM_FORCES);
angleOutput = createOutputSlot(ANGLE);
velocityOutput = createOutputSlot(VELOCITY);
}
@Override
public void processValues() {
float particleAlpha = getScope().getFloat(ScopePayload.PARTICLE_ALPHA);
if(getScope().currParticle() == null) return;
float particleLife = getScope().currParticle().life;
float timePassed = particleAlpha * particleLife;
tmp.set(sumForces.get(0), sumForces.get(1));
float angle = tmp.angle();
float velocity = tmp.len() * timePassed; // V = F * T for mass 1;
angleOutput.set(angle);
velocityOutput.set(velocity);
}
}