#include <stdio.h>

#include "tracer.h"
#include "./intersect/intersect.h"
#include "../common/structs.h"
#include "../common/debug.h"


#include <pthread.h>
extern pthread_mutex_t mutexor;



extern scene_data* main_scene;

int trace(point* start, point* intersection, vector* projection, int step)
{
	object* object_hit;
	printd(CRAZY, "{entering trace\n");

	if(step > main_scene->max_recurs)
	{
		printd(CRAZY, "}exiting trace: max recurs\n");
		//return NOTHING;
		return 0;  //FIXME: temp hack
	}

//pthread_mutex_lock (&mutexor);

	object_hit = intersect(start, projection, intersection, 0);

//pthread_mutex_unlock (&mutexor);
	if(object_hit != NULL)
	{
		printd(CRAZY, "}exiting trace: hit obj[%i]\n", object_hit->id);
		return object_hit->id;
	}

	printd(CRAZY, "}exiting trace: missed\n");
	//printd(CRAZY, "}exiting trace\n");
	return 0;  //FIXME: background (hack)
}
