From 881404b4607d24af0d8efea7b041910d796b9474 Mon Sep 17 00:00:00 2001 From: Roland Hieber Date: Mon, 1 Feb 2010 18:13:08 +0100 Subject: [PATCH] save commit --- Box.cxx | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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& -- 2.20.1