123456789101112131415161718192021222324252627282930313233 |
- #include "common/Box.h"
- Box::Box(const Vector3& min, const Vector3& max) : min(min), max(max) {
- }
- Box::Box(const Vector3& size) : max(size) {
- }
- Box Box::offset(const Vector3& offset) const {
- return Box(offset + min, offset + max);
- }
- bool Box::collidesWith(const Box& other) const {
- return max[0] > other.min[0] && min[0] < other.max[0] &&
- max[1] > other.min[1] && min[1] < other.max[1] &&
- max[2] > other.min[2] && min[2] < other.max[2];
- }
- Box Box::expand(const Vector3& offset) const {
- Vector3 add(offset[0] * (offset[0] >= 0.0), offset[1] * (offset[1] >= 0.0),
- offset[2] * (offset[2] >= 0.0));
- Vector3 sub(offset[0] * (offset[0] <= 0.0), offset[1] * (offset[1] <= 0.0),
- offset[2] * (offset[2] <= 0.0));
- return Box(min + sub, max + add);
- }
- const Vector3& Box::getMin() const {
- return min;
- }
- const Vector3& Box::getMax() const {
- return max;
- }
|