Skip to content

Commit

Permalink
new approach for rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Ski committed Sep 20, 2024
1 parent 2b26758 commit 15cc4ad
Showing 1 changed file with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import com.talosvfx.talos.runtime.vfx.modules.DrawableModule;
import com.talosvfx.talos.runtime.vfx.modules.HistoryParticlePointDataGeneratorModule;
Expand All @@ -33,7 +32,8 @@ public class Particle implements Pool.Poolable {

public Vector3 spawnPosition = new Vector3();

public Vector3 position = new Vector3();
public Vector3 localPosition = new Vector3();
public Vector3 worldPosition = new Vector3();
public Vector3 velocity = new Vector3();
public Vector3 spinVelocity = new Vector3();
public Vector3 acceleration = new Vector3();
Expand Down Expand Up @@ -79,7 +79,7 @@ public void init(IEmitter emitterReference, float seed) {

//Starting values
life = particleModule.getLife();
position.set(particleModule.getSpawnPosition());
localPosition.set(particleModule.getSpawnPosition());
rotation.set(particleModule.getSpawnRotation());
acceleration.set(0, 0, 0);
velocity.set(particleModule.getInitialVelocity());
Expand Down Expand Up @@ -138,12 +138,12 @@ public void applyAlpha (float alpha, float delta) {
Vector2 worldScale = emitterReference.getWorldScale();
if (particleModule.hasPositionOverride()) {
Vector3 temp = new Vector3();
temp.set(particleModule.getSpawnPosition()).scl(worldScale.x, worldScale.y, 1f).rotate(worldRotation, 0, 0, 1);
temp.set(particleModule.getSpawnPosition());

position.set(temp);
localPosition.set(temp);

temp.set(particleModule.getPositionOverride()).scl(worldScale.x, worldScale.y, 1f).rotate(worldRotation, 0, 0, 1);
position.add(temp);
temp.set(particleModule.getPositionOverride());
localPosition.add(temp);

} else {
final Vector3 drag = particleModule.getDrag();
Expand All @@ -155,8 +155,6 @@ public void applyAlpha (float alpha, float delta) {
//Velocity is driven by velocity over time
final Vector3 velocityOverTime = particleModule.getVelocityOverTime();
velocity.set(velocityOverTime);
velocity.rotate(worldRotation, 0, 0, 1);
velocity.scl(emitterReference.getWorldScale().x);
} else {
//Acceleration mutate by forces

Expand Down Expand Up @@ -205,20 +203,19 @@ public void applyAlpha (float alpha, float delta) {
}

velocity.set(vx, vy, vz);
velocity.rotate(worldRotation, 0, 0, 1);
velocity.scl(worldScale.x, worldScale.y, 1f);

}

float posX = position.x;
float posY = position.y;
float posZ = position.z;
float posX = localPosition.x;
float posY = localPosition.y;
float posZ = localPosition.z;

posX += velocity.x * delta;
posY += velocity.y * delta;
posZ += velocity.z * delta;

position.set(posX, posY, posZ);
localPosition.set(posX, posY, posZ);
worldPosition.set(localPosition).rotate(Vector3.Z, worldRotation).scl(worldScale.x);

}

Expand Down Expand Up @@ -256,44 +253,45 @@ public void applyAlpha (float alpha, float delta) {


public float getAttachedPositionX () {
return emitterReference.getEffectPosition().x + position.x;
return emitterReference.getEffectPosition().x + worldPosition.x;
}

public float getAttachedPositionY () {
return emitterReference.getEffectPosition().y + position.y;
return emitterReference.getEffectPosition().y + worldPosition.y;
}

public float getAttachedPositionZ () {
return emitterReference.getEffectPosition().z + position.z;
return emitterReference.getEffectPosition().z + worldPosition.z;
}

public float getX() {
if(emitterReference.getEmitterModule().isAttached()) {
return getAttachedPositionX();
} else {
return spawnPosition.x + position.x;
return spawnPosition.x + worldPosition.x;
}
}

public float getY() {
if(emitterReference.getEmitterModule().isAttached()) {
return getAttachedPositionY();
} else {
return spawnPosition.y + position.y;
return spawnPosition.y + worldPosition.y;
}
}

public float getZ() {
if(emitterReference.getEmitterModule().isAttached()) {
return getAttachedPositionZ();
} else {
return spawnPosition.z + position.z;
return spawnPosition.z + worldPosition.z;
}
}

@Override
public void reset() {
position.setZero();
localPosition.setZero();
worldPosition.setZero();
requesterID = -1;
}

Expand Down

0 comments on commit 15cc4ad

Please sign in to comment.