mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-20 19:21:46 +00:00
MATH: added generic collision code for AABB class
This commit is contained in:
parent
94d557de15
commit
0589fe0912
@ -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) {
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user