12345678910111213141516171819202122232425262728293031323334 |
- #include "common/utils/CollisionBox.h"
- CollisionBox::CollisionBox(const Vector3& min, const Vector3& max)
- : min(min), max(max) {
- }
- CollisionBox::CollisionBox(const Vector3& size) : max(size) {
- }
- CollisionBox CollisionBox::offset(const Vector3& offset) const {
- return CollisionBox(offset + min, offset + max);
- }
- bool CollisionBox::collidesWith(const CollisionBox& 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];
- }
- CollisionBox CollisionBox::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 CollisionBox(min + sub, max + add);
- }
- const Vector3& CollisionBox::getMin() const {
- return min;
- }
- const Vector3& CollisionBox::getMax() const {
- return max;
- }
|