Sphere intersection test

This commit is contained in:
Eryn Wells 2013-09-08 15:35:58 -07:00
parent d636a4f2ee
commit 0fa10c3220

View file

@ -5,18 +5,49 @@
* Eryn Wells <eryn@erynwells.me>
*/
#include <stdlib.h>
#include <check.h>
#include "object.h"
#include "test_suites.h"
void check_sphere_intersection(Object *sphere, Ray ray, int expected_nints);
START_TEST(test_sphere_does_intersect)
{
// Create a sphere at the origin of radius 1.
Object *sphere = object_init(ObjectTypeSphere);
object_sphere_set_radius(sphere, 1.0);
Vector3 loc, dir;
Ray ray;
loc = vector_init(0, 0, -5);
dir = vector_init(0, 0, 1);
ray = ray_init(loc, dir);
check_sphere_intersection(sphere, ray, 2);
loc = vector_init(0, -5, 0);
dir = vector_init(
}
END_TEST
void
check_sphere_intersection(Object *sphere, Ray ray, int expected_nints)
{
float *t;
int nints = object_does_intersect(sphere, ray, &t);
ck_assert(nints == expected_nints);
if (nints > 0) {
free(t);
}
}
Suite *
test_object_create_suite()
{