X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/0e3446ceb6fd6db0cb292671f37b46daaa2aed5b..refs/heads/master:/InfinitePlane.cxx diff --git a/InfinitePlane.cxx b/InfinitePlane.cxx index 442da19..93e165f 100644 --- a/InfinitePlane.cxx +++ b/InfinitePlane.cxx @@ -1,11 +1,11 @@ #include "InfinitePlane.hxx" InfinitePlane::InfinitePlane(const Vec3f& a, const Vec3f& n, Shader* shader) - : Primitive(shader), + : Primitive(shader), m_a(a), m_n(n) { - + } InfinitePlane::~InfinitePlane() @@ -17,14 +17,43 @@ InfinitePlane::Intersect(Ray& ray) { Vec3f diff = m_a - ray.origin(); float t = diff.dot(m_n) / ray.direction().dot(m_n); - if (t < 1e-5 || t > ray.t()) + if (t < Epsilon || t > ray.t()) return false; + ray.setT(t); + ray.setHit(this); + return true; } Vec3f InfinitePlane::GetNormal(Ray& ray) { - return Vec3f(); + return m_n; +} + +Box +InfinitePlane::CalcBounds() +{ + if(fabs(m_n[0]-1) < Epsilon && m_n[1] < Epsilon && m_n[2] < Epsilon) { + // plane is parallel to y and z axes + return Box(Vec3f(m_a[0]-Epsilon, Infinity, Infinity), + Vec3f(m_a[0]+Epsilon, Infinity, Infinity)); + } else if(m_n[0] < Epsilon && fabs(m_n[1]-1) < Epsilon && m_n[2] < Epsilon) { + // plane is parallel to x and z axes + return Box(Vec3f(Infinity, m_a[1]-Epsilon, Infinity), + Vec3f(Infinity, m_a[1]+Epsilon, Infinity)); + } else if(m_n[0] < Epsilon && m_n[1] < Epsilon && fabs(m_n[2]-1) < Epsilon ) { + // plane is parallel to x and y axes + return Box(Vec3f(Infinity, Infinity, m_a[2]-Epsilon), + Vec3f(Infinity, Infinity, m_a[2]+Epsilon)); + } else + // no real border + return Box(); +} + +bool +InfinitePlane::InVoxel(const Box& box) +{ + return CalcBounds().Overlaps(box); }