static bool QuantizedNodeCollision(
            GImpactQuantizedBvh boxset0, GImpactQuantizedBvh boxset1,
            BT_BOX_BOX_TRANSFORM_CACHE trans_cache_1to0,
            int node0, int node1, bool complete_primitive_tests)
        {
            AABB box0;

            boxset0.GetNodeBound(node0, out box0);
            AABB box1;

            boxset1.GetNodeBound(node1, out box1);

            return(box0.OverlappingTransCache(ref box1, ref trans_cache_1to0, complete_primitive_tests));
            //	box1.appy_transform_trans_cache(trans_cache_1to0);
            //	return box0.has_collision(box1);
        }
Beispiel #2
0
        public void GImpactVsGImpactFindPairs(
            ref IndexedMatrix trans0,
            ref IndexedMatrix trans1,
            GImpactShapeInterface shape0,
            GImpactShapeInterface shape1, PairSet pairset)
        {
            if (shape0.HasBoxSet() && shape1.HasBoxSet())
            {
                GImpactQuantizedBvh.FindCollision(shape0.GetBoxSet(), ref trans0, shape1.GetBoxSet(), ref trans1, pairset);
            }
            else
            {
                AABB boxshape0 = new AABB();
                AABB boxshape1 = new AABB();
                int  i         = shape0.GetNumChildShapes();

                while (i-- != 0)
                {
                    shape0.GetChildAabb(i, ref trans0, out boxshape0.m_min, out boxshape0.m_max);

                    int j = shape1.GetNumChildShapes();
                    while (j-- != 0)
                    {
                        shape1.GetChildAabb(i, ref trans1, out boxshape1.m_min, out boxshape1.m_max);

                        if (boxshape1.HasCollision(ref boxshape0))
                        {
                            pairset.PushPair(i, j);
                        }
                    }
                }
            }
#if DEBUG
            if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo)
            {
                BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsGImpactFindPairs [{0}]", pairset.Count);
            }
#endif
        }
        public static void FindCollision(GImpactQuantizedBvh boxset0, ref IndexedMatrix trans0,
                                         GImpactQuantizedBvh boxset1, ref IndexedMatrix trans1,
                                         PairSet collision_pairs)
        {
            if (boxset0.GetNodeCount() == 0 || boxset1.GetNodeCount() == 0)
            {
                return;
            }

            BT_BOX_BOX_TRANSFORM_CACHE trans_cache_1to0 = new BT_BOX_BOX_TRANSFORM_CACHE();

            trans_cache_1to0.CalcFromHomogenic(ref trans0, ref trans1);

#if TRI_COLLISION_PROFILING
            BulletGlobals.StartProfile("GIMPACT-TRIMESH");
#endif //TRI_COLLISION_PROFILING

            FindQuantizedCollisionPairsRecursive(boxset0, boxset1, collision_pairs, ref trans_cache_1to0, 0, 0, true);
#if TRI_COLLISION_PROFILING
            BulletGlobals.StopProfile();
#endif //TRI_COLLISION_PROFILING
        }
        public static void FindQuantizedCollisionPairsRecursive(
            GImpactQuantizedBvh boxset0, GImpactQuantizedBvh boxset1,
            PairSet collision_pairs,
            ref BT_BOX_BOX_TRANSFORM_CACHE trans_cache_1to0,
            int node0, int node1, bool complete_primitive_tests)
        {
            if (QuantizedNodeCollision(
                    boxset0, boxset1, trans_cache_1to0,
                    node0, node1, complete_primitive_tests) == false)
            {
                return;                                                  //avoid colliding internal nodes
            }
            if (boxset0.IsLeafNode(node0))
            {
                if (boxset1.IsLeafNode(node1))
                {
                    // collision result
                    collision_pairs.PushPair(boxset0.GetNodeData(node0), boxset1.GetNodeData(node1));
                    return;
                }
                else
                {
                    //collide left recursive

                    FindQuantizedCollisionPairsRecursive(
                        boxset0, boxset1,
                        collision_pairs, ref trans_cache_1to0,
                        node0, boxset1.GetLeftNode(node1), false);

                    //collide right recursive
                    FindQuantizedCollisionPairsRecursive(
                        boxset0, boxset1,
                        collision_pairs, ref trans_cache_1to0,
                        node0, boxset1.GetRightNode(node1), false);
                }
            }
            else
            {
                if (boxset1.IsLeafNode(node1))
                {
                    //collide left recursive
                    FindQuantizedCollisionPairsRecursive(
                        boxset0, boxset1,
                        collision_pairs, ref trans_cache_1to0,
                        boxset0.GetLeftNode(node0), node1, false);


                    //collide right recursive

                    FindQuantizedCollisionPairsRecursive(
                        boxset0, boxset1,
                        collision_pairs, ref trans_cache_1to0,
                        boxset0.GetRightNode(node0), node1, false);
                }
                else
                {
                    //collide left0 left1



                    FindQuantizedCollisionPairsRecursive(
                        boxset0, boxset1,
                        collision_pairs, ref trans_cache_1to0,
                        boxset0.GetLeftNode(node0), boxset1.GetLeftNode(node1), false);

                    //collide left0 right1

                    FindQuantizedCollisionPairsRecursive(
                        boxset0, boxset1,
                        collision_pairs, ref trans_cache_1to0,
                        boxset0.GetLeftNode(node0), boxset1.GetRightNode(node1), false);


                    //collide right0 left1

                    FindQuantizedCollisionPairsRecursive(
                        boxset0, boxset1,
                        collision_pairs, ref trans_cache_1to0,
                        boxset0.GetRightNode(node0), boxset1.GetLeftNode(node1), false);

                    //collide right0 right1

                    FindQuantizedCollisionPairsRecursive(
                        boxset0, boxset1,
                        collision_pairs, ref trans_cache_1to0,
                        boxset0.GetRightNode(node0), boxset1.GetRightNode(node1), false);
                } // else if node1 is not a leaf
            }     // else if node0 is not a leaf
        }