using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GravityVizField : MonoBehaviour
{
    public int detail = 60;

    private void OnDrawGizmos() {
        Vector3 c = transform.position;
        Vector3 s = new Vector3(transform.localScale.x, transform.localScale.x, 0);
        Vector3 sx = new Vector3(s.x, 0, 0);
        Vector3 sy = new Vector3(0, s.y, 0);

        // Draw bounds
        Gizmos.color = Color.red;
        Gizmos.DrawLine(c-sx-sy, c+sx-sy);
        Gizmos.DrawLine(c-sx+sy, c+sx+sy);
        Gizmos.DrawLine(c-sx-sy, c-sx+sy);
        Gizmos.DrawLine(c+sx-sy, c+sx+sy);

        // Draw field
        Gizmos.color = Color.magenta;
        for(int i = 0;i < detail; i++) {
            for(int j = 0;j < detail; j++) {
                Vector3 position = c-s + (i+1.0f)/(detail+1)*sx*2 + (j+1.0f)/(detail+1)*sy*2;
                Vector2 gravityInPoint = GravitySampler.Sample(position);

                // Draw gravity in point
                Gizmos.DrawRay(position, (Vector3)gravityInPoint);
            }
        }
    }
}
