//! Intersect with a sphere, returning true if there is an intersection. bool intersect(const sphere<Type>& s) const { const Type d1 = (s.getCenter() - m_center).sqrLength(); const Type d2 = m_radius + s.getRadius(); return (d1 < d2 * d2); }
sphere sphere::operator +(const sphere& other) const { glm::vec4 center = (c + other.getCenter()) * 0.5f; float radius = glm::distance(c, center) + glm::max(r, other.getRadius()); return sphere(center, radius); }
//! Extend the boundaries of the sphere by the given sphere. void extendBy(const sphere<Type>& sphere) { if (intersect(sphere)) return; const vec3<Type> dir = (m_center - sphere.getCenter()).normalized(); const vec3<Type> p1 = m_center + m_radius * dir; const vec3<Type> p2 = sphere.getCenter() - sphere.getRadius() * dir; setPoles(p1, p2); }
VkBool32 frustum::isVisible(const sphere& sphereWorld) const { float distance; for (auto& currentSide : sidesWorld) { distance = currentSide.distance(sphereWorld.getCenter()); if (distance + sphereWorld.getRadius() < 0.0f) { return VK_FALSE; } } return VK_TRUE; }
float sphere::distance(const sphere& sphere) const { return glm::abs(glm::distance(c, sphere.getCenter())) - r - sphere.getRadius(); }
sphere operator *(const glm::mat4& transform, const sphere& s) { return sphere(transform * s.getCenter(), s.getRadius()); }