2015-03-11 22:31:35 +11:00
|
|
|
#include "ray.hpp"
|
2015-02-19 13:28:56 +11:00
|
|
|
#include "plane.hpp"
|
|
|
|
#include "debug.hpp"
|
2015-03-07 03:20:50 +11:00
|
|
|
#include "aabb.hpp"
|
2015-02-19 13:28:56 +11:00
|
|
|
|
2015-03-07 03:20:50 +11:00
|
|
|
|
|
|
|
void
|
|
|
|
test_intersect_plane (void)
|
2015-02-19 13:28:56 +11:00
|
|
|
{
|
2015-03-11 22:31:35 +11:00
|
|
|
// trivial case: origin ray facing z, plane at unit z facing -z.
|
|
|
|
util::ray3f l ({0,0,0}, {0,0, 1});
|
2015-02-19 13:28:56 +11:00
|
|
|
util::plane3f p ({0,0,1}, {0,0,-1});
|
|
|
|
|
|
|
|
CHECK_EQ (l.intersect (p), 1);
|
|
|
|
}
|
2015-03-07 03:20:50 +11:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
test_intersect_aabb (void)
|
|
|
|
{
|
|
|
|
// trivial case: unit aabb at origin, ray from (0.5,-0.5) upwards
|
|
|
|
util::AABB2f b {
|
|
|
|
{ 0.f, 0.f },
|
|
|
|
{ 1.f, 1.f }
|
|
|
|
};
|
|
|
|
|
2015-03-11 22:31:35 +11:00
|
|
|
util::ray2f l {
|
2015-03-07 03:20:50 +11:00
|
|
|
{ 0.5f, -0.5f },
|
|
|
|
{ 0.f, 1.f }
|
|
|
|
};
|
|
|
|
|
|
|
|
CHECK_EQ (l.intersect (b), 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
test_intersect_plane ();
|
|
|
|
test_intersect_aabb ();
|
|
|
|
}
|