From: Roland Hieber Date: Mon, 1 Feb 2010 17:13:08 +0000 (+0100) Subject: save commit X-Git-Url: https://git.rohieb.name/MicroTrace.git/commitdiff_plain/881404b4607d24af0d8efea7b041910d796b9474 save commit --- diff --git a/Box.cxx b/Box.cxx index e68ef40..9f1ca77 100644 --- a/Box.cxx +++ b/Box.cxx @@ -1,4 +1,5 @@ #include "Box.hxx" +#include "InfinitePlane.hxx" Box::Box() : m_min(Infinity, Infinity, Infinity), m_max(-Infinity, -Infinity, -Infinity) @@ -59,6 +60,48 @@ Box::Overlaps(const Box& b) const void Box::Clip(const Ray& ray, float& tnear, float& tfar) const { + // Note: equations here are the same as in InfinitePlane::Intersect() + // t = ((o-a)*n) / (d*n) + // o = ray.origin(), d = ray.direction(), + // n = surface normal of plane, a = anchor point of plane + Vec3f diff_min = m_min - ray.origin(); // o-a + Vec3f diff_max = m_max - ray.origin(); + + float cos_theta; + float tx_near, tx_far; + + // clip along x axis + if(cos_theta = ray.direction().dot(Vec3f(1,0,0)) != 0) // if not parallel... + tx_near = diff_min.dot(Vec3f(1,0,0)) / cos_theta; + if(cos_theta = ray.direction().dot(Vec3f(1,0,0)) != 0) + tx_far = diff_max.dot(Vec3f(1,0,0)) / cos_theta; + + // clip along y axis + if(cos_theta = ray.direction().dot(Vec3f(0,1,0)) != 0) + ty_near = diff_min.dot(Vec3f(0,1,0)) / cos_theta; + if(cos_theta = ray.direction().dot(Vec3f(0,0,1)) != 0) + ty_far = diff_max.dot(Vec3f(0,1,0)) / cos_theta; + + // ray intersects box iff it intersects projection on xy plane + // in this case: tx_near <= ty_near <= tx_far <= ty_far + // or: tx_far <= ty_near <= tx_near <= ty_far + // or: tx_far <= ty_far <= tx_near <= ty_near + // or: tx_near <= ty_far <= tx_far <= ty_near + if(tx_near <= ty_near && tx_far <= ty_near && + tx_near <= ty_far && tx_far <= ty_far) { + + // clip along z axis + if (cos_theta = ray.direction().dot(Vec3f(0, 1, 0)) != 0) + tz_near = diff_min.dot(Vec3f(0, 1, 0)) / cos_theta; + if (cos_theta = ray.direction().dot(Vec3f(0, 0, 1)) != 0) + tz_far = diff_max.dot(Vec3f(0, 1, 0)) / cos_theta; + + } else { + + } + + ////////////////////////// + } const Vec3f&