|
|
@@ -4,6 +4,7 @@
|
|
|
// http://www.anki3d.org/LICENSE
|
|
|
|
|
|
#include "anki/collision/ConvexHullShape.h"
|
|
|
+#include "anki/collision/Plane.h"
|
|
|
|
|
|
namespace anki {
|
|
|
|
|
|
@@ -17,6 +18,8 @@ ConvexHullShape::~ConvexHullShape()
|
|
|
m_alloc.deallocate(static_cast<void*>(m_points), m_pointsCount);
|
|
|
}
|
|
|
|
|
|
+ m_trf = Transform::getIdentity();
|
|
|
+ m_invTrf = Transform::getIdentity();
|
|
|
m_points = nullptr;
|
|
|
m_pointsCount = 0;
|
|
|
m_alloc = CollisionAllocator<U8>();
|
|
|
@@ -31,6 +34,9 @@ void ConvexHullShape::move(ConvexHullShape& b)
|
|
|
|
|
|
m_trf = b.m_trf;
|
|
|
b.m_trf = Transform::getIdentity();
|
|
|
+
|
|
|
+ m_invTrf = b.m_invTrf;
|
|
|
+ b.m_invTrf = Transform::getIdentity();
|
|
|
|
|
|
m_points = b.m_points;
|
|
|
b.m_points = nullptr;
|
|
|
@@ -78,4 +84,41 @@ void ConvexHullShape::initStorage(void* buffer, U pointCount)
|
|
|
ANKI_ASSERT(m_ownsTheStorage == false);
|
|
|
}
|
|
|
|
|
|
+//==============================================================================
|
|
|
+F32 ConvexHullShape::testPlane(const Plane& p) const
|
|
|
+{
|
|
|
+ // Compute the invert transformation of the plane instead
|
|
|
+ Plane pa = p.getTransformed(m_invTrf);
|
|
|
+
|
|
|
+ F32 minDist = MAX_F32;
|
|
|
+
|
|
|
+ const Vec4* point = m_points;
|
|
|
+ const Vec4* end = m_points + m_pointsCount;
|
|
|
+ for(; point != end; ++point)
|
|
|
+ {
|
|
|
+ F32 test = pa.test(*point);
|
|
|
+ if(test == 0.0)
|
|
|
+ {
|
|
|
+ // Early exit
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ minDist = min(minDist, test);
|
|
|
+ }
|
|
|
+
|
|
|
+ return minDist;
|
|
|
+}
|
|
|
+
|
|
|
+//==============================================================================
|
|
|
+void ConvexHullShape::transform(const Transform& trf)
|
|
|
+{
|
|
|
+ m_trf = m_trf.combineTransformations(trf);
|
|
|
+ m_invTrf = m_trf.getInverse();
|
|
|
+}
|
|
|
+
|
|
|
+//==============================================================================
|
|
|
+void ConvexHullShape::computeAabb(Aabb& aabb) const
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
} // end namespace anki
|