Exemple #1
0
		/*!
		 * \brief Tests for intersection with another Aabb
		 * \return TRUE If this Aabb intersects with \p other. Otherwise FALSE.
		 * 
		 * TODO: Implement correct/faster collision detection methods for
		 *       collisions between different types of bounding volumes.
		 */
		bool Aabb::collidesWith(const BoundingVolume& other) const {
			if (other.getVolumeType() == getVolumeType()) {
				const BoundingVolume* otherPointer = &other;
				const Aabb* aabbPointer = static_cast<const Aabb*>(otherPointer);
				return collidesWithInternal(*aabbPointer);
			}
			return collidesWithInternal(Aabb(other.getSurroundingAabbMin(),
											 other.getSurroundingAabbMax()));
		}
    /*!
     * TODO: Implement correct/faster collision detection methods for
     *       collisions between different types of bounding volumes.
     */
    bool BoundingSphere::collidesWith(const BoundingVolume& other) const {
        if (other.getVolumeType() == BV_TYPE_SPHERE) {
            const BoundingSphere& otherSphere = (const BoundingSphere&) other;

            real distance = (getCenterVector() - otherSphere.getCenterVector()).dotProduct();
            real radii = (mRadius + otherSphere.getRadius()) * (mRadius + otherSphere.getRadius());

            //std::cout << "2. Distanz : " << distance << "     2. radius: " << radii << std::endl;
            
            if (distance > radii) {
                return 0;
            } else {
                //std::cout << "Kollision" << std::endl;
                return 1;
            }
        } else {
            Aabb thisAabb(getSurroundingAabbMin(), getSurroundingAabbMax());
            return
                thisAabb.collidesWith(
                    Aabb(other.getSurroundingAabbMin(),
                         other.getSurroundingAabbMax()));
        }
    }