Advertisement
ThinMatrix

Untitled

Nov 3rd, 2022
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. package thinmatrix.lowPolyEngine.particles;
  2.  
  3. import org.lwjgl.util.vector.Vector3f;
  4.  
  5. import thinmatrix.lowPolyEngine.engineMain.gameObjects.Camera;
  6. import thinmatrix.lowPolyEngine.particles.particleSystem.ParticleSystem;
  7. import thinmatrix.toolbox.math3d.Maths;
  8. import thinmatrix.toolbox.objectPools.Vec3Pool;
  9.  
  10. public abstract class Particle implements Comparable<Particle>{
  11.    
  12.     private final ParticleSystem system;
  13.     public final Vector3f position;
  14.     public float baseScale = 1;
  15.     public float alpha = 1;
  16.     public Vector3f velocity;
  17.     public float timeAlive;
  18.     public float lifeLength;
  19.     private float distance;
  20.    
  21.     public float scaleModifier = 1;
  22.    
  23.     public boolean dead = false;
  24.    
  25.     public Particle(ParticleSystem system) {
  26.         this.system = system;
  27.         this.position = Vec3Pool.get();
  28.         this.velocity = Vec3Pool.get();
  29.     }
  30.    
  31.     public void update(Camera camera) {
  32.         scaleModifier = 1;
  33.         system.updateParticle(this);
  34.         calculateDistanceFromCamera(camera);
  35.     }
  36.    
  37.     public boolean isDead() {
  38.         return dead;
  39.     }
  40.    
  41.     public float getSize() {
  42.         return baseScale * scaleModifier;
  43.     }
  44.    
  45.     public float getProgress() {
  46.         return Maths.clamp(timeAlive / lifeLength, 0, 1);
  47.     }
  48.    
  49.     public void cleanUp() {
  50.         Vec3Pool.release(position, velocity);
  51.     }
  52.  
  53.     @Override
  54.     public int compareTo(Particle otherParticle) {
  55.         return (int) Math.signum(distance - otherParticle.distance);
  56.     }
  57.    
  58.     private void calculateDistanceFromCamera(Camera camera) {
  59.         Vector3f temp = Vec3Pool.get();
  60.         this.distance = Vector3f.sub(camera.getPosition(), position, temp).lengthSquared();
  61.         Vec3Pool.release(temp);
  62.     }
  63.  
  64.  
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement