Browse Source

Some collision work

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
0a1b654f56
2 changed files with 44 additions and 0 deletions
  1. 1 0
      include/anki/collision/ConvexHullShape.h
  2. 43 0
      src/collision/ConvexHullShape.cpp

+ 1 - 0
include/anki/collision/ConvexHullShape.h

@@ -91,6 +91,7 @@ public:
 
 
 private:
 private:
 	Transform m_trf = Transform::getIdentity();
 	Transform m_trf = Transform::getIdentity();
+	Transform m_invTrf = Transform::getIdentity();
 	Vec4* m_points = nullptr;
 	Vec4* m_points = nullptr;
 	U32 m_pointsCount = 0;
 	U32 m_pointsCount = 0;
 	CollisionAllocator<Vec4> m_alloc;
 	CollisionAllocator<Vec4> m_alloc;

+ 43 - 0
src/collision/ConvexHullShape.cpp

@@ -4,6 +4,7 @@
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
 #include "anki/collision/ConvexHullShape.h"
 #include "anki/collision/ConvexHullShape.h"
+#include "anki/collision/Plane.h"
 
 
 namespace anki {
 namespace anki {
 
 
@@ -17,6 +18,8 @@ ConvexHullShape::~ConvexHullShape()
 		m_alloc.deallocate(static_cast<void*>(m_points), m_pointsCount);
 		m_alloc.deallocate(static_cast<void*>(m_points), m_pointsCount);
 	}
 	}
 
 
+	m_trf = Transform::getIdentity();
+	m_invTrf = Transform::getIdentity();
 	m_points = nullptr;
 	m_points = nullptr;
 	m_pointsCount = 0;
 	m_pointsCount = 0;
 	m_alloc = CollisionAllocator<U8>();
 	m_alloc = CollisionAllocator<U8>();
@@ -31,6 +34,9 @@ void ConvexHullShape::move(ConvexHullShape& b)
 
 
 	m_trf = b.m_trf;
 	m_trf = b.m_trf;
 	b.m_trf = Transform::getIdentity();
 	b.m_trf = Transform::getIdentity();
+
+	m_invTrf = b.m_invTrf;
+	b.m_invTrf = Transform::getIdentity();
 	
 	
 	m_points = b.m_points;
 	m_points = b.m_points;
 	b.m_points = nullptr;
 	b.m_points = nullptr;
@@ -78,4 +84,41 @@ void ConvexHullShape::initStorage(void* buffer, U pointCount)
 	ANKI_ASSERT(m_ownsTheStorage == false);
 	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
 } // end namespace anki