/// <summary> /// Perform robust collision detection using BoundingSpheres to determine if two models are intersecting. /// </summary> /// <param name="modelA"></param> /// <param name="modelB"></param> /// <returns></returns> public bool collidesWith(BasicModel modelA, BasicModel modelB) { // get the position of each model Matrix modelATranslation = modelA.GetWorld(); Matrix modelBTranslation = modelB.GetWorld(); // check each bounding sphere of each model foreach (ModelMesh modelMeshesA in modelA.model.Meshes) { foreach (ModelMesh modelMeshesB in modelB.model.Meshes) { // update bounding spheres of each models mesh BoundingSphere BSA = modelMeshesA.BoundingSphere.Transform(modelATranslation); BoundingSphere BSB = modelMeshesB.BoundingSphere.Transform(modelBTranslation); // check if any the mesh bounding sphere intersects with another if (BSA.Intersects(BSB)) { return true; } } } return false; }