#include "raycolor.h"
#include "first_hit.h"
#include "blinn_phong_shading.h"
#include "reflect.h"

// Hint: for the mirror reflections, you can use raycolor recursively. That is what 'num_recursive_calls' is for.
// The maximum number of recursive calls should be 10. In other words, to get the color of a mirror reflection,
// stop after 10 bounces.
// This is of course only important when you hand in your code. In the meantime, to speed stuff up, you can lower it to 5.
bool raycolor(
    const Ray & ray,
    const double min_t,
    const std::vector< std::shared_ptr<Object> > & objects,
    const std::vector< std::shared_ptr<Light> > & lights,
    const int num_recursive_calls,
    Eigen::Vector3d & rgb)
{
    int hit_id;
    double t;
    Eigen::Vector3d n;

    /* Compute viewing array. */
    if (!first_hit(ray, min_t, objects, hit_id, t, n)) {
        rgb = Eigen::Vector3d(0,0,0);
        return false;
    }

    /* Evaluate shading model and set pixel to that color. */
    rgb = blinn_phong_shading(ray, hit_id, t, n, objects, lights);
    return true;
}
