Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package thinmatrix.lowPolyEngine.particles;
- import org.lwjgl.util.vector.Vector3f;
- import thinmatrix.lowPolyEngine.engineMain.gameObjects.Camera;
- import thinmatrix.lowPolyEngine.particles.particleSystem.ParticleSystem;
- import thinmatrix.toolbox.math3d.Maths;
- import thinmatrix.toolbox.objectPools.Vec3Pool;
- public abstract class Particle implements Comparable<Particle>{
- private final ParticleSystem system;
- public final Vector3f position;
- public float baseScale = 1;
- public float alpha = 1;
- public Vector3f velocity;
- public float timeAlive;
- public float lifeLength;
- private float distance;
- public float scaleModifier = 1;
- public boolean dead = false;
- public Particle(ParticleSystem system) {
- this.system = system;
- this.position = Vec3Pool.get();
- this.velocity = Vec3Pool.get();
- }
- public void update(Camera camera) {
- scaleModifier = 1;
- system.updateParticle(this);
- calculateDistanceFromCamera(camera);
- }
- public boolean isDead() {
- return dead;
- }
- public float getSize() {
- return baseScale * scaleModifier;
- }
- public float getProgress() {
- return Maths.clamp(timeAlive / lifeLength, 0, 1);
- }
- public void cleanUp() {
- Vec3Pool.release(position, velocity);
- }
- @Override
- public int compareTo(Particle otherParticle) {
- return (int) Math.signum(distance - otherParticle.distance);
- }
- private void calculateDistanceFromCamera(Camera camera) {
- Vector3f temp = Vec3Pool.get();
- this.distance = Vector3f.sub(camera.getPosition(), position, temp).lengthSquared();
- Vec3Pool.release(temp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement