bool Aabb::hasCollision(const Aabb& other) const { bool result = false; if (intersects(other) == false) return result; Vector2f overlapMin(std::max(m_min.x, other.m_min.x), std::max(m_min.y, other.m_min.y)); Vector2f overlapMax(std::min(m_max.x, other.m_max.x), std::min(m_max.y, other.m_max.y)); if (contains(other)) result = true; return result; }
/*! * \brief calculates the intersection with another Aabb * * OWNERSHIP NOTICE: The caller must take care of deleting the created Aabb * \return NULL if the Aabbs do not intersect */ Aabb* Aabb::intersectWith(const Aabb& other) const{ if (collidesWithInternal(other)) { //overlap Minimum is componentwise maximum of the 2 min vectors Vector3_r overlapMin( std::max(mMin.x, other.getMax().x), std::max(mMin.y, other.getMax().y), std::max(mMin.z, other.getMax().z)); //overlap Maximum is componentwise minimum of the 2 max vectors Vector3_r overlapMax( std::min(mMax.x, other.getMax().x), std::min(mMax.y, other.getMax().y), std::min(mMax.z, other.getMax().z)); return new Aabb(overlapMin, overlapMax); } else { return 0; } }