TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Sphere Class Reference

#include <Sphere.h>

Public Member Functions

 Sphere ()
 
 Sphere (float radius)
 
 Sphere (class BinaryInput &b)
 
void serialize (class BinaryOutput &b) const
 
void deserialize (class BinaryInput &b)
 
 Sphere (const class Any &a)
 
Any toAny () const
 
 Sphere (const Point3 &center, float radius)
 
virtual ~Sphere ()
 
bool operator== (const Sphere &other) const
 
bool operator!= (const Sphere &other) const
 
bool contains (const Point3 &point) const
 
bool contains (const Sphere &other) const
 
bool culledBy (const class Plane *plane, int numPlanes, int32 &cullingPlaneIndex, const uint32 testMask, uint32 &childMask) const
 
bool culledBy (const class Plane *plane, int numPlanes, int32 &cullingPlaneIndex=dummy, const uint32 testMask=0xFFFFFFFF) const
 
bool culledBy (const Array< Plane > &plane, int32 &cullingPlaneIndex, const uint32 testMask, uint32 &childMask) const
 
bool culledBy (const Array< Plane > &plane, int32 &cullingPlaneIndex=dummy, const uint32 testMask=0xFFFFFFFF) const
 
virtual std::string toString () const
 
float volume () const
 
float area () const
 
Point3 randomSurfacePoint () const
 
Point3 randomInteriorPoint () const
 
void getBounds (class AABox &out) const
 
bool intersects (const Sphere &other) const
 
Sphere operator+ (const Vector3 &v) const
 
Sphere operator- (const Vector3 &v) const
 
void merge (const Sphere &s)
 

Static Public Member Functions

static const Sphereinf ()
 

Public Attributes

Point3 center
 
float radius
 

Static Private Attributes

static int32 dummy
 

Detailed Description

Constructor & Destructor Documentation

G3D::Sphere::Sphere ( )
inline
33  : center(Point3::zero()), radius(0) {
34  }
float radius
Definition: Sphere.h:31
static const Vector3 & zero()
Definition: Vector3.cpp:119
Point3 center
Definition: Sphere.h:30

+ Here is the caller graph for this function:

G3D::Sphere::Sphere ( float  radius)
inlineexplicit
36 : radius(radius) {}
float radius
Definition: Sphere.h:31
G3D::Sphere::Sphere ( class BinaryInput b)
50  {
51  deserialize(b);
52 }
void deserialize(class BinaryInput &b)
Definition: Sphere.cpp:61

+ Here is the call graph for this function:

G3D::Sphere::Sphere ( const class Any a)
explicit

Format is one of:

  • Sphere(point, radius)
  • Sphere(radius)
G3D::Sphere::Sphere ( const Point3 center,
float  radius 
)
inline
52  : center(center), radius(radius) {
53  }
float radius
Definition: Sphere.h:31
Point3 center
Definition: Sphere.h:30
virtual G3D::Sphere::~Sphere ( )
inlinevirtual
55 {}

Member Function Documentation

float G3D::Sphere::area ( ) const
247  {
248  return (float)pi() * 4.0f * powf((float)radius, 2.0f);
249 }
float radius
Definition: Sphere.h:31
double pi()
Definition: g3dmath.h:147

+ Here is the call graph for this function:

bool G3D::Sphere::contains ( const Point3 point) const

Returns true if point is less than or equal to radius away from the center.

79  {
80  float distance = (center - point).squaredMagnitude();
81  return distance <= square(radius);
82 }
float radius
Definition: Sphere.h:31
double distance(double x, double y)
Definition: g3dmath.h:731
double square(double fValue)
Definition: g3dmath.h:698
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::Sphere::contains ( const Sphere other) const
85  {
86  float distance = (center - other.center).squaredMagnitude();
87  return (radius >= other.radius) && (distance <= square(radius - other.radius));
88 }
float radius
Definition: Sphere.h:31
double distance(double x, double y)
Definition: g3dmath.h:731
double square(double fValue)
Definition: g3dmath.h:698
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

bool G3D::Sphere::culledBy ( const class Plane plane,
int  numPlanes,
int32 cullingPlaneIndex,
const uint32  testMask,
uint32 childMask 
) const
Deprecated:
Use culledBy(Array<Plane>&)
bool G3D::Sphere::culledBy ( const class Plane plane,
int  numPlanes,
int32 cullingPlaneIndex = dummy,
const uint32  testMask = 0xFFFFFFFF 
) const
Deprecated:
Use culledBy(Array<Plane>&)
bool G3D::Sphere::culledBy ( const Array< Plane > &  plane,
int32 cullingPlaneIndex,
const uint32  testMask,
uint32 childMask 
) const
bool G3D::Sphere::culledBy ( const Array< Plane > &  plane,
int32 cullingPlaneIndex = dummy,
const uint32  testMask = 0xFFFFFFFF 
) const

Conservative culling test that does not produce a mask for children.

void G3D::Sphere::deserialize ( class BinaryInput b)
61  {
63  radius = (float)b.readFloat64();
64 }
float radius
Definition: Sphere.h:31
void deserialize(class BinaryInput &b)
Definition: Vector3.cpp:190
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::Sphere::getBounds ( class AABox out) const
252  {
253  Vector3 extent(radius, radius, radius);
254  out = AABox(center - extent, center + extent);
255 }
float radius
Definition: Sphere.h:31
Point3 center
Definition: Sphere.h:30

+ Here is the caller graph for this function:

const Sphere & G3D::Sphere::inf ( )
static

Returns the infinite sphere.

67  {
68  static const Sphere s(Point3::zero(), finf());
69  return s;
70 }
float finf()
Definition: g3dmath.cpp:71
Sphere()
Definition: Sphere.h:33
static const Vector3 & zero()
Definition: Vector3.cpp:119

+ Here is the call graph for this function:

bool G3D::Sphere::intersects ( const Sphere other) const
91  {
92  return (other.center - center).length() <= (radius + other.radius);
93 }
float radius
Definition: Sphere.h:31
Point3 center
Definition: Sphere.h:30
void G3D::Sphere::merge ( const Sphere s)

Sets this to the smallest sphere that encapsulates both

96  {
97  if (other.contains(*this)) {
98  *this = other;
99  } else if (! contains(other)) {
100  // The farthest distance is along the axis between the centers, which
101  // must not be colocated since neither contains the other.
102  Vector3 toMe = center - other.center;
103  // Get a point on the axis from each
104  toMe = toMe.direction();
105  const Vector3& A = center + toMe * radius;
106  const Vector3& B = other.center - toMe * other.radius;
107 
108  // Now just bound the A->B segment
109  center = (A + B) * 0.5f;
110  radius = (A - B).length();
111  }
112  // (if this contains other, we're done)
113 }
float radius
Definition: Sphere.h:31
Vector3 direction() const
Definition: Vector3.h:756
float length(float v)
Definition: vectorMath.h:208
bool contains(const Point3 &point) const
Definition: Sphere.cpp:79
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

bool G3D::Sphere::operator!= ( const Sphere other) const
inline
64  {
65  return !((center == other.center) && (radius == other.radius));
66  }
float radius
Definition: Sphere.h:31
Point3 center
Definition: Sphere.h:30
Sphere G3D::Sphere::operator+ ( const Vector3 v) const
inline

Translates the sphere

133  {
134  return Sphere(center + v, radius);
135  }
float radius
Definition: Sphere.h:31
Sphere()
Definition: Sphere.h:33
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

Sphere G3D::Sphere::operator- ( const Vector3 v) const
inline

Translates the sphere

138  {
139  return Sphere(center - v, radius);
140  }
float radius
Definition: Sphere.h:31
Sphere()
Definition: Sphere.h:33
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

bool G3D::Sphere::operator== ( const Sphere other) const
inline
60  {
61  return (center == other.center) && (radius == other.radius);
62  }
float radius
Definition: Sphere.h:31
Point3 center
Definition: Sphere.h:30
Vector3 G3D::Sphere::randomInteriorPoint ( ) const

Uniformly distributed on the interior (includes surface)

230  {
231  Vector3 result;
232  do {
233  result = Vector3(uniformRandom(-1, 1),
234  uniformRandom(-1, 1),
235  uniformRandom(-1, 1));
236  } while (result.squaredMagnitude() >= 1.0f);
237 
238  return result * radius + center;
239 }
float radius
Definition: Sphere.h:31
float uniformRandom(float low=0.0f, float hi=1.0f)
Definition: g3dmath.h:694
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector3 G3D::Sphere::randomSurfacePoint ( ) const

Uniformly distributed on the surface.

225  {
226  return Vector3::random() * radius + center;
227 }
float radius
Definition: Sphere.h:31
static Vector3 random(Random &r=Random::common())
Random unit vector, uniformly distributed on the sphere.
Definition: Vector3.cpp:226
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::Sphere::serialize ( class BinaryOutput b) const
55  {
56  center.serialize(b);
57  b.writeFloat64(radius);
58 }
float radius
Definition: Sphere.h:31
void serialize(class BinaryOutput &b) const
Definition: Vector3.cpp:219
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

Any G3D::Sphere::toAny ( ) const
39  {
40  Any a(Any::ARRAY, "Sphere");
41  if (center != Point3::zero()) {
42  a.append(center);
43  }
44 
45  a.append(radius);
46  return a;
47 }
float radius
Definition: Sphere.h:31
Definition: Any.h:187
static const Vector3 & zero()
Definition: Vector3.cpp:119
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

std::string G3D::Sphere::toString ( ) const
virtual
73  {
74  return format("Sphere(<%g, %g, %g>, %g)",
76 }
float x
Definition: Vector3.h:62
float radius
Definition: Sphere.h:31
float y
Definition: Vector3.h:62
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
float z
Definition: Vector3.h:62
Point3 center
Definition: Sphere.h:30

+ Here is the call graph for this function:

float G3D::Sphere::volume ( ) const
242  {
243  return (float)pi() * (4.0f / 3.0f) * powf((float)radius, 3.0f);
244 }
float radius
Definition: Sphere.h:31
double pi()
Definition: g3dmath.h:147

+ Here is the call graph for this function:

Member Data Documentation

Point3 G3D::Sphere::center
int32 G3D::Sphere::dummy
staticprivate
float G3D::Sphere::radius

The documentation for this class was generated from the following files: