Exemplo n.º 1
0
        private void UpdateDeterminant(int xmIdx)
        {
            int index1 = 1 << xmIdx;

            this.det[index1][xmIdx] = 1f;
            int num1 = GjkD.BitsToIndices[this.simplexBits];
            int num2 = num1;
            int num3 = 0;

            while (num2 != 0)
            {
                int index2 = (num2 & 7) - 1;
                int num4   = 1 << index2;
                int index3 = num4 | index1;
                this.det[index3][index2] = GjkD.Dot(ref this.edges[xmIdx][index2], ref this.y[xmIdx]);
                this.det[index3][xmIdx]  = GjkD.Dot(ref this.edges[index2][xmIdx], ref this.y[index2]);
                int num5 = num1;
                for (int index4 = 0; index4 < num3; ++index4)
                {
                    int index5 = (num5 & 7) - 1;
                    int num6   = 1 << index5;
                    int index6 = index3 | num6;
                    int index7 = (double)this.edgeLengthSq[index2][index5] < (double)this.edgeLengthSq[xmIdx][index5] ? index2 : xmIdx;
                    this.det[index6][index5] = (double)((double)this.det[index3][index2] * (double)GjkD.Dot(ref this.edges[index7][index5], ref this.y[index2]) + (double)this.det[index3][xmIdx] * (double)GjkD.Dot(ref this.edges[index7][index5], ref this.y[xmIdx]));
                    int index8 = (double)this.edgeLengthSq[index5][index2] < (double)this.edgeLengthSq[xmIdx][index2] ? index5 : xmIdx;
                    this.det[index6][index2] = (double)((double)this.det[num6 | index1][index5] * (double)GjkD.Dot(ref this.edges[index8][index2], ref this.y[index5]) + (double)this.det[num6 | index1][xmIdx] * (double)GjkD.Dot(ref this.edges[index8][index2], ref this.y[xmIdx]));
                    int index9 = (double)this.edgeLengthSq[index2][xmIdx] < (double)this.edgeLengthSq[index5][xmIdx] ? index2 : index5;
                    this.det[index6][xmIdx] = (double)((double)this.det[num4 | num6][index5] * (double)GjkD.Dot(ref this.edges[index9][xmIdx], ref this.y[index5]) + (double)this.det[num4 | num6][index2] * (double)GjkD.Dot(ref this.edges[index9][xmIdx], ref this.y[index2]));
                    num5 >>= 3;
                }
                num2 >>= 3;
                ++num3;
            }
            if ((this.simplexBits | index1) != 15)
            {
                return;
            }
            int index10 = (double)this.edgeLengthSq[1][0] < (double)this.edgeLengthSq[2][0] ? ((double)this.edgeLengthSq[1][0] < (double)this.edgeLengthSq[3][0] ? 1 : 3) : ((double)this.edgeLengthSq[2][0] < (double)this.edgeLengthSq[3][0] ? 2 : 3);

            this.det[15][0] = (double)((double)this.det[14][1] * (double)GjkD.Dot(ref this.edges[index10][0], ref this.y[1]) + (double)this.det[14][2] * (double)GjkD.Dot(ref this.edges[index10][0], ref this.y[2]) + (double)this.det[14][3] * (double)GjkD.Dot(ref this.edges[index10][0], ref this.y[3]));
            int index11 = (double)this.edgeLengthSq[0][1] < (double)this.edgeLengthSq[2][1] ? ((double)this.edgeLengthSq[0][1] < (double)this.edgeLengthSq[3][1] ? 0 : 3) : ((double)this.edgeLengthSq[2][1] < (double)this.edgeLengthSq[3][1] ? 2 : 3);

            this.det[15][1] = (double)((double)this.det[13][0] * (double)GjkD.Dot(ref this.edges[index11][1], ref this.y[0]) + (double)this.det[13][2] * (double)GjkD.Dot(ref this.edges[index11][1], ref this.y[2]) + (double)this.det[13][3] * (double)GjkD.Dot(ref this.edges[index11][1], ref this.y[3]));
            int index12 = (double)this.edgeLengthSq[0][2] < (double)this.edgeLengthSq[1][2] ? ((double)this.edgeLengthSq[0][2] < (double)this.edgeLengthSq[3][2] ? 0 : 3) : ((double)this.edgeLengthSq[1][2] < (double)this.edgeLengthSq[3][2] ? 1 : 3);

            this.det[15][2] = (double)((double)this.det[11][0] * (double)GjkD.Dot(ref this.edges[index12][2], ref this.y[0]) + (double)this.det[11][1] * (double)GjkD.Dot(ref this.edges[index12][2], ref this.y[1]) + (double)this.det[11][3] * (double)GjkD.Dot(ref this.edges[index12][2], ref this.y[3]));
            int index13 = (double)this.edgeLengthSq[0][3] < (double)this.edgeLengthSq[1][3] ? ((double)this.edgeLengthSq[0][3] < (double)this.edgeLengthSq[2][3] ? 0 : 2) : ((double)this.edgeLengthSq[1][3] < (double)this.edgeLengthSq[2][3] ? 1 : 2);

            this.det[15][3] = (double)((double)this.det[7][0] * (double)GjkD.Dot(ref this.edges[index13][3], ref this.y[0]) + (double)this.det[7][1] * (double)GjkD.Dot(ref this.edges[index13][3], ref this.y[1]) + (double)this.det[7][2] * (double)GjkD.Dot(ref this.edges[index13][3], ref this.y[2]));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks whether the current BoundingFrustumD intersects the specified BoundingFrustumD.
        /// </summary>
        /// <param name="frustum">The BoundingFrustumD to check for intersection.</param>
        public bool Intersects(BoundingFrustumD frustum)
        {
            if (frustum == (BoundingFrustumD)null)
            {
                throw new ArgumentNullException("frustum");
            }
            if (this.gjk == null)
            {
                this.gjk = new GjkD();
            }
            this.gjk.Reset();
            Vector3D result1;

            Vector3D.Subtract(ref this.cornerArray[0], ref frustum.cornerArray[0], out result1);
            if ((double)result1.LengthSquared() < 9.99999974737875E-06)
            {
                Vector3D.Subtract(ref this.cornerArray[0], ref frustum.cornerArray[1], out result1);
            }
            double num1 = double.MaxValue;
            double num2;

            do
            {
                Vector3D v;
                v.X = -result1.X;
                v.Y = -result1.Y;
                v.Z = -result1.Z;
                Vector3D result2;
                this.SupportMapping(ref v, out result2);
                Vector3D result3;
                frustum.SupportMapping(ref result1, out result3);
                Vector3D result4;
                Vector3D.Subtract(ref result2, ref result3, out result4);
                if ((double)result1.X * (double)result4.X + (double)result1.Y * (double)result4.Y + (double)result1.Z * (double)result4.Z > 0.0)
                {
                    return(false);
                }
                this.gjk.AddSupportPoint(ref result4);
                result1 = this.gjk.ClosestPoint;
                double num3 = num1;
                num1 = result1.LengthSquared();
                num2 = 4E-05f * this.gjk.MaxLengthSquared;
                if ((double)num3 - (double)num1 <= 9.99999974737875E-06 * (double)num3)
                {
                    return(false);
                }
            }while (!this.gjk.FullSimplex && (double)num1 >= (double)num2);
            return(true);
        }
Exemplo n.º 3
0
        public bool Intersects(BoundingFrustumD frustum)
        {
            Vector3D closestPoint;
            double   num2;

            if (frustum == null)
            {
                throw new ArgumentNullException("frustum");
            }
            if (this.gjk == null)
            {
                this.gjk = new GjkD();
            }
            this.gjk.Reset();
            Vector3D.Subtract(ref this.cornerArray[0], ref frustum.cornerArray[0], out closestPoint);
            if (closestPoint.LengthSquared() < 9.99999974737875E-06)
            {
                Vector3D.Subtract(ref this.cornerArray[0], ref frustum.cornerArray[1], out closestPoint);
            }
            double maxValue = double.MaxValue;

            do
            {
                Vector3D vectord2;
                Vector3D vectord3;
                Vector3D vectord4;
                Vector3D vectord5;
                vectord2.X = -closestPoint.X;
                vectord2.Y = -closestPoint.Y;
                vectord2.Z = -closestPoint.Z;
                this.SupportMapping(ref vectord2, out vectord3);
                frustum.SupportMapping(ref closestPoint, out vectord4);
                Vector3D.Subtract(ref vectord3, ref vectord4, out vectord5);
                if ((((closestPoint.X * vectord5.X) + (closestPoint.Y * vectord5.Y)) + (closestPoint.Z * vectord5.Z)) > 0.0)
                {
                    return(false);
                }
                this.gjk.AddSupportPoint(ref vectord5);
                closestPoint = this.gjk.ClosestPoint;
                double num3 = maxValue;
                maxValue = closestPoint.LengthSquared();
                num2     = 3.9999998989515007E-05 * this.gjk.MaxLengthSquared;
                if ((num3 - maxValue) <= (9.99999974737875E-06 * num3))
                {
                    return(false);
                }
            }while (!this.gjk.FullSimplex && (maxValue >= num2));
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks whether the current BoundingFrustumD intersects a BoundingSphere.
        /// </summary>
        /// <param name="sphere">The BoundingSphere to check for intersection with.</param><param name="result">[OutAttribute] true if the BoundingFrustumD and BoundingSphere intersect; false otherwise.</param>
        public void Intersects(ref BoundingSphereD sphere, out bool result)
        {
            if (this.gjk == null)
            {
                this.gjk = new GjkD();
            }
            this.gjk.Reset();
            Vector3D result1;

            Vector3D.Subtract(ref this.cornerArray[0], ref sphere.Center, out result1);
            if ((double)result1.LengthSquared() < 9.99999974737875E-06)
            {
                result1 = Vector3D.UnitX;
            }
            double num1 = double.MaxValue;

            result = false;
            double num2;

            do
            {
                Vector3D v;
                v.X = -result1.X;
                v.Y = -result1.Y;
                v.Z = -result1.Z;
                Vector3D result2;
                this.SupportMapping(ref v, out result2);
                Vector3D result3;
                sphere.SupportMapping(ref result1, out result3);
                Vector3D result4;
                Vector3D.Subtract(ref result2, ref result3, out result4);
                if ((double)result1.X * (double)result4.X + (double)result1.Y * (double)result4.Y + (double)result1.Z * (double)result4.Z > 0.0)
                {
                    return;
                }
                this.gjk.AddSupportPoint(ref result4);
                result1 = this.gjk.ClosestPoint;
                double num3 = num1;
                num1 = result1.LengthSquared();
                if ((double)num3 - (double)num1 <= 9.99999974737875E-06 * (double)num3)
                {
                    return;
                }
                num2 = 4E-05f * this.gjk.MaxLengthSquared;
            }while (!this.gjk.FullSimplex && (double)num1 >= (double)num2);
            result = true;
        }
Exemplo n.º 5
0
        public void Intersects(ref BoundingSphereD sphere, out bool result)
        {
            Vector3D unitX;
            Vector3D vectord2;
            Vector3D vectord3;
            Vector3D vectord4;
            Vector3D vectord5;

            if (this.gjk == null)
            {
                this.gjk = new GjkD();
            }
            this.gjk.Reset();
            Vector3D.Subtract(ref this.cornerArray[0], ref sphere.Center, out unitX);
            if (unitX.LengthSquared() < 9.99999974737875E-06)
            {
                unitX = Vector3D.UnitX;
            }
            double maxValue = double.MaxValue;

            result = false;
Label_005D:
            vectord2.X = -unitX.X;
            vectord2.Y = -unitX.Y;
            vectord2.Z = -unitX.Z;
            this.SupportMapping(ref vectord2, out vectord3);
            sphere.SupportMapping(ref unitX, out vectord4);
            Vector3D.Subtract(ref vectord3, ref vectord4, out vectord5);
            if ((((unitX.X * vectord5.X) + (unitX.Y * vectord5.Y)) + (unitX.Z * vectord5.Z)) <= 0.0)
            {
                this.gjk.AddSupportPoint(ref vectord5);
                unitX = this.gjk.ClosestPoint;
                double num3 = maxValue;
                maxValue = unitX.LengthSquared();
                if ((num3 - maxValue) > (9.99999974737875E-06 * num3))
                {
                    double num2 = 3.9999998989515007E-05 * this.gjk.MaxLengthSquared;
                    if (!this.gjk.FullSimplex && (maxValue >= num2))
                    {
                        goto Label_005D;
                    }
                    result = true;
                }
            }
        }
Exemplo n.º 6
0
        public void Intersects(ref BoundingBoxD box, out bool result)
        {
            Vector3D closestPoint;
            Vector3D vectord2;
            Vector3D vectord3;
            Vector3D vectord4;
            Vector3D vectord5;

            if (this.gjk == null)
            {
                this.gjk = new GjkD();
            }
            this.gjk.Reset();
            Vector3D.Subtract(ref this.cornerArray[0], ref box.Min, out closestPoint);
            if (closestPoint.LengthSquared() < 9.99999974737875E-06)
            {
                Vector3D.Subtract(ref this.cornerArray[0], ref box.Max, out closestPoint);
            }
            double maxValue = double.MaxValue;

            result = false;
Label_0070:
            vectord2.X = -closestPoint.X;
            vectord2.Y = -closestPoint.Y;
            vectord2.Z = -closestPoint.Z;
            this.SupportMapping(ref vectord2, out vectord3);
            box.SupportMapping(ref closestPoint, out vectord4);
            Vector3D.Subtract(ref vectord3, ref vectord4, out vectord5);
            if ((((closestPoint.X * vectord5.X) + (closestPoint.Y * vectord5.Y)) + (closestPoint.Z * vectord5.Z)) <= 0.0)
            {
                this.gjk.AddSupportPoint(ref vectord5);
                closestPoint = this.gjk.ClosestPoint;
                double num3 = maxValue;
                maxValue = closestPoint.LengthSquared();
                if ((num3 - maxValue) > (9.99999974737875E-06 * num3))
                {
                    double num2 = 3.9999998989515007E-05 * this.gjk.MaxLengthSquared;
                    if (!this.gjk.FullSimplex && (maxValue >= num2))
                    {
                        goto Label_0070;
                    }
                    result = true;
                }
            }
        }