2010-09-03 05:41:20 +08:00
|
|
|
/*
|
|
|
|
This file is part of Mitsuba, a physically based rendering system.
|
|
|
|
|
2012-09-28 00:43:51 +08:00
|
|
|
Copyright (c) 2007-2012 by Wenzel Jakob and others.
|
2010-09-03 05:41:20 +08:00
|
|
|
|
|
|
|
Mitsuba is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License Version 3
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
Mitsuba is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-04-14 21:15:59 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-09-03 05:41:20 +08:00
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-08-10 01:38:37 +08:00
|
|
|
#include <mitsuba/core/aabb.h>
|
|
|
|
|
|
|
|
MTS_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
Point AABB::getCorner(uint8_t corner) const {
|
|
|
|
return Point(corner & 1 ? max.x : min.x,
|
|
|
|
corner & 2 ? max.y : min.y,
|
|
|
|
corner & 4 ? max.z : min.z);
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:14:48 +08:00
|
|
|
|
|
|
|
bool AABB::overlaps(const BSphere &sphere) const {
|
|
|
|
Float distance = 0;
|
|
|
|
for (int i=0; i<3; ++i) {
|
|
|
|
if (sphere.center[i] < min[i]) {
|
|
|
|
Float d = sphere.center[i]-min[i];
|
|
|
|
distance += d*d;
|
|
|
|
} else if (sphere.center[i] > max[i]) {
|
|
|
|
Float d = sphere.center[i]-max[i];
|
|
|
|
distance += d*d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return distance < sphere.radius*sphere.radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
BSphere AABB::getBSphere() const {
|
|
|
|
Point3 center = getCenter();
|
|
|
|
return BSphere(center, (center - max).length());
|
|
|
|
}
|
|
|
|
|
2010-08-10 01:38:37 +08:00
|
|
|
MTS_NAMESPACE_END
|