5 #include "VectorMath.h"
6 #include "SingleSphere.h"
24 const float fMax = std::numeric_limits<float>::max();
25 const float fMin = -fMax;
27 return Bounds3D(fMax, fMax, fMax, fMin, fMin, fMin);
32 return Bounds3D(v3::Zero(), v3::Zero());
35 static Bounds3D CreateFromPoints(
const std::vector<v3>& points);
37 static inline Bounds3D CreateFromPointPair(
const v3& a,
const v3& b)
77 inline Bounds3D(
float minX,
float minY,
float minZ,
float maxX,
float maxY,
float maxZ)
78 : m_min(minX, minY, minZ)
79 , m_max(maxX, maxY, maxZ)
89 v3 GetMin()
const {
return m_min; }
90 v3 GetMax()
const {
return m_max; }
92 v3 Center()
const {
return (m_min + m_max) * 0.5f; }
94 void SetMinMax(
v3 min,
v3 max)
100 inline void Encapsulate(
const v3& vertex)
102 if(vertex.GetX() < m_min.GetX()) m_min.SetX(vertex.GetX());
103 if(vertex.GetY() < m_min.GetY()) m_min.SetY(vertex.GetY());
104 if(vertex.GetZ() < m_min.GetZ()) m_min.SetZ(vertex.GetZ());
106 if(vertex.GetX() > m_max.GetX()) m_max.SetX(vertex.GetX());
107 if(vertex.GetY() > m_max.GetY()) m_max.SetY(vertex.GetY());
108 if(vertex.GetZ() > m_max.GetZ()) m_max.SetZ(vertex.GetZ());
111 inline bool intersects(
const Bounds3D& bounds)
const
113 if(m_max.x < bounds.m_min.x || m_min.x > bounds.m_max.x)
return false;
114 if(m_max.y < bounds.m_min.y || m_min.y > bounds.m_max.y)
return false;
115 if(m_max.z < bounds.m_min.z || m_min.z > bounds.m_max.z)
return false;
119 bool intersectsXY(
const Bounds3D& bounds)
const
121 return (m_max.GetX() >= bounds.m_min.GetX()) &&
122 (m_min.GetX() <= bounds.m_max.GetX()) &&
123 (m_max.GetY() >= bounds.m_min.GetY()) &&
124 (m_min.GetY() <= bounds.m_max.GetY());
129 float radiusSq = sphere.radius * sphere.radius;
131 v3 deltaMin = sphere.centre - m_min;
132 v3 deltaMax = sphere.centre - m_max;
134 if (deltaMin.x < 0.f)
136 radiusSq -= deltaMin.x*deltaMin.x;
138 else if (deltaMax.x > 0.f)
140 radiusSq -= deltaMax.x*deltaMax.x;
143 if (deltaMin.y < 0.f)
145 radiusSq -= deltaMin.y*deltaMin.y;
147 else if (deltaMax.y > 0.f)
149 radiusSq -= deltaMax.y*deltaMax.y;
152 if (deltaMin.z < 0.f)
154 radiusSq -= deltaMin.z*deltaMin.z;
156 else if (deltaMax.z > 0.f)
158 radiusSq -= deltaMax.z*deltaMax.z;
161 return radiusSq > 0.f;
164 v3 Size()
const {
return (m_max - m_min); };
166 bool Contains(
const v3& p)
const
185 const dv3& GetMin()
const
190 const dv3& GetMax()
const
201 Eegeo::dv3 Center()
const {
return m_min + ((m_max - m_min)/2.0); }
205 if(vertex.GetX() < m_min.GetX()) m_min.SetX(vertex.GetX());
206 if(vertex.GetY() < m_min.GetY()) m_min.SetY(vertex.GetY());
207 if(vertex.GetZ() < m_min.GetZ()) m_min.SetZ(vertex.GetZ());
209 if(vertex.GetX() > m_max.GetX()) m_max.SetX(vertex.GetX());
210 if(vertex.GetY() > m_max.GetY()) m_max.SetY(vertex.GetY());
211 if(vertex.GetZ() > m_max.GetZ()) m_max.SetZ(vertex.GetZ());
214 Eegeo::dv3 Size()
const {
return (m_max - m_min); };
225 Eegeo::v2(std::numeric_limits<float>::max(), std::numeric_limits<float>::max()),
226 Eegeo::v2(-std::numeric_limits<float>::max(), -std::numeric_limits<float>::max())
236 :min(Eegeo::v2::Zero())
237 ,max(Eegeo::v2::Zero())
245 bool intersects(
const Bounds2D& bounds)
const
247 return (max.GetX() >= bounds.min.GetX()) &&
248 (min.GetX() <= bounds.max.GetX()) &&
249 (max.GetY() >= bounds.min.GetY()) &&
250 (min.GetY() <= bounds.max.GetY());
253 bool contains(
float x,
float y)
const
255 return (max.GetX() >= x) &&
261 inline void Encapsulate(
const Bounds2D& other)
263 min = v2::Min(min, other.min);
264 max = v2::Max(max, other.max);
269 min = v2::Min(min, point);
270 max = v2::Max(max, point);
273 void GetClockwiseVertices(
v4* pVertices)
const
275 pVertices[0] =
v4(min.GetX(), min.GetY(), 0, 1);
276 pVertices[1] =
v4(min.GetX(), max.GetY(), 0, 1);
277 pVertices[2] =
v4(max.GetX(), max.GetY(), 0, 1);
278 pVertices[3] =
v4(max.GetX(), min.GetY(), 0, 1);
283 return (min + max) * 0.5f;
291 void Translate(
const v2& translation)