using OpenTK.Mathematics;

namespace DoomDeathmatch.Component.Util;

public class RigidbodyComponent : Engine.Scene.Component.Component
{
  public Vector3 Velocity { get; private set; } = Vector3.Zero;
  public Vector3 Acceleration { get; private set; } = Vector3.Zero;
  public Vector3 Force { get; private set; } = Vector3.Zero;
  public float Mass { get; set; } = 1.0f;
  public bool IsStatic { get; set; } = false;

  public void AddForce(Vector3 parForce)
  {
    if (IsStatic)
      return;

    Force += parForce;
  }

  public void AddVelocity(Vector3 parVelocity)
  {
    if (IsStatic)
      return;

    Velocity += parVelocity;
  }

  public override void Update(double parDeltaTime)
  {
    if (IsStatic)
      return;

    Acceleration = Force / Mass;
    Velocity += Acceleration * (float)parDeltaTime;
    GameObject.Transform.Translation += Velocity * (float)parDeltaTime;
    Force = Vector3.Zero;
  }
}