TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Sphere.h
Go to the documentation of this file.
1 
12 #ifndef G3D_Sphere_h
13 #define G3D_Sphere_h
14 
15 #include "G3D/platform.h"
16 #include "G3D/Vector3.h"
17 #include "G3D/Array.h"
18 
19 namespace G3D {
20 
24 class Sphere {
25 private:
26 
27  static int32 dummy;
28 
29 public:
31  float radius;
32 
33  Sphere() : center(Point3::zero()), radius(0) {
34  }
35 
36  explicit Sphere(float radius) : radius(radius) {}
37 
38  Sphere(class BinaryInput& b);
39  void serialize(class BinaryOutput& b) const;
40  void deserialize(class BinaryInput& b);
41 
46  explicit Sphere(const class Any& a);
47 
48  Any toAny() const;
49 
50  Sphere
51  (const Point3& center,
52  float radius) : center(center), radius(radius) {
53  }
54 
55  virtual ~Sphere() {}
56 
58  static const Sphere& inf();
59 
60  bool operator==(const Sphere& other) const {
61  return (center == other.center) && (radius == other.radius);
62  }
63 
64  bool operator!=(const Sphere& other) const {
65  return !((center == other.center) && (radius == other.radius));
66  }
67 
72  bool contains(const Point3& point) const;
73 
74  bool contains(const Sphere& other) const;
75 
79  bool culledBy(
80  const class Plane* plane,
81  int numPlanes,
82  int32& cullingPlaneIndex,
83  const uint32 testMask,
84  uint32& childMask) const;
85 
89  bool culledBy(
90  const class Plane* plane,
91  int numPlanes,
92  int32& cullingPlaneIndex = dummy,
93  const uint32 testMask = 0xFFFFFFFF) const;
94 
98  bool culledBy(
99  const Array<Plane>& plane,
100  int32& cullingPlaneIndex,
101  const uint32 testMask,
102  uint32& childMask) const;
103 
107  bool culledBy(
108  const Array<Plane>& plane,
109  int32& cullingPlaneIndex = dummy,
110  const uint32 testMask = 0xFFFFFFFF) const;
111 
112  virtual std::string toString() const;
113 
114  float volume() const;
115 
116  float area() const;
117 
121  Point3 randomSurfacePoint() const;
122 
126  Point3 randomInteriorPoint() const;
127 
128  void getBounds(class AABox& out) const;
129 
130  bool intersects(const Sphere& other) const;
131 
133  Sphere operator+(const Vector3& v) const {
134  return Sphere(center + v, radius);
135  }
136 
138  Sphere operator-(const Vector3& v) const {
139  return Sphere(center - v, radius);
140  }
141 
143  void merge(const Sphere& s);
144 };
145 
146 }
147 
148 template <> struct HashTrait<G3D::Sphere> {
149  static size_t hashCode(const G3D::Sphere& key) {
150  return static_cast<size_t>(key.center.hashCode() + (key.radius * 13));
151  }
152 };
153 
154 
155 #endif
bool intersects(const Sphere &other) const
Definition: Sphere.cpp:91
virtual ~Sphere()
Definition: Sphere.h:55
Definition: Plane.h:25
float volume() const
Definition: Sphere.cpp:242
bool operator!=(const Sphere &other) const
Definition: Sphere.h:64
static const Sphere & inf()
Definition: Sphere.cpp:67
Sphere operator+(const Vector3 &v) const
Definition: Sphere.h:133
Definition: BinaryInput.h:69
float radius
Definition: Sphere.h:31
Definition: HashTrait.h:105
Definition: AABox.h:25
Dynamic 1D array tuned for performance.
Definition: Array.h:95
Sphere()
Definition: Sphere.h:33
void merge(const Sphere &s)
Definition: Sphere.cpp:96
bool operator==(const Sphere &other) const
Definition: Sphere.h:60
void getBounds(class AABox &out) const
Definition: Sphere.cpp:252
virtual std::string toString() const
Definition: Sphere.cpp:73
Definition: Vector3.h:58
Point3 randomSurfacePoint() const
Definition: Sphere.cpp:225
Sphere(float radius)
Definition: Sphere.h:36
Definition: Sphere.h:24
Easy loading and saving of human-readable configuration files.
Definition: Any.h:184
size_t hashCode() const
Definition: Vector3.cpp:155
static int32 dummy
Definition: Sphere.h:27
Sphere operator-(const Vector3 &v) const
Definition: Sphere.h:138
Point3 randomInteriorPoint() const
Definition: Sphere.cpp:230
Any toAny() const
Definition: Sphere.cpp:39
Definition: AABox.h:32
bool culledBy(const class Plane *plane, int numPlanes, int32 &cullingPlaneIndex, const uint32 testMask, uint32 &childMask) const
bool contains(const Point3 &point) const
Definition: Sphere.cpp:79
float area() const
Definition: Sphere.cpp:247
static size_t hashCode(const G3D::Sphere &key)
Definition: Sphere.h:149
Point3 center
Definition: Sphere.h:30
static unorm16 zero()
Definition: unorm16.h:82
Definition: BinaryOutput.h:52
int32_t int32
Definition: g3dmath.h:167
uint32_t uint32
Definition: g3dmath.h:168
void serialize(class BinaryOutput &b) const
Definition: Sphere.cpp:55
void deserialize(class BinaryInput &b)
Definition: Sphere.cpp:61