package net.halbear.Terrain4J.EngineCore.Main.Scene;

import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;

public class ParticleActor extends Actor {

    private Vector3f Velocity;
    private Vector3f RotatingAngles;
    private float Angle = 0.0f;
    private int LifeTicks = 1000;
    private float decelerationRate = 0.1f;

    public ParticleActor(String ID, String ModelID, Vector3f Position, Vector3f RotatingAngles, float Rotation, Vector3f Velocity, float Deceleration, int LifeTicks){
        super(ID,ModelID,Position);
        this.Angle = Rotation;
        this.RotatingAngles = RotatingAngles;
        this.decelerationRate = Deceleration;
        this.LifeTicks = LifeTicks;
        this.Velocity = Velocity;
    }
    public int TicksLeft(){return LifeTicks;}
    public float Deleration(){return decelerationRate;}
    public Vector3f GetVelocity(){return Velocity;}

    public void TickUpdate(){
        Angle = (Angle + 1.0f) % 360;
        GetRotation().identity().rotateAxis((float) EngineConfig.DegToRad * Angle, RotatingAngles);
        GetPosition().add((Velocity.x/100.0f),(Velocity.y/100.0f) ,(Velocity.z/100.0f));
        Velocity.x = Velocity.x != 0? Velocity.x > 0 ? Math.max(Velocity.x - decelerationRate, 0) : Math.min(Velocity.x + decelerationRate, 0) : 0;
        Velocity.y = Velocity.y != 0? Velocity.y > 0 ? Math.max(Velocity.y - decelerationRate, 0) : Math.min(Velocity.y + decelerationRate, 0) : 0;
        Velocity.z = Velocity.z != 0? Velocity.z > 0 ? Math.max(Velocity.z - decelerationRate, 0) : Math.min(Velocity.z + decelerationRate, 0) : 0;
        UpdateModelMatrix();
        LifeTicks--;
    }
}
