public void ProcessTriangle(IndexedVector3[] triangle, int partId, int triangleIndex) { //do a swept sphere for now IndexedMatrix ident = IndexedMatrix.Identity; CastResult castResult = BulletGlobals.CastResultPool.Get(); castResult.m_fraction = m_hitFraction; SphereShape pointShape = BulletGlobals.SphereShapePool.Get(); pointShape.Initialize(m_ccdSphereRadius); using (TriangleShape triShape = BulletGlobals.TriangleShapePool.Get()) { triShape.Initialize(ref triangle[0], ref triangle[1], ref triangle[2]); VoronoiSimplexSolver simplexSolver = BulletGlobals.VoronoiSimplexSolverPool.Get(); SubSimplexConvexCast convexCaster = BulletGlobals.SubSimplexConvexCastPool.Get(); convexCaster.Initialize(pointShape, triShape, simplexSolver); //GjkConvexCast convexCaster(&pointShape,convexShape,&simplexSolver); //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0); //local space? if (convexCaster.CalcTimeOfImpact(ref m_ccdSphereFromTrans, ref m_ccdSphereToTrans, ref ident, ref ident, castResult)) { if (m_hitFraction > castResult.m_fraction) { m_hitFraction = castResult.m_fraction; } } BulletGlobals.SubSimplexConvexCastPool.Free(convexCaster); BulletGlobals.VoronoiSimplexSolverPool.Free(simplexSolver); BulletGlobals.SphereShapePool.Free(pointShape); castResult.Cleanup(); } }
public virtual void ProcessTriangle(IndexedVector3[] triangle, int partId, int triangleIndex) { if (!AabbUtil2.TestTriangleAgainstAabb2(triangle, ref m_aabbMin, ref m_aabbMax)) { return; } //aabb filter is already applied! CollisionAlgorithmConstructionInfo ci = new CollisionAlgorithmConstructionInfo(); ci.SetDispatcher(m_dispatcher); CollisionObject ob = m_triBody as CollisionObject; ///debug drawing of the overlapping triangles /// #if false if (m_dispatchInfoPtr != null && m_dispatchInfoPtr.getDebugDraw() != null && ((m_dispatchInfoPtr.getDebugDraw().GetDebugMode() & DebugDrawModes.DBG_DrawWireframe) > 0)) { IndexedVector3 color = new IndexedVector3(1, 1, 0); IndexedMatrix tr = ob.GetWorldTransform(); IndexedVector3[] transformedTriangles = new IndexedVector3[3]; IndexedVector3.Transform(triangle, ref tr, transformedTriangles); m_dispatchInfoPtr.getDebugDraw().DrawLine(ref transformedTriangles[0], ref transformedTriangles[1], ref color); m_dispatchInfoPtr.getDebugDraw().DrawLine(ref transformedTriangles[1], ref transformedTriangles[2], ref color); m_dispatchInfoPtr.getDebugDraw().DrawLine(ref transformedTriangles[2], ref transformedTriangles[0], ref color); } #endif if (m_convexBody.GetCollisionShape().IsConvex()) { using (TriangleShape tm = BulletGlobals.TriangleShapePool.Get()) { tm.Initialize(ref triangle[0], ref triangle[1], ref triangle[2]); tm.SetMargin(m_collisionMarginTriangle); CollisionShape tmpShape = ob.GetCollisionShape(); ob.InternalSetTemporaryCollisionShape(tm); CollisionAlgorithm colAlgo = ci.GetDispatcher().FindAlgorithm(m_convexBody, m_triBody, m_manifoldPtr); ///this should use the btDispatcher, so the actual registered algorithm is used // btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody); if (m_resultOut.GetBody0Internal() == m_triBody) { m_resultOut.SetShapeIdentifiersA(partId, triangleIndex); } else { m_resultOut.SetShapeIdentifiersB(partId, triangleIndex); } colAlgo.ProcessCollision(m_convexBody, m_triBody, m_dispatchInfoPtr, m_resultOut); ci.GetDispatcher().FreeCollisionAlgorithm(colAlgo); colAlgo = null; ob.InternalSetTemporaryCollisionShape(tmpShape); } } }