#pragma once

#include "math/float_types.hpp"

namespace physics {

  struct rigid_body
  {
    float inverse_mass;
    vec3 position;
    vec4 orientation;
    vec3 velocity;
    vec3 rotation;
    mat4x4 transform_matrix;
    mat3x3 inverse_inertia_tensor;
    mat3x3 inverse_inertia_tensor_world;
    vec3 force_accum;
    vec3 torque_accum;
    float linear_damping;
    float angular_damping;
    vec3 acceleration;
    vec3 last_frame_acceleration;

    void calculate_derived_data();

    void set_inertia_tensor(const mat3x3& inertia_tensor);

    void clear_accumulators();

    void add_force_at_local_point(const vec3& force,
                                  const vec3& point);

    void add_force_at_point(const vec3& force,
                            const vec3& point);

    void integrate(float duration);

    inline float get_mass() const
    {
      float sqrt_mass = 1.0f / sqrt<float>(inverse_mass);
      return sqrt_mass * sqrt_mass;
    }
  };

}
