#pragma once

#include "physics/particle.hpp"

namespace physics {

  struct particle_contact
  {
    physics::particle * particle[2];

    float restitution;

    vec3 contact_normal;

    float penetration;

    void resolve(float duration);

    float calculate_separating_velocity() const;

    void resolve_velocity(float duration);

    void resolve_interpenetration(float duration);

    inline float get_total_inverse_mass()
    {
      float total_inverse_mass = particle[0]->inverse_mass;
      if (particle[1]) total_inverse_mass += particle[1]->inverse_mass;
      return total_inverse_mass;
    }
  };

  struct particle_contact_resolver
  {
    int max_iterations;
    int iterations;

    void resolve_contacts(particle_contact * contacts,
                          int contacts_length,
                          float duration);
  };

}
