Example #1
0
        private static bool CompoundDummiesIntersect(ref Matrix thisRotation, ref Matrix otherRotation, List <MyModelDummy> thisDummies, List <MyModelDummy> otherDummies)
        {
            using (List <MyModelDummy> .Enumerator enumerator = thisDummies.GetEnumerator())
            {
                bool flag;
                while (true)
                {
                    if (enumerator.MoveNext())
                    {
                        Matrix       matrix2;
                        MyModelDummy current = enumerator.Current;
                        Vector3      forward = current.Matrix.Forward;
                        Vector3      max     = new Vector3(current.Matrix.Right.Length(), current.Matrix.Up.Length(), forward.Length()) * 0.5f;
                        BoundingBox  box     = new BoundingBox(-max, max);
                        Matrix       matrix  = Matrix.Normalize(current.Matrix);
                        Matrix.Multiply(ref matrix, ref thisRotation, out matrix2);
                        Matrix.Invert(ref matrix2, out matrix);
                        List <MyModelDummy> .Enumerator enumerator2 = otherDummies.GetEnumerator();
                        try
                        {
                            while (true)
                            {
                                Matrix matrix4;
                                if (!enumerator2.MoveNext())
                                {
                                    break;
                                }
                                MyModelDummy dummy2 = enumerator2.Current;
                                forward = dummy2.Matrix.Forward;
                                Vector3 vector3 = new Vector3(dummy2.Matrix.Right.Length(), dummy2.Matrix.Up.Length(), forward.Length()) * 0.5f;
                                Matrix  matrix3 = Matrix.Normalize(dummy2.Matrix);
                                Matrix.Multiply(ref matrix3, ref otherRotation, out matrix4);
                                Matrix.Multiply(ref matrix4, ref matrix, out matrix3);
                                MyOrientedBoundingBox box2 = MyOrientedBoundingBox.Create(new BoundingBox(-vector3, vector3), matrix3);
                                if (box2.Intersects(ref box))
                                {
                                    return(true);
                                }
                            }
                            continue;
                        }
                        finally
                        {
                            enumerator2.Dispose();
                            continue;
                        }
                    }
                    else
                    {
                        goto TR_0000;
                    }
                    break;
                }
                return(flag);
            }
TR_0000:
            return(false);
        }
Example #2
0
        private static bool CompoundDummiesIntersect(ref Matrix thisRotation, ref Matrix otherRotation, List <MyModelDummy> thisDummies, List <MyModelDummy> otherDummies)
        {
            foreach (var dummy in thisDummies)
            {
                //TODO: thisBoxHalfExtends should be dummy.Matrix.Scale * 0.5 but Scale in Matrix is bad.
                Vector3     thisBoxHalfExtends = new Vector3(dummy.Matrix.Right.Length(), dummy.Matrix.Up.Length(), dummy.Matrix.Forward.Length()) * 0.5f;
                BoundingBox thisAABB           = new BoundingBox(-thisBoxHalfExtends, thisBoxHalfExtends);

                // Normalize this dummy, use inverse matrix as temporary.
                Matrix thisDummyMatrixInv = Matrix.Normalize(dummy.Matrix);

                // Rotate this dummy
                Matrix thisDummyMatrix;
                Matrix.Multiply(ref thisDummyMatrixInv, ref thisRotation, out thisDummyMatrix);
                // Create trasform to this dummy (inverse).
                Matrix.Invert(ref thisDummyMatrix, out thisDummyMatrixInv);

                //DebugDrawAABB(thisAABB, thisDummyMatrix);

                foreach (var otherDummy in otherDummies)
                {
                    //TODO: otherBoxHalfExtends should be otherDummy.Matrix.Scale * 0.5 but Scale in Matrix is bad.
                    Vector3     otherBoxHalfExtends = new Vector3(otherDummy.Matrix.Right.Length(), otherDummy.Matrix.Up.Length(), otherDummy.Matrix.Forward.Length()) * 0.5f;
                    BoundingBox otherAABB           = new BoundingBox(-otherBoxHalfExtends, otherBoxHalfExtends);

                    // Store normalized dummy matrix as temporary
                    Matrix otherDummyMatrixInThis = Matrix.Normalize(otherDummy.Matrix);

                    // Rotate other dummy
                    Matrix otherDummyMatrix;
                    Matrix.Multiply(ref otherDummyMatrixInThis, ref otherRotation, out otherDummyMatrix);
                    // Transform other dummy to this dummy
                    Matrix.Multiply(ref otherDummyMatrix, ref thisDummyMatrixInv, out otherDummyMatrixInThis);

                    MyOrientedBoundingBox obb = MyOrientedBoundingBox.Create(otherAABB, otherDummyMatrixInThis);
                    //DebugDrawOBB(obb, thisDummyMatrix);
                    if (obb.Intersects(ref thisAABB))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }