1 | /** |
---|
2 | @file Sphere.h |
---|
3 | |
---|
4 | Sphere class |
---|
5 | |
---|
6 | @maintainer Morgan McGuire, matrix@graphics3d.com |
---|
7 | |
---|
8 | @created 2001-06-02 |
---|
9 | @edited 2004-07-05 |
---|
10 | */ |
---|
11 | |
---|
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 | #include "G3D/Sphere.h" |
---|
19 | |
---|
20 | namespace G3D { |
---|
21 | |
---|
22 | /** |
---|
23 | Sphere. |
---|
24 | */ |
---|
25 | class Sphere { |
---|
26 | private: |
---|
27 | |
---|
28 | static int32 dummy; |
---|
29 | |
---|
30 | public: |
---|
31 | Vector3 center; |
---|
32 | float radius; |
---|
33 | |
---|
34 | Sphere() { |
---|
35 | center = Vector3::zero(); |
---|
36 | radius = 0; |
---|
37 | } |
---|
38 | |
---|
39 | Sphere( |
---|
40 | const Vector3& center, |
---|
41 | float radius) { |
---|
42 | |
---|
43 | this->center = center; |
---|
44 | this->radius = radius; |
---|
45 | } |
---|
46 | |
---|
47 | virtual ~Sphere() {} |
---|
48 | |
---|
49 | bool operator==(const Sphere& other) const { |
---|
50 | return (center == other.center) && (radius == other.radius); |
---|
51 | } |
---|
52 | |
---|
53 | bool operator!=(const Sphere& other) const { |
---|
54 | return !((center == other.center) && (radius == other.radius)); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | Returns true if point is less than or equal to radius away from |
---|
59 | the center. |
---|
60 | */ |
---|
61 | bool contains(const Vector3& point) const; |
---|
62 | |
---|
63 | /** |
---|
64 | @deprecated Use culledBy(Array<Plane>&) |
---|
65 | */ |
---|
66 | bool culledBy( |
---|
67 | const class Plane* plane, |
---|
68 | int numPlanes, |
---|
69 | int32& cullingPlaneIndex, |
---|
70 | const uint32 testMask, |
---|
71 | uint32& childMask) const; |
---|
72 | |
---|
73 | /** |
---|
74 | @deprecated Use culledBy(Array<Plane>&) |
---|
75 | */ |
---|
76 | bool culledBy( |
---|
77 | const class Plane* plane, |
---|
78 | int numPlanes, |
---|
79 | int32& cullingPlaneIndex = dummy, |
---|
80 | const uint32 testMask = -1) const; |
---|
81 | |
---|
82 | /** |
---|
83 | See AABox::culledBy |
---|
84 | */ |
---|
85 | bool culledBy( |
---|
86 | const Array<Plane>& plane, |
---|
87 | int32& cullingPlaneIndex, |
---|
88 | const uint32 testMask, |
---|
89 | uint32& childMask) const; |
---|
90 | |
---|
91 | /** |
---|
92 | Conservative culling test that does not produce a mask for children. |
---|
93 | */ |
---|
94 | bool culledBy( |
---|
95 | const Array<Plane>& plane, |
---|
96 | int32& cullingPlaneIndex = dummy, |
---|
97 | const uint32 testMask = -1) const; |
---|
98 | virtual std::string toString() const; |
---|
99 | |
---|
100 | float volume() const; |
---|
101 | |
---|
102 | /** @deprecated */ |
---|
103 | float surfaceArea() const; |
---|
104 | |
---|
105 | inline float area() const { |
---|
106 | return surfaceArea(); |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | Uniformly distributed on the surface. |
---|
111 | */ |
---|
112 | Vector3 randomSurfacePoint() const; |
---|
113 | |
---|
114 | /** |
---|
115 | Uniformly distributed on the interior (includes surface) |
---|
116 | */ |
---|
117 | Vector3 randomInteriorPoint() const; |
---|
118 | |
---|
119 | void getBounds(class AABox& out) const; |
---|
120 | }; |
---|
121 | |
---|
122 | } // namespace |
---|
123 | |
---|
124 | inline unsigned int hashCode(const G3D::Sphere& sphere) { |
---|
125 | return (unsigned int)(hashCode(sphere.center) + (sphere.radius * 13)); |
---|
126 | } |
---|
127 | |
---|
128 | #endif |
---|