32 #ifndef Sphere_INCLUDE_ONCE 33 #define Sphere_INCLUDE_ONCE 50 Sphere(
const vec3& center, real radius): mCenter(center), mRadius(radius) {}
59 bool isNull()
const {
return mRadius < 0.0f; }
62 bool isPoint()
const {
return mRadius == 0.0f; }
74 real
radius()
const {
return mRadius; }
87 return radius() >= distance + other.
radius();
134 if (!other.
isNull() && !this->includes(other))
141 setRadius( radius() > other.
radius() ? radius() : other.
radius() );
146 vec3 p0 = this->center() - v * this->radius();
148 setCenter( (p0 + p1)*(real)0.5 );
149 setRadius( (p0 - p1).
length()*(real)0.5 );
167 vec3 p0 = center() +
vec3(radius(),0,0);
168 vec3 p1 = center() +
vec3(0,radius(),0);
169 vec3 p2 = center() +
vec3(0,0,radius());
173 real d0 = (p0 - out.
mCenter).lengthSquared();
174 real d1 = (p1 - out.
mCenter).lengthSquared();
175 real d2 = (p2 - out.
mCenter).lengthSquared();
176 out.
mRadius =
::sqrt( d0>d1 ? (d0>d2?d0:d2) : (d1>d2?d1:d2) );
184 transformed(sphere, mat);
const Vector3 & normalize(T_Scalar *len=NULL)
bool operator!=(const Sphere &other) const
Returns true if two spheres are not identical.
bool isNull() const
Returns true if the AABB is null.
const vec3 & center() const
Returns the center of the sphere.
const Sphere & operator+=(const Sphere &other)
Enlarges the sphere to contain the specified sphere.
vec3 center() const
Returns the center of the AABB.
Sphere operator+(const Sphere &other)
Returns a sphere that contains the two specified spheres.
Visualization Library main namespace.
real radius() const
Returns the radius of the sphere.
bool isPoint() const
Returns true if the sphere as radius == 0.
The AABB class implements an axis-aligned bounding box using vl::real precision.
const vec3 & maxCorner() const
Returns the corner of the AABB with the maximum x y z coordinates.
Sphere transformed(const mat4 &mat) const
Returns a sphere that contains the original sphere transformed by the given matrix.
void setRadius(real radius)
Sets the radius of the sphere.
The Sphere class defines a sphere using a center and a radius using vl::real precision.
const vec3 & minCorner() const
Returns the corner of the AABB with the minimum x y z coordinates.
Sphere(const AABB &aabb)
Copy-constructor.
void setNull()
Sets the sphere as null.
fvec3 vec3
Defined as: 'typedef fvec3 vec3'. See also VL_PIPELINE_PRECISION.
bool operator==(const ref< T1 > &o1, const ref< T2 > &o2)
bool includes(const Sphere &other) const
Returns true if a sphere contains the specified sphere.
Sphere()
Constructor: creates a null sphere.
void transformed(Sphere &out, const mat4 &mat) const
Returns a sphere that contains the original sphere transformed by the given matrix.
bool isNull() const
Returns true if the sphere is null, ie, if radius is < 0.
Sphere(const vec3 ¢er, real radius)
Constructor: creates a sphere with the given center and radius.
bool operator==(const Sphere &other) const
Returns true if two spheres are identical.
void setCenter(const vec3 ¢er)
Sets the center of the sphere.
Sphere & operator=(const AABB &aabb)
Constructs a sphere that contains the specified AABB.