#include "bvh.h"

bool intersect_object(list<Object*>::const_iterator iter, Ray ray, RayInfo* ray_info) {
	switch ((*iter)->type) {
		case    SCENE_OBJECT_TYPE_POINT: {
			break;
		}
		case   SCENE_OBJECT_TYPE_SPHERE: {
			Sphere* object = (Sphere*)(*iter);
			return glLib::Math::Intersect::ray_sphere(ray.origin,ray.get_direction(),object->position,object->radius,&ray_info->hit_distance);
		}
		case    SCENE_OBJECT_TYPE_PLANE: {
			Plane* object = (Plane*)(*iter);
			return glLib::Math::Intersect::ray_plane(ray.origin,ray.get_direction(),object->position,object->normal,&ray_info->hit_distance);
		}
		case SCENE_OBJECT_TYPE_TRIANGLE: {
			Triangle* object = (Triangle*)(*iter);
			return glLib::Math::Intersect::ray_triangle(
				ray.origin,ray.get_direction(),
				object->position,object->position2,object->position3,
				&ray_info->hit_distance
			);
		}
		default: { throw glLib::error("Not implemented!"); break; }
	}
	return false;
}