protected void ShapeVsShapeCollision(
            CollisionObject body0,
            CollisionObject body1,
            CollisionShape shape0,
            CollisionShape shape1)
        {
            CollisionShape tmpShape0 = body0.GetCollisionShape();
            CollisionShape tmpShape1 = body1.GetCollisionShape();

            body0.InternalSetTemporaryCollisionShape(shape0);
            body1.InternalSetTemporaryCollisionShape(shape1);

            if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo)
            {
                BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::ShapeVsShape");
            }



            {
                CollisionAlgorithm algor = NewAlgorithm(body0, body1);
                // post :	checkManifold is called

                m_resultOut.SetShapeIdentifiersA(m_part0, m_triface0);
                m_resultOut.SetShapeIdentifiersB(m_part1, m_triface1);

                algor.ProcessCollision(body0, body1, m_dispatchInfo, m_resultOut);

                m_dispatcher.FreeCollisionAlgorithm(algor);
            }

            body0.InternalSetTemporaryCollisionShape(tmpShape0);
            body1.InternalSetTemporaryCollisionShape(tmpShape1);
        }
Example #2
0
 public virtual void FreeCollisionAlgorithm(CollisionAlgorithm collisionAlgorithm)
 {
     if (collisionAlgorithm != null)
     {
         collisionAlgorithm.Cleanup();
     }
 }
Example #3
0
        private void PreallocateChildAlgorithms(CollisionObject body0, CollisionObject body1)
        {
            CollisionObject colObj   = m_isSwapped ? body1 : body0;
            CollisionObject otherObj = m_isSwapped ? body0 : body1;

            Debug.Assert(colObj.GetCollisionShape().IsCompound());

            CompoundShape compoundShape = (CompoundShape)(colObj.GetCollisionShape());

            int numChildren = compoundShape.GetNumChildShapes();
            int i;

            //m_childCollisionAlgorithms.resize(numChildren);
            m_childCollisionAlgorithms.Clear();
            for (i = 0; i < numChildren; i++)
            {
                if (compoundShape.GetDynamicAabbTree() != null)
                {
                    m_childCollisionAlgorithms.Add(null);
                }
                else
                {
                    CollisionShape tmpShape   = colObj.GetCollisionShape();
                    CollisionShape childShape = compoundShape.GetChildShape(i);
                    colObj.InternalSetTemporaryCollisionShape(childShape);
                    CollisionAlgorithm ca = m_dispatcher.FindAlgorithm(colObj, otherObj, m_sharedManifold);
                    m_childCollisionAlgorithms.Add(ca);
                    colObj.InternalSetTemporaryCollisionShape(tmpShape);
                }
            }
        }
 protected void DestroyConvexAlgorithm()
 {
     if (m_convex_algorithm != null)
     {
         m_dispatcher.FreeCollisionAlgorithm(m_convex_algorithm);
         m_convex_algorithm = null;
     }
 }
 protected void DestroyConvexAlgorithm()
 {
     if (m_convex_algorithm != null)
     {
         m_dispatcher.FreeCollisionAlgorithm(m_convex_algorithm);
         m_convex_algorithm = null;
     }
 }
        // Call before process collision
        protected CollisionAlgorithm NewAlgorithm(CollisionObject body0, CollisionObject body1)
        {
            CheckManifold(body0, body1);

            CollisionAlgorithm convex_algorithm = m_dispatcher.FindAlgorithm(
                body0, body1, GetLastManifold());

            return(convex_algorithm);
        }
Example #7
0
        public virtual void ProcessTriangle(IndexedVector3[] triangle, int partId, int triangleIndex)
        {
            //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);
                }
            }
        }
        // Call before process collision
        protected void CheckConvexAlgorithm(CollisionObject body0, CollisionObject body1)
        {
            if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo)
            {
                BulletGlobals.g_streamWriter.WriteLine("GImpactAlgo::CheckConvexAlgo");
            }

            if (m_convex_algorithm != null)
            {
                return;
            }
            m_convex_algorithm = NewAlgorithm(body0, body1);
        }
        // Call before process collision
        protected void CheckConvexAlgorithm(CollisionObject body0, CollisionObject body1)
        {
            if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo)
            {
                BulletGlobals.g_streamWriter.WriteLine("GImpactAlgo::CheckConvexAlgo");
            }

            if (m_convex_algorithm != null)
            {
                return;
            }
            m_convex_algorithm = NewAlgorithm(body0, body1);
        }
 public virtual void FreeCollisionAlgorithm(CollisionAlgorithm collisionAlgorithm)
 {
     if (collisionAlgorithm != null)
     {
         collisionAlgorithm.Cleanup();
     }
 }