Ejemplo n.º 1
0
        public bool OverlappingTransConservative2(ref AABB box,
                                                  BT_BOX_BOX_TRANSFORM_CACHE trans1_to_0)
        {
            AABB tbox = box;

            tbox.ApplyTransformTransCache(ref trans1_to_0);
            return(HasCollision(ref tbox));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        //! Apply a transform to an AABB
        public void ApplyTransformTransCache(ref BT_BOX_BOX_TRANSFORM_CACHE trans)
        {
            IndexedVector3 center  = (m_max + m_min) * 0.5f;
            IndexedVector3 extends = m_max - center;

            // Compute new center
            center = trans.Transform(ref center);

            IndexedBasisMatrix absMatrix = trans.m_R1to0.Absolute();

            IndexedVector3 textends = new IndexedVector3(extends.Dot(trans.m_R1to0.GetRow(0).Absolute()),
                                                         extends.Dot(trans.m_R1to0.GetRow(1).Absolute()),
                                                         extends.Dot(trans.m_R1to0.GetRow(2).Absolute()));

            m_min = center - textends;
            m_max = center + textends;
        }
Ejemplo n.º 4
0
        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
        }
Ejemplo n.º 5
0
        public static void FindCollision(GImpactBvh boxset1, ref IndexedMatrix trans1,
                                         GImpactBvh boxset2, ref IndexedMatrix trans2,
                                         PairSet collision_pairs)
        {
            if (boxset1.GetNodeCount() == 0 || boxset2.GetNodeCount() == 0)
            {
                return;
            }

            BT_BOX_BOX_TRANSFORM_CACHE trans_cache_1to0 = new BT_BOX_BOX_TRANSFORM_CACHE();

            trans_cache_1to0.CalcFromHomogenic(ref trans1, ref trans2);

#if TRI_COLLISION_PROFILING
            bt_begin_gim02_tree_time();
#endif //TRI_COLLISION_PROFILING

            FindCollisionPairsRecursive(boxset1, boxset2, collision_pairs, trans_cache_1to0, 0, 0, true);
#if TRI_COLLISION_PROFILING
            bt_end_gim02_tree_time();
#endif //TRI_COLLISION_PROFILING
        }
Ejemplo n.º 6
0
        //! transcache is the transformation cache from box to this AABB
        public bool OverlappingTransCache(ref AABB box, ref BT_BOX_BOX_TRANSFORM_CACHE transcache, bool fulltest)
        {
            //Taken from OPCODE
            IndexedVector3 ea, eb; //extends
            IndexedVector3 ca, cb; //extends

            GetCenterExtend(out ca, out ea);
            box.GetCenterExtend(out cb, out eb);



            IndexedVector3 T = new IndexedVector3(0, 0, 0);
            float          t, t2;
            int            i;

            // Class I : A's basis vectors

            for (i = 0; i < 3; i++)
            {
                T[i] = transcache.m_R1to0[i].Dot(ref cb) + transcache.m_T1to0[i] - ca[i];
                t    = transcache.m_AR[i].Dot(ref eb) + ea[i];

                if (BoxCollision.BT_GREATER(T[i], t))
                {
                    return(false);
                }
            }
            // Class II : B's basis vectors
            for (i = 0; i < 3; i++)
            {
                t  = Mat3DotCol(ref transcache.m_R1to0, ref T, i);
                t2 = Mat3DotCol(ref transcache.m_AR, ref ea, i) + eb[i];
                if (BoxCollision.BT_GREATER(t, t2))
                {
                    return(false);
                }
            }
            // Class III : 9 cross products
            if (fulltest)
            {
                // check to see if these need to be restored back or are read-only
                float[,] m_R1to0 = MathUtil.BasisMatrixToFloatArray(ref transcache.m_R1to0);
                float[,] m_AR    = MathUtil.BasisMatrixToFloatArray(ref transcache.m_AR);


                int j, m, n, o, p, q, r;
                for (i = 0; i < 3; i++)
                {
                    m = (i + 1) % 3;
                    n = (i + 2) % 3;
                    o = i == 0 ? 1 : 0;
                    p = i == 2 ? 1 : 2;
                    for (j = 0; j < 3; j++)
                    {
                        q  = j == 2 ? 1 : 2;
                        r  = j == 0 ? 1 : 0;
                        t  = T[n] * m_R1to0[m, j] - T[m] * m_R1to0[n, j];
                        t2 = ea[o] * m_AR[p, j] + ea[p] * m_AR[o, j] +
                             eb[r] * m_AR[i, q] + eb[q] * m_AR[i, r];
                        if (BoxCollision.BT_GREATER(t, t2))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 7
0
        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
        }
Ejemplo n.º 8
0
        //! transcache is the transformation cache from box to this AABB
        public bool OverlappingTransCache(ref AABB box, ref BT_BOX_BOX_TRANSFORM_CACHE transcache, bool fulltest)
        {

            //Taken from OPCODE
            IndexedVector3 ea, eb;//extends
            IndexedVector3 ca, cb;//extends
            GetCenterExtend(out ca, out ea);
            box.GetCenterExtend(out cb, out eb);



            IndexedVector3 T = new IndexedVector3(0, 0, 0);
            float t, t2;
            int i;

            // Class I : A's basis vectors

            for (i = 0; i < 3; i++)
            {
                T[i] = transcache.m_R1to0[i].Dot(ref cb) + transcache.m_T1to0[i] - ca[i];
                t = transcache.m_AR[i].Dot(ref eb) + ea[i];

                if (BoxCollision.BT_GREATER(T[i], t))
                {
                    return false;
                }
            }
            // Class II : B's basis vectors
            for (i = 0; i < 3; i++)
            {
                t = Mat3DotCol(ref transcache.m_R1to0, ref T, i);
                t2 = Mat3DotCol(ref transcache.m_AR, ref ea, i) + eb[i];
                if (BoxCollision.BT_GREATER(t, t2))
                {
                    return false;
                }
            }
            // Class III : 9 cross products
            if (fulltest)
            {
                // check to see if these need to be restored back or are read-only
                float[,] m_R1to0 = MathUtil.BasisMatrixToFloatArray(ref transcache.m_R1to0);
                float[,] m_AR = MathUtil.BasisMatrixToFloatArray(ref transcache.m_AR);


                int j, m, n, o, p, q, r;
                for (i = 0; i < 3; i++)
                {
                    m = (i + 1) % 3;
                    n = (i + 2) % 3;
                    o = i == 0 ? 1 : 0;
                    p = i == 2 ? 1 : 2;
                    for (j = 0; j < 3; j++)
                    {
                        q = j == 2 ? 1 : 2;
                        r = j == 0 ? 1 : 0;
                        t = T[n] * m_R1to0[m, j] - T[m] * m_R1to0[n, j];
                        t2 = ea[o] * m_AR[p, j] + ea[p] * m_AR[o, j] +
                            eb[r] * m_AR[i, q] + eb[q] * m_AR[i, r];
                        if (BoxCollision.BT_GREATER(t, t2)) return false;
                    }
                }
            }
            return true;
        }
Ejemplo n.º 9
0
 public bool OverlappingTransConservative2(ref AABB box,
     BT_BOX_BOX_TRANSFORM_CACHE trans1_to_0)
 {
     AABB tbox = box;
     tbox.ApplyTransformTransCache(ref trans1_to_0);
     return HasCollision(ref tbox);
 }
Ejemplo n.º 10
0
        //! Apply a transform to an AABB
        public void ApplyTransformTransCache(ref BT_BOX_BOX_TRANSFORM_CACHE trans)
        {
            IndexedVector3 center = (m_max + m_min) * 0.5f;
            IndexedVector3 extends = m_max - center;
            // Compute new center
            center = trans.Transform(ref center);

            IndexedBasisMatrix absMatrix = trans.m_R1to0.Absolute();

		    IndexedVector3 textends = new IndexedVector3(extends.Dot(trans.m_R1to0.GetRow(0).Absolute()),
 				 extends.Dot(trans.m_R1to0.GetRow(1).Absolute()),
				 extends.Dot(trans.m_R1to0.GetRow(2).Absolute()));

            m_min = center - textends;
            m_max = center + textends;
        }