Ejemplo n.º 1
0
        // Token: 0x06000464 RID: 1124 RVA: 0x00013F08 File Offset: 0x00012108
        public bool Test()
        {
            Vector3[] array = new Vector3[]
            {
                this.triangle0.V1 - this.triangle0.V0,
                this.triangle0.V2 - this.triangle0.V1,
                this.triangle0.V0 - this.triangle0.V2
            };
            UnitVector3 axis;

            if (!array[0].TryGetUnitCross(array[1], out axis))
            {
                int      num     = IntersectionUtility3.MaxIndex(array[0].SquaredLength, array[1].SquaredLength, array[2].SquaredLength);
                Segment3 segment = new Segment3(this.triangle0[num], this.triangle0[(num + 1) % 3]);
                IntersectionSegment3Triangle3 intersectionSegment3Triangle = new IntersectionSegment3Triangle3(segment, this.triangle1);
                return(intersectionSegment3Triangle.Test());
            }
            double num2 = axis.Dot(this.triangle0.V0);
            double num3;
            double num4;

            IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle1, axis, out num3, out num4);
            if (num2 < num3 || num2 > num4)
            {
                return(false);
            }
            Vector3[] array2 = new Vector3[]
            {
                this.triangle1.V1 - this.triangle1.V0,
                this.triangle1.V2 - this.triangle1.V1,
                this.triangle1.V0 - this.triangle1.V2
            };
            UnitVector3 unitVector;

            if (!array2[0].TryGetUnitCross(array2[1], out unitVector))
            {
                int      num5     = IntersectionUtility3.MaxIndex(array2[0].SquaredLength, array2[1].SquaredLength, array2[2].SquaredLength);
                Segment3 segment2 = new Segment3(this.triangle1[num5], this.triangle1[(num5 + 1) % 3]);
                IntersectionSegment3Triangle3 intersectionSegment3Triangle2 = new IntersectionSegment3Triangle3(segment2, this.triangle0);
                return(intersectionSegment3Triangle2.Test());
            }
            Vector3 vector = new Vector3();

            if (axis.Cross(unitVector).Dot(vector) >= 1E-08)
            {
                double num6 = unitVector.Dot(this.triangle1.V0);
                double num7;
                double num8;
                IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle0, unitVector, out num7, out num8);
                if (num6 < num7 || num6 > num8)
                {
                    return(false);
                }
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        UnitVector3 axis2;
                        if (array[j].TryGetUnitCross(array2[i], out axis2))
                        {
                            IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle0, axis2, out num7, out num8);
                            IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle1, axis2, out num3, out num4);
                            if (num8 < num3 || num4 < num7)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            else
            {
                for (int j = 0; j < 3; j++)
                {
                    UnitVector3 axis3;
                    if (axis.TryGetUnitCross(array[j], out axis3))
                    {
                        double num7;
                        double num8;
                        IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle0, axis3, out num7, out num8);
                        IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle1, axis3, out num3, out num4);
                        if (num8 < num3 || num4 < num7)
                        {
                            return(false);
                        }
                    }
                }
                for (int i = 0; i < 3; i++)
                {
                    UnitVector3 axis4;
                    if (unitVector.TryGetUnitCross(array2[i], out axis4))
                    {
                        double num7;
                        double num8;
                        IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle0, axis4, out num7, out num8);
                        IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle1, axis4, out num3, out num4);
                        if (num8 < num3 || num4 < num7)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        // Token: 0x06000252 RID: 594 RVA: 0x00009AC4 File Offset: 0x00007CC4
        private void CalcSquared(ref Vector3 vector, ref Triangle3 triangle)
        {
            Vector3 vector2        = triangle.V0 - vector;
            Vector3 vector3        = triangle.V1 - triangle.V0;
            Vector3 vector4        = triangle.V2 - triangle.V0;
            double  squaredLength  = vector3.SquaredLength;
            double  num            = vector3.Dot(vector4);
            double  squaredLength2 = vector4.SquaredLength;
            double  num2           = vector2.Dot(vector3);
            double  num3           = vector2.Dot(vector4);
            double  squaredLength3 = vector2.SquaredLength;
            double  num4           = squaredLength * squaredLength2;
            double  num5           = num;
            double  num6           = Math.Abs(num4 - num5 * num5);
            double  num7           = num * num3 - squaredLength2 * num2;
            double  num8           = num * num2 - squaredLength * num3;
            double  num9;

            if (num7 + num8 <= num6)
            {
                if (num7 < 0.0)
                {
                    if (num8 < 0.0)
                    {
                        if (num2 < 0.0)
                        {
                            num8 = 0.0;
                            if (-num2 >= squaredLength)
                            {
                                num7 = 1.0;
                                num9 = squaredLength + 2.0 * num2 + squaredLength3;
                            }
                            else
                            {
                                num7 = -num2 / squaredLength;
                                num9 = num2 * num7 + squaredLength3;
                            }
                        }
                        else
                        {
                            num7 = 0.0;
                            if (num3 >= 0.0)
                            {
                                num8 = 0.0;
                                num9 = squaredLength3;
                            }
                            else if (-num3 >= squaredLength2)
                            {
                                num8 = 1.0;
                                num9 = squaredLength2 + 2.0 * num3 + squaredLength3;
                            }
                            else
                            {
                                num8 = -num3 / squaredLength2;
                                num9 = num3 * num8 + squaredLength3;
                            }
                        }
                    }
                    else
                    {
                        num7 = 0.0;
                        if (num3 >= 0.0)
                        {
                            num8 = 0.0;
                            num9 = squaredLength3;
                        }
                        else if (-num3 >= squaredLength2)
                        {
                            num8 = 1.0;
                            num9 = squaredLength2 + 2.0 * num3 + squaredLength3;
                        }
                        else
                        {
                            num8 = -num3 / squaredLength2;
                            num9 = num3 * num8 + squaredLength3;
                        }
                    }
                }
                else if (num8 < 0.0)
                {
                    num8 = 0.0;
                    if (num2 >= 0.0)
                    {
                        num7 = 0.0;
                        num9 = squaredLength3;
                    }
                    else if (-num2 >= squaredLength)
                    {
                        num7 = 1.0;
                        num9 = squaredLength + 2.0 * num2 + squaredLength3;
                    }
                    else
                    {
                        num7 = -num2 / squaredLength;
                        num9 = num2 * num7 + squaredLength3;
                    }
                }
                else
                {
                    if (num6 == 0.0)
                    {
                        Vector3[] array = new Vector3[]
                        {
                            triangle.V1 - triangle.V0,
                            triangle.V2 - triangle.V1,
                            triangle.V0 - triangle.V2
                        };
                        int      num10   = IntersectionUtility3.MaxIndex(array[0].SquaredLength, array[1].SquaredLength, array[2].SquaredLength);
                        Segment3 segment = new Segment3(triangle[num10], triangle[(num10 + 1) % 3]);
                        DistanceVector3Segment3 distanceVector3Segment = new DistanceVector3Segment3(vector, segment);
                        this.ClosestPointOnVector   = vector;
                        this.ClosestPointOnTriangle = distanceVector3Segment.ClosestPointOnSegment;
                        this.SquaredDistance        = distanceVector3Segment.SquaredDistance;
                        return;
                    }
                    double num11 = 1.0 / num6;
                    num7 *= num11;
                    num8 *= num11;
                    num9  = num7 * (squaredLength * num7 + num * num8 + 2.0 * num2) + num8 * (num * num7 + squaredLength2 * num8 + 2.0 * num3) + squaredLength3;
                }
            }
            else if (num7 < 0.0)
            {
                double num12 = num + num2;
                double num13 = squaredLength2 + num3;
                if (num13 > num12)
                {
                    double num14 = num13 - num12;
                    double num15 = squaredLength - 2.0 * num + squaredLength2;
                    if (num14 >= num15)
                    {
                        num7 = 1.0;
                        num8 = 0.0;
                        num9 = squaredLength + 2.0 * num2 + squaredLength3;
                    }
                    else
                    {
                        num7 = num14 / num15;
                        num8 = 1.0 - num7;
                        num9 = num7 * (squaredLength * num7 + num * num8 + 2.0 * num2) + num8 * (num * num7 + squaredLength2 * num8 + 2.0 * num3) + squaredLength3;
                    }
                }
                else
                {
                    num7 = 0.0;
                    if (num13 <= 0.0)
                    {
                        num8 = 1.0;
                        num9 = squaredLength2 + 2.0 * num3 + squaredLength3;
                    }
                    else if (num3 >= 0.0)
                    {
                        num8 = 0.0;
                        num9 = squaredLength3;
                    }
                    else
                    {
                        num8 = -num3 / squaredLength2;
                        num9 = num3 * num8 + squaredLength3;
                    }
                }
            }
            else if (num8 < 0.0)
            {
                double num16 = num + num3;
                double num17 = squaredLength + num2;
                if (num17 > num16)
                {
                    double num14 = num17 - num16;
                    double num15 = squaredLength - 2.0 * num + squaredLength2;
                    if (num14 >= num15)
                    {
                        num8 = 1.0;
                        num7 = 0.0;
                        num9 = squaredLength2 + 2.0 * num3 + squaredLength3;
                    }
                    else
                    {
                        num8 = num14 / num15;
                        num7 = 1.0 - num8;
                        num9 = num7 * (squaredLength * num7 + num * num8 + 2.0 * num2) + num8 * (num * num7 + squaredLength2 * num8 + 2.0 * num3) + squaredLength3;
                    }
                }
                else
                {
                    num8 = 0.0;
                    if (num17 <= 0.0)
                    {
                        num7 = 1.0;
                        num9 = squaredLength + 2.0 * num2 + squaredLength3;
                    }
                    else if (num2 >= 0.0)
                    {
                        num7 = 0.0;
                        num9 = squaredLength3;
                    }
                    else
                    {
                        num7 = -num2 / squaredLength;
                        num9 = num2 * num7 + squaredLength3;
                    }
                }
            }
            else
            {
                double num14 = squaredLength2 + num3 - num - num2;
                if (num14 <= 0.0)
                {
                    num7 = 0.0;
                    num8 = 1.0;
                    num9 = squaredLength2 + 2.0 * num3 + squaredLength3;
                }
                else
                {
                    double num15 = squaredLength - 2.0 * num + squaredLength2;
                    if (num14 >= num15)
                    {
                        num7 = 1.0;
                        num8 = 0.0;
                        num9 = squaredLength + 2.0 * num2 + squaredLength3;
                    }
                    else
                    {
                        num7 = num14 / num15;
                        num8 = 1.0 - num7;
                        num9 = num7 * (squaredLength * num7 + num * num8 + 2.0 * num2) + num8 * (num * num7 + squaredLength2 * num8 + 2.0 * num3) + squaredLength3;
                    }
                }
            }
            if (num9 < 0.0)
            {
                num9 = 0.0;
            }
            this.ClosestPointOnVector   = vector;
            this.ClosestPointOnTriangle = triangle.V0 + num7 * vector3 + num8 * vector4;
            this.TriangleBary1          = num7;
            this.TriangleBary2          = num8;
            this.TriangleBary0          = 1.0 - num7 - num8;
            this.SquaredDistance        = num9;
        }
Ejemplo n.º 3
0
        // Token: 0x06000465 RID: 1125 RVA: 0x000142D4 File Offset: 0x000124D4
        public bool Find()
        {
            Vector3[] array = new Vector3[]
            {
                this.triangle0.V1 - this.triangle0.V0,
                this.triangle0.V2 - this.triangle0.V1,
                this.triangle0.V0 - this.triangle0.V2
            };
            UnitVector3 unitVector;

            if (!array[0].TryGetUnitCross(array[1], out unitVector))
            {
                int      num     = IntersectionUtility3.MaxIndex(array[0].SquaredLength, array[1].SquaredLength, array[2].SquaredLength);
                Segment3 segment = new Segment3(this.triangle0[num], this.triangle0[(num + 1) % 3]);
                IntersectionSegment3Triangle3 intersectionSegment3Triangle = new IntersectionSegment3Triangle3(segment, this.triangle1);
                bool result = intersectionSegment3Triangle.Find();
                if (intersectionSegment3Triangle.IntersectionType == Intersection.Type.IT_POINT)
                {
                    this.Points[0]        = segment.Origin + intersectionSegment3Triangle.SegmentParameter * segment.Direction;
                    this.Quantity         = 1;
                    this.IntersectionType = Intersection.Type.IT_POINT;
                }
                return(result);
            }
            Plane3 plane = new Plane3(this.triangle0.V0, this.triangle0.V1, this.triangle0.V2);

            int[]    array2 = new int[3];
            double[] array3 = new double[3];
            int      num2;
            int      num3;
            int      num4;

            IntersectionTriangle3Triangle3.TrianglePlaneRelations(this.triangle1, plane, ref array3, ref array2, out num2, out num3, out num4);
            if (num2 == 3 || num3 == 3)
            {
                return(false);
            }
            if (num4 == 3)
            {
                return(this.ReportCoplanarIntersections && this.GetCoplanarIntersection(plane, this.triangle0, this.triangle1));
            }
            if (num2 == 0 || num3 == 0)
            {
                if (num4 == 2)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (array2[i] != 0)
                        {
                            int num5 = (i + 2) % 3;
                            int num6 = (i + 1) % 3;
                            return(this.IntersectsSegment(plane, this.triangle0, this.triangle1[num5], this.triangle1[num6]));
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (array2[i] == 0)
                        {
                            return(this.ContainsPoint(this.triangle0, plane, this.triangle1[i]));
                        }
                    }
                }
            }
            if (num4 == 0)
            {
                int num7 = (num2 == 1) ? 1 : -1;
                for (int i = 0; i < 3; i++)
                {
                    if (array2[i] == num7)
                    {
                        int     num5   = (i + 2) % 3;
                        int     num6   = (i + 1) % 3;
                        double  scalar = array3[i] / (array3[i] - array3[num5]);
                        Vector3 vector = this.triangle1[i] + scalar * (this.triangle1[num5] - this.triangle1[i]);
                        scalar = array3[i] / (array3[i] - array3[num6]);
                        Vector3 end = this.triangle1[i] + scalar * (this.triangle1[num6] - this.triangle1[i]);
                        return(this.IntersectsSegment(plane, this.triangle0, vector, end));
                    }
                }
            }
            for (int i = 0; i < 3; i++)
            {
                if (array2[i] == 0)
                {
                    int     num5   = (i + 2) % 3;
                    int     num6   = (i + 1) % 3;
                    double  scalar = array3[num5] / (array3[num5] - array3[num6]);
                    Vector3 vector = this.triangle1[num5] + scalar * (this.triangle1[num6] - this.triangle1[num5]);
                    return(this.IntersectsSegment(plane, this.triangle0, this.triangle1[i], vector));
                }
            }
            MathBase.Assert(false, "Triangle3Triangle3.Find(): should not be here");
            return(false);
        }