Sphere
Sphere stores a center point and a radius and is used as a simple bounding volume for intersection tests, culling, and spatial queries. A negative radius indicates an empty sphere. The class supports expansion with points, merging with other spheres, translation, and transformation by a matrix.
Construction
Constructors
Sphere() constexpr
Constructs a sphere from a center and radius.
Sphere::Sphere(const Vector3 center, float radius);| Parameter | Description |
|---|---|
| center | Sphere center. |
| radius | Sphere radius (negative indicates empty). |
Properties
radius float
Sphere radius. A negative value indicates an empty sphere.
float radius {-1.0f};Functions
ApplyTransform() void
Applies a 4×4 transform to the sphere.
The center is transformed directly, while the radius is scaled by the largest scale factor present in the matrix to ensure conservative bounding behavior.
void Sphere::ApplyTransform(const Matrix4& transform);| Parameter | Description |
|---|---|
| transform | Matrix to apply. |
ExpandWithPoint() void
Expands the sphere to include a point.
If the sphere is empty, it becomes a zero-radius sphere at the point. Otherwise, the sphere grows minimally to contain the point.
void Sphere::ExpandWithPoint(const Vector3& p);| Parameter | Description |
|---|---|
| p | Point to include. |
IsEmpty() bool
Checks whether the sphere is empty.
bool Sphere::IsEmpty() const;Radius() float
Returns the sphere radius.
float Sphere::Radius() const;Reset() void
Resets the sphere to an empty state.
void Sphere::Reset();Translate() void
Translates the sphere by a vector.
void Sphere::Translate(const Vector3& translation);| Parameter | Description |
|---|---|
| translation | Offset to apply. |
Union() void
Expands this sphere to fully contain another sphere.
Handles empty spheres, identical centers, and general cases using two directional expansion points.
void Sphere::Union(const Sphere& other);| Parameter | Description |
|---|---|
| other | Sphere to merge. |