|
|
@@ -25,6 +25,10 @@
|
|
|
#include "../Math/Rect.h"
|
|
|
#include "../Math/Vector3.h"
|
|
|
|
|
|
+#ifdef URHO3D_SSE
|
|
|
+#include <xmmintrin.h>
|
|
|
+#endif
|
|
|
+
|
|
|
namespace Urho3D
|
|
|
{
|
|
|
|
|
|
@@ -41,68 +45,67 @@ class URHO3D_API BoundingBox
|
|
|
public:
|
|
|
/// Construct with zero size.
|
|
|
BoundingBox() :
|
|
|
- min_(Vector3::ZERO),
|
|
|
- max_(Vector3::ZERO),
|
|
|
- defined_(false)
|
|
|
+ min_(M_INFINITY, M_INFINITY, M_INFINITY),
|
|
|
+ max_(-M_INFINITY, -M_INFINITY, -M_INFINITY)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/// Copy-construct from another bounding box.
|
|
|
BoundingBox(const BoundingBox& box) :
|
|
|
min_(box.min_),
|
|
|
- max_(box.max_),
|
|
|
- defined_(box.defined_)
|
|
|
+ max_(box.max_)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/// Construct from a rect, with the Z dimension left zero.
|
|
|
BoundingBox(const Rect& rect) :
|
|
|
min_(Vector3(rect.min_, 0.0f)),
|
|
|
- max_(Vector3(rect.max_, 0.0f)),
|
|
|
- defined_(true)
|
|
|
+ max_(Vector3(rect.max_, 0.0f))
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/// Construct from minimum and maximum vectors.
|
|
|
BoundingBox(const Vector3& min, const Vector3& max) :
|
|
|
min_(min),
|
|
|
- max_(max),
|
|
|
- defined_(true)
|
|
|
+ max_(max)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/// Construct from minimum and maximum floats (all dimensions same.)
|
|
|
BoundingBox(float min, float max) :
|
|
|
min_(Vector3(min, min, min)),
|
|
|
- max_(Vector3(max, max, max)),
|
|
|
- defined_(true)
|
|
|
+ max_(Vector3(max, max, max))
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/// Construct from an array of vertices.
|
|
|
BoundingBox(const Vector3* vertices, unsigned count) :
|
|
|
- defined_(false)
|
|
|
+ min_(M_INFINITY, M_INFINITY, M_INFINITY),
|
|
|
+ max_(-M_INFINITY, -M_INFINITY, -M_INFINITY)
|
|
|
{
|
|
|
Define(vertices, count);
|
|
|
}
|
|
|
|
|
|
/// Construct from a frustum.
|
|
|
BoundingBox(const Frustum& frustum) :
|
|
|
- defined_(false)
|
|
|
+ min_(M_INFINITY, M_INFINITY, M_INFINITY),
|
|
|
+ max_(-M_INFINITY, -M_INFINITY, -M_INFINITY)
|
|
|
{
|
|
|
Define(frustum);
|
|
|
}
|
|
|
|
|
|
/// Construct from a polyhedron.
|
|
|
BoundingBox(const Polyhedron& poly) :
|
|
|
- defined_(false)
|
|
|
+ min_(M_INFINITY, M_INFINITY, M_INFINITY),
|
|
|
+ max_(-M_INFINITY, -M_INFINITY, -M_INFINITY)
|
|
|
{
|
|
|
Define(poly);
|
|
|
}
|
|
|
|
|
|
/// Construct from a sphere.
|
|
|
BoundingBox(const Sphere& sphere) :
|
|
|
- defined_(false)
|
|
|
+ min_(M_INFINITY, M_INFINITY, M_INFINITY),
|
|
|
+ max_(-M_INFINITY, -M_INFINITY, -M_INFINITY)
|
|
|
{
|
|
|
Define(sphere);
|
|
|
}
|
|
|
@@ -112,7 +115,6 @@ public:
|
|
|
{
|
|
|
min_ = rhs.min_;
|
|
|
max_ = rhs.max_;
|
|
|
- defined_ = rhs.defined_;
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
@@ -121,7 +123,6 @@ public:
|
|
|
{
|
|
|
min_ = Vector3(rhs.min_, 0.0f);
|
|
|
max_ = Vector3(rhs.max_, 0.0f);
|
|
|
- defined_ = true;
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
@@ -148,7 +149,6 @@ public:
|
|
|
{
|
|
|
min_ = min;
|
|
|
max_ = max;
|
|
|
- defined_ = true;
|
|
|
}
|
|
|
|
|
|
/// Define from minimum and maximum floats (all dimensions same.)
|
|
|
@@ -156,26 +156,28 @@ public:
|
|
|
{
|
|
|
min_ = Vector3(min, min, min);
|
|
|
max_ = Vector3(max, max, max);
|
|
|
- defined_ = true;
|
|
|
}
|
|
|
|
|
|
/// Define from a point.
|
|
|
void Define(const Vector3& point)
|
|
|
{
|
|
|
min_ = max_ = point;
|
|
|
- defined_ = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Returns true if this bounding box is defined via a previous call to Define() or Merge().
|
|
|
+ bool Defined() const
|
|
|
+ {
|
|
|
+ return min_.x_ != M_INFINITY;
|
|
|
}
|
|
|
|
|
|
/// Merge a point.
|
|
|
void Merge(const Vector3& point)
|
|
|
{
|
|
|
- if (!defined_)
|
|
|
- {
|
|
|
- min_ = max_ = point;
|
|
|
- defined_ = true;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+#ifdef URHO3D_SSE
|
|
|
+ __m128 vec = _mm_set_ps(1.f, point.z_, point.y_, point.x_);
|
|
|
+ _mm_storeu_ps(&min_.x_, _mm_min_ps(_mm_loadu_ps(&min_.x_), vec));
|
|
|
+ _mm_storeu_ps(&max_.x_, _mm_max_ps(_mm_loadu_ps(&max_.x_), vec));
|
|
|
+#else
|
|
|
if (point.x_ < min_.x_)
|
|
|
min_.x_ = point.x_;
|
|
|
if (point.y_ < min_.y_)
|
|
|
@@ -188,19 +190,16 @@ public:
|
|
|
max_.y_ = point.y_;
|
|
|
if (point.z_ > max_.z_)
|
|
|
max_.z_ = point.z_;
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
/// Merge another bounding box.
|
|
|
void Merge(const BoundingBox& box)
|
|
|
{
|
|
|
- if (!defined_)
|
|
|
- {
|
|
|
- min_ = box.min_;
|
|
|
- max_ = box.max_;
|
|
|
- defined_ = true;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+#ifdef URHO3D_SSE
|
|
|
+ _mm_storeu_ps(&min_.x_, _mm_min_ps(_mm_loadu_ps(&min_.x_), _mm_loadu_ps(&box.min_.x_)));
|
|
|
+ _mm_storeu_ps(&max_.x_, _mm_max_ps(_mm_loadu_ps(&max_.x_), _mm_loadu_ps(&box.max_.x_)));
|
|
|
+#else
|
|
|
if (box.min_.x_ < min_.x_)
|
|
|
min_.x_ = box.min_.x_;
|
|
|
if (box.min_.y_ < min_.y_)
|
|
|
@@ -213,6 +212,7 @@ public:
|
|
|
max_.y_ = box.max_.y_;
|
|
|
if (box.max_.z_ > max_.z_)
|
|
|
max_.z_ = box.max_.z_;
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
/// Define from an array of vertices.
|
|
|
@@ -241,9 +241,13 @@ public:
|
|
|
/// Clear to undefined state.
|
|
|
void Clear()
|
|
|
{
|
|
|
- min_ = Vector3::ZERO;
|
|
|
- max_ = Vector3::ZERO;
|
|
|
- defined_ = false;
|
|
|
+#ifdef URHO3D_SSE
|
|
|
+ _mm_storeu_ps(&min_.x_, _mm_set1_ps(M_INFINITY));
|
|
|
+ _mm_storeu_ps(&max_.x_, _mm_set1_ps(-M_INFINITY));
|
|
|
+#else
|
|
|
+ min_ = Vector3(M_INFINITY, M_INFINITY, M_INFINITY);
|
|
|
+ max_ = Vector3(-M_INFINITY, -M_INFINITY, -M_INFINITY);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
/// Return center.
|
|
|
@@ -305,10 +309,14 @@ public:
|
|
|
|
|
|
/// Minimum vector.
|
|
|
Vector3 min_;
|
|
|
+#ifdef URHO3D_SSE
|
|
|
+ float dummyMin_; // This is never used, but exists to pad the min_ value to four floats.
|
|
|
+#endif
|
|
|
/// Maximum vector.
|
|
|
Vector3 max_;
|
|
|
- /// Defined flag.
|
|
|
- bool defined_;
|
|
|
+#ifdef URHO3D_SSE
|
|
|
+ float dummyMax_; // This is never used, but exists to pad the max_ value to four floats.
|
|
|
+#endif
|
|
|
};
|
|
|
|
|
|
}
|