MATH: added generic collision code for AABB class

This commit is contained in:
neuromancer 2023-05-06 14:02:43 +02:00
parent 94d557de15
commit 0589fe0912
3 changed files with 11 additions and 6 deletions

View File

@ -367,12 +367,7 @@ bool GeometricObject::collides(const Math::AABB &boundingBox_) {
if (isDestroyed() || isInvisible() || !_boundingBox.isValid() || !boundingBox_.isValid())
return false;
return (_boundingBox.getMax().x() > boundingBox_.getMin().x() &&
_boundingBox.getMin().x() < boundingBox_.getMax().x() &&
_boundingBox.getMax().y() > boundingBox_.getMin().y() &&
_boundingBox.getMin().y() < boundingBox_.getMax().y() &&
_boundingBox.getMax().z() > boundingBox_.getMin().z() &&
_boundingBox.getMin().z() < boundingBox_.getMax().z());
return _boundingBox.collides(boundingBox_);
}
void GeometricObject::draw(Freescape::Renderer *gfx) {

View File

@ -77,4 +77,13 @@ void AABB::transform(const Math::Matrix4 &matrix) {
}
}
bool AABB::collides(const AABB &aabb) {
return (getMax().x() > aabb.getMin().x() &&
getMin().x() < aabb.getMax().x() &&
getMax().y() > aabb.getMin().y() &&
getMin().y() < aabb.getMax().y() &&
getMax().z() > aabb.getMin().z() &&
getMin().z() < aabb.getMax().z());
}
}

View File

@ -39,6 +39,7 @@ public:
Math::Vector3d getMin() const { return _min; }
Math::Vector3d getMax() const { return _max; }
bool isValid() const { return _valid; }
bool collides(const AABB &aabb);
private:
Math::Vector3d _min, _max;