Ejemplo n.º 1
0
        public override void SupportMapping(ref TSVector direction, out TSVector result)
        {
            TSVector tSVector;

            TSVector.Normalize(ref direction, out tSVector);
            TSVector.Multiply(ref tSVector, this.sphericalExpansion, out tSVector);
            int  num  = 0;
            FP   y    = TSVector.Dot(ref this.points[0], ref direction);
            FP   fP   = TSVector.Dot(ref this.points[1], ref direction);
            bool flag = fP > y;

            if (flag)
            {
                y   = fP;
                num = 1;
            }
            fP = TSVector.Dot(ref this.points[2], ref direction);
            bool flag2 = fP > y;

            if (flag2)
            {
                num = 2;
            }
            TSVector.Add(ref this.points[num], ref tSVector, out result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Normalizes the given vector.
        /// </summary>
        /// <param name="value">The vector which should be normalized.</param>
        /// <returns>A normalized vector.</returns>
        #region public static JVector Normalize(JVector value)
        public static TSVector Normalize(TSVector value)
        {
            TSVector result;

            TSVector.Normalize(ref value, out result);
            return(result);
        }
Ejemplo n.º 3
0
        public override void SupportMapping(ref TSVector direction, out TSVector result)
        {
            FP   fP   = FP.Sqrt(direction.x * direction.x + direction.z * direction.z);
            bool flag = FP.Abs(direction.y) > FP.Zero;

            if (flag)
            {
                TSVector tSVector;
                TSVector.Normalize(ref direction, out tSVector);
                TSVector.Multiply(ref tSVector, this.radius, out result);
                result.y += FP.Sign(direction.y) * FP.Half * this.length;
            }
            else
            {
                bool flag2 = fP > FP.Zero;
                if (flag2)
                {
                    result.x = direction.x / fP * this.radius;
                    result.y = FP.Zero;
                    result.z = direction.z / fP * this.radius;
                }
                else
                {
                    result.x = FP.Zero;
                    result.y = FP.Zero;
                    result.z = FP.Zero;
                }
            }
        }
Ejemplo n.º 4
0
        public override void PrepareForIteration(FP timestep)
        {
            TSVector.Transform(ref this.localAnchor1, ref this.body1.orientation, out this.r1);
            TSVector.Transform(ref this.localAnchor2, ref this.body2.orientation, out this.r2);
            TSVector value;

            TSVector.Add(ref this.body1.position, ref this.r1, out value);
            TSVector value2;

            TSVector.Add(ref this.body2.position, ref this.r2, out value2);
            TSVector tSVector;

            TSVector.Subtract(ref value2, ref value, out tSVector);
            FP   x    = tSVector.magnitude - this.distance;
            bool flag = this.behavior == PointPointDistance.DistanceBehavior.LimitMaximumDistance && x <= FP.Zero;

            if (flag)
            {
                this.skipConstraint = true;
            }
            else
            {
                bool flag2 = this.behavior == PointPointDistance.DistanceBehavior.LimitMinimumDistance && x >= FP.Zero;
                if (flag2)
                {
                    this.skipConstraint = true;
                }
                else
                {
                    this.skipConstraint = false;
                    TSVector value3 = value2 - value;
                    bool     flag3  = value3.sqrMagnitude != FP.Zero;
                    if (flag3)
                    {
                        value3.Normalize();
                    }
                    this.jacobian[0]    = -FP.One * value3;
                    this.jacobian[1]    = -FP.One * (this.r1 % value3);
                    this.jacobian[2]    = FP.One * value3;
                    this.jacobian[3]    = this.r2 % value3;
                    this.effectiveMass  = this.body1.inverseMass + this.body2.inverseMass + TSVector.Transform(this.jacobian[1], this.body1.invInertiaWorld) * this.jacobian[1] + TSVector.Transform(this.jacobian[3], this.body2.invInertiaWorld) * this.jacobian[3];
                    this.softnessOverDt = this.softness / timestep;
                    this.effectiveMass += this.softnessOverDt;
                    this.effectiveMass  = FP.One / this.effectiveMass;
                    this.bias           = x * this.biasFactor * (FP.One / timestep);
                    bool flag4 = !this.body1.isStatic;
                    if (flag4)
                    {
                        this.body1.linearVelocity  += this.body1.inverseMass * this.accumulatedImpulse * this.jacobian[0];
                        this.body1.angularVelocity += TSVector.Transform(this.accumulatedImpulse * this.jacobian[1], this.body1.invInertiaWorld);
                    }
                    bool flag5 = !this.body2.isStatic;
                    if (flag5)
                    {
                        this.body2.linearVelocity  += this.body2.inverseMass * this.accumulatedImpulse * this.jacobian[2];
                        this.body2.angularVelocity += TSVector.Transform(this.accumulatedImpulse * this.jacobian[3], this.body2.invInertiaWorld);
                    }
                }
            }
        }
Ejemplo n.º 5
0
            public void SupportMapping(ref TSVector direction, out TSVector result)
            {
                FP       y        = TSVector.Dot(ref this.owner.points[this.indices.I0].position, ref direction);
                FP       fP       = TSVector.Dot(ref this.owner.points[this.indices.I1].position, ref direction);
                TSVector position = this.owner.points[this.indices.I0].position;
                bool     flag     = fP > y;

                if (flag)
                {
                    y        = fP;
                    position = this.owner.points[this.indices.I1].position;
                }
                fP = TSVector.Dot(ref this.owner.points[this.indices.I2].position, ref direction);
                bool flag2 = fP > y;

                if (flag2)
                {
                    position = this.owner.points[this.indices.I2].position;
                }
                TSVector tSVector;

                TSVector.Normalize(ref direction, out tSVector);
                tSVector *= this.owner.triangleExpansion;
                result    = position + tSVector;
            }
Ejemplo n.º 6
0
        public override void SupportMapping(ref TSVector direction, out TSVector result)
        {
            TSVector tSVector;

            TSVector.Normalize(ref direction, out tSVector);
            tSVector *= this.sphericalExpansion;
            FP   y    = TSVector.Dot(ref this.vecs[0], ref direction);
            int  num  = 0;
            FP   fP   = TSVector.Dot(ref this.vecs[1], ref direction);
            bool flag = fP > y;

            if (flag)
            {
                y   = fP;
                num = 1;
            }
            fP = TSVector.Dot(ref this.vecs[2], ref direction);
            bool flag2 = fP > y;

            if (flag2)
            {
                num = 2;
            }
            result = this.vecs[num] + tSVector;
        }
Ejemplo n.º 7
0
 public PointOnLine(RigidBody body1, RigidBody body2, TSVector lineStartPointBody1, TSVector pointBody2) : base(body1, body2)
 {
     TSVector.Subtract(ref lineStartPointBody1, ref body1.position, out this.localAnchor1);
     TSVector.Subtract(ref pointBody2, ref body2.position, out this.localAnchor2);
     TSVector.Transform(ref this.localAnchor1, ref body1.invOrientation, out this.localAnchor1);
     TSVector.Transform(ref this.localAnchor2, ref body2.invOrientation, out this.localAnchor2);
     this.lineNormal = TSVector.Normalize(lineStartPointBody1 - pointBody2);
 }
Ejemplo n.º 8
0
        public override int Prepare(ref TSVector rayOrigin, ref TSVector rayDelta)
        {
            this.potentialTriangles.Clear();
            TSVector tSVector;

            TSVector.Normalize(ref rayDelta, out tSVector);
            tSVector = rayDelta + tSVector * this.sphericalExpansion;
            this.octree.GetTrianglesIntersectingRay(this.potentialTriangles, rayOrigin, tSVector);
            return(this.potentialTriangles.Count);
        }
Ejemplo n.º 9
0
        public override int Prepare(ref TSVector rayOrigin, ref TSVector rayDelta)
        {
            TSBBox   smallBox = TSBBox.SmallBox;
            TSVector value;

            TSVector.Normalize(ref rayDelta, out value);
            value = rayOrigin + rayDelta + value * this.sphericalExpansion;
            smallBox.AddPoint(ref rayOrigin);
            smallBox.AddPoint(ref value);
            return(this.Prepare(ref smallBox));
        }
Ejemplo n.º 10
0
        public override void PrepareForIteration(FP timestep)
        {
            TSVector.Transform(ref this.localAnchor1, ref this.body1.orientation, out this.r1);
            TSVector.Transform(ref this.localAnchor2, ref this.body2.orientation, out this.r2);
            TSVector tSVector;

            TSVector.Add(ref this.body1.position, ref this.r1, out tSVector);
            TSVector tSVector2;

            TSVector.Add(ref this.body2.position, ref this.r2, out tSVector2);
            TSVector tSVector3;

            TSVector.Subtract(ref tSVector2, ref tSVector, out tSVector3);
            TSVector tSVector4 = TSVector.Transform(this.lineNormal, this.body1.orientation);

            tSVector4.Normalize();
            TSVector tSVector5 = (tSVector - tSVector2) % tSVector4;
            bool     flag      = tSVector5.sqrMagnitude != FP.Zero;

            if (flag)
            {
                tSVector5.Normalize();
            }
            tSVector5          %= tSVector4;
            this.jacobian[0]    = tSVector5;
            this.jacobian[1]    = (this.r1 + tSVector2 - tSVector) % tSVector5;
            this.jacobian[2]    = -FP.One * tSVector5;
            this.jacobian[3]    = -FP.One * this.r2 % tSVector5;
            this.effectiveMass  = this.body1.inverseMass + this.body2.inverseMass + TSVector.Transform(this.jacobian[1], this.body1.invInertiaWorld) * this.jacobian[1] + TSVector.Transform(this.jacobian[3], this.body2.invInertiaWorld) * this.jacobian[3];
            this.softnessOverDt = this.softness / timestep;
            this.effectiveMass += this.softnessOverDt;
            bool flag2 = this.effectiveMass != 0;

            if (flag2)
            {
                this.effectiveMass = FP.One / this.effectiveMass;
            }
            this.bias = -(tSVector4 % (tSVector2 - tSVector)).magnitude * this.biasFactor * (FP.One / timestep);
            bool flag3 = !this.body1.isStatic;

            if (flag3)
            {
                this.body1.linearVelocity  += this.body1.inverseMass * this.accumulatedImpulse * this.jacobian[0];
                this.body1.angularVelocity += TSVector.Transform(this.accumulatedImpulse * this.jacobian[1], this.body1.invInertiaWorld);
            }
            bool flag4 = !this.body2.isStatic;

            if (flag4)
            {
                this.body2.linearVelocity  += this.body2.inverseMass * this.accumulatedImpulse * this.jacobian[2];
                this.body2.angularVelocity += TSVector.Transform(this.accumulatedImpulse * this.jacobian[3], this.body2.invInertiaWorld);
            }
        }
Ejemplo n.º 11
0
        public static bool ClosestPoints(ISupportMappable support1, ISupportMappable support2, ref TSMatrix orientation1, ref TSMatrix orientation2, ref TSVector position1, ref TSVector position2, out TSVector p1, out TSVector p2, out TSVector normal)
        {
            VoronoiSimplexSolver @new = GJKCollide.simplexSolverPool.GetNew();

            @new.Reset();
            p1 = (p2 = TSVector.zero);
            TSVector value    = position1 - position2;
            TSVector tSVector = TSVector.Negate(value);
            TSVector tSVector2;

            GJKCollide.SupportMapTransformed(support1, ref orientation1, ref position1, ref tSVector, out tSVector2);
            TSVector tSVector3;

            GJKCollide.SupportMapTransformed(support2, ref orientation2, ref position2, ref value, out tSVector3);
            TSVector tSVector4 = tSVector2 - tSVector3;

            normal = TSVector.zero;
            int num = 15;
            FP  x   = tSVector4.sqrMagnitude;
            FP  eN  = FP.EN5;

            while (x > eN && num-- != 0)
            {
                TSVector tSVector5 = TSVector.Negate(tSVector4);
                GJKCollide.SupportMapTransformed(support1, ref orientation1, ref position1, ref tSVector5, out tSVector2);
                GJKCollide.SupportMapTransformed(support2, ref orientation2, ref position2, ref tSVector4, out tSVector3);
                TSVector w    = tSVector2 - tSVector3;
                bool     flag = [email protected](w);
                if (flag)
                {
                    @new.AddVertex(w, tSVector2, tSVector3);
                }
                bool flag2 = @new.Closest(out tSVector4);
                if (flag2)
                {
                    x      = tSVector4.sqrMagnitude;
                    normal = tSVector4;
                }
                else
                {
                    x = FP.Zero;
                }
            }
            @new.ComputePoints(out p1, out p2);
            bool flag3 = normal.sqrMagnitude > TSMath.Epsilon * TSMath.Epsilon;

            if (flag3)
            {
                normal.Normalize();
            }
            GJKCollide.simplexSolverPool.GiveBack(@new);
            return(true);
        }
Ejemplo n.º 12
0
        public static TSQuaternion AngleAxis(FP angle, TSVector axis)
        {
            axis *= FP.Deg2Rad;
            axis.Normalize();
            FP           fP  = angle * FP.Deg2Rad * FP.Half;
            FP           fP2 = FP.Sin(fP);
            TSQuaternion result;

            result.x = axis.x * fP2;
            result.y = axis.y * fP2;
            result.z = axis.z * fP2;
            result.w = FP.Cos(fP);
            return(result);
        }
Ejemplo n.º 13
0
            public override void PrepareForIteration(FP timestep)
            {
                TSVector tSVector;

                TSVector.Subtract(ref this.body2.position, ref this.body1.position, out tSVector);
                FP   x    = tSVector.magnitude - this.distance;
                bool flag = this.behavior == SoftBody.Spring.DistanceBehavior.LimitMaximumDistance && x <= FP.Zero;

                if (flag)
                {
                    this.skipConstraint = true;
                }
                else
                {
                    bool flag2 = this.behavior == SoftBody.Spring.DistanceBehavior.LimitMinimumDistance && x >= FP.Zero;
                    if (flag2)
                    {
                        this.skipConstraint = true;
                    }
                    else
                    {
                        this.skipConstraint = false;
                        TSVector value = tSVector;
                        bool     flag3 = value.sqrMagnitude != FP.Zero;
                        if (flag3)
                        {
                            value.Normalize();
                        }
                        this.jacobian[0]    = -FP.One * value;
                        this.jacobian[1]    = FP.One * value;
                        this.effectiveMass  = this.body1.inverseMass + this.body2.inverseMass;
                        this.softnessOverDt = this.softness / timestep;
                        this.effectiveMass += this.softnessOverDt;
                        this.effectiveMass  = FP.One / this.effectiveMass;
                        this.bias           = x * this.biasFactor * (FP.One / timestep);
                        bool flag4 = !this.body1.isStatic;
                        if (flag4)
                        {
                            this.body1.linearVelocity += this.body1.inverseMass * this.accumulatedImpulse * this.jacobian[0];
                        }
                        bool flag5 = !this.body2.isStatic;
                        if (flag5)
                        {
                            this.body2.linearVelocity += this.body2.inverseMass * this.accumulatedImpulse * this.jacobian[1];
                        }
                    }
                }
            }
Ejemplo n.º 14
0
        public static TSQuaternion AngleAxis(FP angle, TSVector axis)
        {
            axis = axis * FP.Deg2Rad;
            axis.Normalize();

            FP halfAngle = angle * FP.Deg2Rad * FP.Half;

            TSQuaternion rotation;
            FP           sin = FP.Sin(halfAngle);

            rotation.x = axis.x * sin;
            rotation.y = axis.y * sin;
            rotation.z = axis.z * sin;
            rotation.w = FP.Cos(halfAngle);

            return(rotation);
        }
Ejemplo n.º 15
0
        public override void PrepareForIteration(FP timestep)
        {
            TSVector.Transform(ref this.localAnchor1, ref this.body1.orientation, out this.r1);
            TSVector.Transform(ref this.localAnchor2, ref this.body2.orientation, out this.r2);
            TSVector value;

            TSVector.Add(ref this.body1.position, ref this.r1, out value);
            TSVector value2;

            TSVector.Add(ref this.body2.position, ref this.r2, out value2);
            TSVector tSVector;

            TSVector.Subtract(ref value2, ref value, out tSVector);
            FP       magnitude = tSVector.magnitude;
            TSVector value3    = value2 - value;
            bool     flag      = value3.sqrMagnitude != FP.Zero;

            if (flag)
            {
                value3.Normalize();
            }
            this.jacobian[0]    = -FP.One * value3;
            this.jacobian[1]    = -FP.One * (this.r1 % value3);
            this.jacobian[2]    = FP.One * value3;
            this.jacobian[3]    = this.r2 % value3;
            this.effectiveMass  = this.body1.inverseMass + this.body2.inverseMass + TSVector.Transform(this.jacobian[1], this.body1.invInertiaWorld) * this.jacobian[1] + TSVector.Transform(this.jacobian[3], this.body2.invInertiaWorld) * this.jacobian[3];
            this.softnessOverDt = this.softness / timestep;
            this.effectiveMass += this.softnessOverDt;
            this.effectiveMass  = FP.One / this.effectiveMass;
            this.bias           = magnitude * this.biasFactor * (FP.One / timestep);
            bool flag2 = !this.body1.isStatic;

            if (flag2)
            {
                this.body1.linearVelocity  += this.body1.inverseMass * this.accumulatedImpulse * this.jacobian[0];
                this.body1.angularVelocity += TSVector.Transform(this.accumulatedImpulse * this.jacobian[1], this.body1.invInertiaWorld);
            }
            bool flag3 = !this.body2.isStatic;

            if (flag3)
            {
                this.body2.linearVelocity  += this.body2.inverseMass * this.accumulatedImpulse * this.jacobian[2];
                this.body2.angularVelocity += TSVector.Transform(this.accumulatedImpulse * this.jacobian[3], this.body2.invInertiaWorld);
            }
        }
Ejemplo n.º 16
0
        public static void LookAt(out TSMatrix result, TSVector position, TSVector target)
        {
            TSVector tSVector = target - position;

            tSVector.Normalize();
            TSVector tSVector2 = TSVector.Cross(TSVector.up, tSVector);

            tSVector2.Normalize();
            TSVector tSVector3 = TSVector.Cross(tSVector, tSVector2);

            result.M11 = tSVector2.x;
            result.M21 = tSVector3.x;
            result.M31 = tSVector.x;
            result.M12 = tSVector2.y;
            result.M22 = tSVector3.y;
            result.M32 = tSVector.y;
            result.M13 = tSVector2.z;
            result.M23 = tSVector3.z;
            result.M33 = tSVector.z;
        }
Ejemplo n.º 17
0
 public override void SupportMapping(ref TSVector direction, out TSVector result)
 {
     result = direction;
     result.Normalize();
     TSVector.Multiply(ref result, this.radius, out result);
 }
Ejemplo n.º 18
0
        public static bool Raycast(ISupportMappable support, ref TSMatrix orientation, ref TSMatrix invOrientation, ref TSVector position, ref TSVector origin, ref TSVector direction, out FP fraction, out TSVector normal)
        {
            VoronoiSimplexSolver @new = GJKCollide.simplexSolverPool.GetNew();

            @new.Reset();
            normal   = TSVector.zero;
            fraction = FP.MaxValue;
            FP       fP       = FP.Zero;
            TSVector tSVector = direction;
            TSVector p        = origin;
            TSVector tSVector2;

            GJKCollide.SupportMapTransformed(support, ref orientation, ref position, ref tSVector, out tSVector2);
            TSVector tSVector3;

            TSVector.Subtract(ref p, ref tSVector2, out tSVector3);
            int  num = 15;
            FP   x   = tSVector3.sqrMagnitude;
            FP   eN  = FP.EN6;
            bool result;

            while (x > eN && num-- != 0)
            {
                TSVector q;
                GJKCollide.SupportMapTransformed(support, ref orientation, ref position, ref tSVector3, out q);
                TSVector w;
                TSVector.Subtract(ref p, ref q, out w);
                FP   x2   = TSVector.Dot(ref tSVector3, ref w);
                bool flag = x2 > FP.Zero;
                if (flag)
                {
                    FP   fP2   = TSVector.Dot(ref tSVector3, ref tSVector);
                    bool flag2 = fP2 >= -TSMath.Epsilon;
                    if (flag2)
                    {
                        GJKCollide.simplexSolverPool.GiveBack(@new);
                        result = false;
                        return(result);
                    }
                    fP -= x2 / fP2;
                    TSVector.Multiply(ref tSVector, fP, out p);
                    TSVector.Add(ref origin, ref p, out p);
                    TSVector.Subtract(ref p, ref q, out w);
                    normal = tSVector3;
                }
                bool flag3 = [email protected](w);
                if (flag3)
                {
                    @new.AddVertex(w, p, q);
                }
                bool flag4 = @new.Closest(out tSVector3);
                if (flag4)
                {
                    x = tSVector3.sqrMagnitude;
                }
                else
                {
                    x = FP.Zero;
                }
            }
            TSVector tSVector4;
            TSVector value;

            @new.ComputePoints(out tSVector4, out value);
            value   -= origin;
            fraction = value.magnitude / direction.magnitude;
            bool flag5 = normal.sqrMagnitude > TSMath.Epsilon * TSMath.Epsilon;

            if (flag5)
            {
                normal.Normalize();
            }
            GJKCollide.simplexSolverPool.GiveBack(@new);
            result = true;
            return(result);
        }
Ejemplo n.º 19
0
        public virtual void MakeHull(ref List <TSVector> triangleList, int generationThreshold)
        {
            FP   zero = FP.Zero;
            bool flag = generationThreshold < 0;

            if (flag)
            {
                generationThreshold = 4;
            }
            Stack <Shape.ClipTriangle> stack = new Stack <Shape.ClipTriangle>();

            TSVector[] array = new TSVector[]
            {
                new TSVector(-1, 0, 0),
                new TSVector(1, 0, 0),
                new TSVector(0, -1, 0),
                new TSVector(0, 1, 0),
                new TSVector(0, 0, -1),
                new TSVector(0, 0, 1)
            };
            int[,] array2 = new int[, ]
            {
                {
                    5,
                    1,
                    3
                },
                {
                    4,
                    3,
                    1
                },
                {
                    3,
                    4,
                    0
                },
                {
                    0,
                    5,
                    3
                },
                {
                    5,
                    2,
                    1
                },
                {
                    4,
                    1,
                    2
                },
                {
                    2,
                    0,
                    4
                },
                {
                    0,
                    2,
                    5
                }
            };
            for (int i = 0; i < 8; i++)
            {
                stack.Push(new Shape.ClipTriangle
                {
                    n1         = array[array2[i, 0]],
                    n2         = array[array2[i, 1]],
                    n3         = array[array2[i, 2]],
                    generation = 0
                });
            }
            while (stack.Count > 0)
            {
                Shape.ClipTriangle clipTriangle = stack.Pop();
                TSVector           tSVector;
                this.SupportMapping(ref clipTriangle.n1, out tSVector);
                TSVector tSVector2;
                this.SupportMapping(ref clipTriangle.n2, out tSVector2);
                TSVector tSVector3;
                this.SupportMapping(ref clipTriangle.n3, out tSVector3);
                FP   sqrMagnitude  = (tSVector2 - tSVector).sqrMagnitude;
                FP   sqrMagnitude2 = (tSVector3 - tSVector2).sqrMagnitude;
                FP   sqrMagnitude3 = (tSVector - tSVector3).sqrMagnitude;
                bool flag2         = TSMath.Max(TSMath.Max(sqrMagnitude, sqrMagnitude2), sqrMagnitude3) > zero && clipTriangle.generation < generationThreshold;
                if (flag2)
                {
                    Shape.ClipTriangle item  = default(Shape.ClipTriangle);
                    Shape.ClipTriangle item2 = default(Shape.ClipTriangle);
                    Shape.ClipTriangle item3 = default(Shape.ClipTriangle);
                    Shape.ClipTriangle item4 = default(Shape.ClipTriangle);
                    item.generation  = clipTriangle.generation + 1;
                    item2.generation = clipTriangle.generation + 1;
                    item3.generation = clipTriangle.generation + 1;
                    item4.generation = clipTriangle.generation + 1;
                    item.n1          = clipTriangle.n1;
                    item2.n2         = clipTriangle.n2;
                    item3.n3         = clipTriangle.n3;
                    TSVector tSVector4 = FP.Half * (clipTriangle.n1 + clipTriangle.n2);
                    tSVector4.Normalize();
                    item.n2   = tSVector4;
                    item2.n1  = tSVector4;
                    item4.n3  = tSVector4;
                    tSVector4 = FP.Half * (clipTriangle.n2 + clipTriangle.n3);
                    tSVector4.Normalize();
                    item2.n3  = tSVector4;
                    item3.n2  = tSVector4;
                    item4.n1  = tSVector4;
                    tSVector4 = FP.Half * (clipTriangle.n3 + clipTriangle.n1);
                    tSVector4.Normalize();
                    item.n3  = tSVector4;
                    item3.n1 = tSVector4;
                    item4.n2 = tSVector4;
                    stack.Push(item);
                    stack.Push(item2);
                    stack.Push(item3);
                    stack.Push(item4);
                }
                else
                {
                    bool flag3 = ((tSVector3 - tSVector) % (tSVector2 - tSVector)).sqrMagnitude > TSMath.Epsilon;
                    if (flag3)
                    {
                        triangleList.Add(tSVector);
                        triangleList.Add(tSVector2);
                        triangleList.Add(tSVector3);
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public static bool Detect(ISupportMappable support1, ISupportMappable support2, ref TSMatrix orientation1, ref TSMatrix orientation2, ref TSVector position1, ref TSVector position2, out TSVector point, out TSVector normal, out FP penetration)
        {
            TSVector zero  = TSVector.zero;
            TSVector zero2 = TSVector.zero;
            TSVector zero3 = TSVector.zero;

            point       = (normal = TSVector.zero);
            penetration = FP.Zero;
            TSVector tSVector;

            support1.SupportCenter(out tSVector);
            TSVector.Transform(ref tSVector, ref orientation1, out tSVector);
            TSVector.Add(ref position1, ref tSVector, out tSVector);
            TSVector tSVector2;

            support2.SupportCenter(out tSVector2);
            TSVector.Transform(ref tSVector2, ref orientation2, out tSVector2);
            TSVector.Add(ref position2, ref tSVector2, out tSVector2);
            TSVector tSVector3;

            TSVector.Subtract(ref tSVector2, ref tSVector, out tSVector3);
            bool flag = tSVector3.IsNearlyZero();

            if (flag)
            {
                tSVector3 = new TSVector(FP.EN4, 0, 0);
            }
            TSVector tSVector4 = tSVector3;

            TSVector.Negate(ref tSVector3, out normal);
            TSVector tSVector5;

            XenoCollide.SupportMapTransformed(support1, ref orientation1, ref position1, ref tSVector4, out tSVector5);
            TSVector tSVector6;

            XenoCollide.SupportMapTransformed(support2, ref orientation2, ref position2, ref normal, out tSVector6);
            TSVector tSVector7;

            TSVector.Subtract(ref tSVector6, ref tSVector5, out tSVector7);
            bool flag2 = TSVector.Dot(ref tSVector7, ref normal) <= FP.Zero;
            bool result;

            if (flag2)
            {
                result = false;
            }
            else
            {
                TSVector.Cross(ref tSVector7, ref tSVector3, out normal);
                bool flag3 = normal.IsNearlyZero();
                if (flag3)
                {
                    TSVector.Subtract(ref tSVector7, ref tSVector3, out normal);
                    normal.Normalize();
                    point = tSVector5;
                    TSVector.Add(ref point, ref tSVector6, out point);
                    TSVector.Multiply(ref point, FP.Half, out point);
                    TSVector tSVector8;
                    TSVector.Subtract(ref tSVector6, ref tSVector5, out tSVector8);
                    penetration = TSVector.Dot(ref tSVector8, ref normal);
                    result      = true;
                }
                else
                {
                    TSVector.Negate(ref normal, out tSVector4);
                    TSVector tSVector9;
                    XenoCollide.SupportMapTransformed(support1, ref orientation1, ref position1, ref tSVector4, out tSVector9);
                    TSVector tSVector10;
                    XenoCollide.SupportMapTransformed(support2, ref orientation2, ref position2, ref normal, out tSVector10);
                    TSVector tSVector11;
                    TSVector.Subtract(ref tSVector10, ref tSVector9, out tSVector11);
                    bool flag4 = TSVector.Dot(ref tSVector11, ref normal) <= FP.Zero;
                    if (flag4)
                    {
                        result = false;
                    }
                    else
                    {
                        TSVector tSVector8;
                        TSVector.Subtract(ref tSVector7, ref tSVector3, out tSVector8);
                        TSVector tSVector12;
                        TSVector.Subtract(ref tSVector11, ref tSVector3, out tSVector12);
                        TSVector.Cross(ref tSVector8, ref tSVector12, out normal);
                        FP   x     = TSVector.Dot(ref normal, ref tSVector3);
                        bool flag5 = x > FP.Zero;
                        if (flag5)
                        {
                            TSVector.Swap(ref tSVector7, ref tSVector11);
                            TSVector.Swap(ref tSVector5, ref tSVector9);
                            TSVector.Swap(ref tSVector6, ref tSVector10);
                            TSVector.Negate(ref normal, out normal);
                            Debug.Log("normal: " + normal);
                        }
                        int  num   = 0;
                        int  num2  = 0;
                        bool flag6 = false;
                        while (true)
                        {
                            bool flag7 = num2 > 34;
                            if (flag7)
                            {
                                break;
                            }
                            num2++;
                            TSVector.Negate(ref normal, out tSVector4);
                            TSVector tSVector13;
                            XenoCollide.SupportMapTransformed(support1, ref orientation1, ref position1, ref tSVector4, out tSVector13);
                            TSVector tSVector14;
                            XenoCollide.SupportMapTransformed(support2, ref orientation2, ref position2, ref normal, out tSVector14);
                            TSVector tSVector15;
                            TSVector.Subtract(ref tSVector14, ref tSVector13, out tSVector15);
                            bool flag8 = TSVector.Dot(ref tSVector15, ref normal) <= FP.Zero;
                            if (flag8)
                            {
                                goto Block_7;
                            }
                            TSVector.Cross(ref tSVector7, ref tSVector15, out tSVector8);
                            bool flag9 = TSVector.Dot(ref tSVector8, ref tSVector3) < FP.Zero;
                            if (flag9)
                            {
                                tSVector11 = tSVector15;
                                tSVector9  = tSVector13;
                                tSVector10 = tSVector14;
                                TSVector.Subtract(ref tSVector7, ref tSVector3, out tSVector8);
                                TSVector.Subtract(ref tSVector15, ref tSVector3, out tSVector12);
                                TSVector.Cross(ref tSVector8, ref tSVector12, out normal);
                            }
                            else
                            {
                                TSVector.Cross(ref tSVector15, ref tSVector11, out tSVector8);
                                bool flag10 = TSVector.Dot(ref tSVector8, ref tSVector3) < FP.Zero;
                                if (!flag10)
                                {
                                    goto IL_385;
                                }
                                tSVector7 = tSVector15;
                                tSVector5 = tSVector13;
                                tSVector6 = tSVector14;
                                TSVector.Subtract(ref tSVector15, ref tSVector3, out tSVector8);
                                TSVector.Subtract(ref tSVector11, ref tSVector3, out tSVector12);
                                TSVector.Cross(ref tSVector8, ref tSVector12, out normal);
                            }
                        }
                        result = false;
                        return(result);

Block_7:
                        result = false;
                        return(result);

IL_385:
                        while (true)
                        {
                            num++;
                            TSVector.Subtract(ref tSVector11, ref tSVector7, out tSVector8);
                            TSVector tSVector15;
                            TSVector.Subtract(ref tSVector15, ref tSVector7, out tSVector12);
                            TSVector.Cross(ref tSVector8, ref tSVector12, out normal);
                            bool flag11 = normal.IsNearlyZero();
                            if (flag11)
                            {
                                break;
                            }
                            normal.Normalize();
                            FP   x2     = TSVector.Dot(ref normal, ref tSVector7);
                            bool flag12 = x2 >= 0 && !flag6;
                            if (flag12)
                            {
                                flag6 = true;
                            }
                            TSVector.Negate(ref normal, out tSVector4);
                            XenoCollide.SupportMapTransformed(support1, ref orientation1, ref position1, ref tSVector4, out zero);
                            XenoCollide.SupportMapTransformed(support2, ref orientation2, ref position2, ref normal, out zero2);
                            TSVector.Subtract(ref zero2, ref zero, out zero3);
                            TSVector.Subtract(ref zero3, ref tSVector15, out tSVector8);
                            FP x3 = TSVector.Dot(ref tSVector8, ref normal);
                            penetration = TSVector.Dot(ref zero3, ref normal);
                            bool flag13 = x3 <= XenoCollide.CollideEpsilon || penetration <= FP.Zero || num > 34;
                            if (flag13)
                            {
                                goto Block_15;
                            }
                            TSVector.Cross(ref zero3, ref tSVector3, out tSVector8);
                            FP   x4     = TSVector.Dot(ref tSVector8, ref tSVector7);
                            bool flag14 = x4 >= FP.Zero;
                            if (flag14)
                            {
                                x4 = TSVector.Dot(ref tSVector8, ref tSVector11);
                                bool flag15 = x4 >= FP.Zero;
                                if (flag15)
                                {
                                    tSVector7 = zero3;
                                    tSVector5 = zero;
                                    tSVector6 = zero2;
                                }
                                else
                                {
                                    tSVector15 = zero3;
                                    TSVector tSVector13 = zero;
                                    TSVector tSVector14 = zero2;
                                }
                            }
                            else
                            {
                                x4 = TSVector.Dot(ref tSVector8, ref tSVector15);
                                bool flag16 = x4 >= FP.Zero;
                                if (flag16)
                                {
                                    tSVector11 = zero3;
                                    tSVector9  = zero;
                                    tSVector10 = zero2;
                                }
                                else
                                {
                                    tSVector7 = zero3;
                                    tSVector5 = zero;
                                    tSVector6 = zero2;
                                }
                            }
                        }
                        result = true;
                        return(result);

Block_15:
                        bool flag17 = flag6;
                        if (flag17)
                        {
                            TSVector.Cross(ref tSVector7, ref tSVector11, out tSVector8);
                            TSVector tSVector15;
                            FP       fP = TSVector.Dot(ref tSVector8, ref tSVector15);
                            TSVector.Cross(ref tSVector15, ref tSVector11, out tSVector8);
                            FP fP2 = TSVector.Dot(ref tSVector8, ref tSVector3);
                            TSVector.Cross(ref tSVector3, ref tSVector7, out tSVector8);
                            FP fP3 = TSVector.Dot(ref tSVector8, ref tSVector15);
                            TSVector.Cross(ref tSVector11, ref tSVector7, out tSVector8);
                            FP   fP4    = TSVector.Dot(ref tSVector8, ref tSVector3);
                            FP   fP5    = fP + fP2 + fP3 + fP4;
                            bool flag18 = fP5 <= 0;
                            if (flag18)
                            {
                                fP = 0;
                                TSVector.Cross(ref tSVector11, ref tSVector15, out tSVector8);
                                fP2 = TSVector.Dot(ref tSVector8, ref normal);
                                TSVector.Cross(ref tSVector15, ref tSVector7, out tSVector8);
                                fP3 = TSVector.Dot(ref tSVector8, ref normal);
                                TSVector.Cross(ref tSVector7, ref tSVector11, out tSVector8);
                                fP4 = TSVector.Dot(ref tSVector8, ref normal);
                                fP5 = fP2 + fP3 + fP4;
                            }
                            FP x5 = FP.One / fP5;
                            TSVector.Multiply(ref tSVector, fP, out point);
                            TSVector.Multiply(ref tSVector5, fP2, out tSVector8);
                            TSVector.Add(ref point, ref tSVector8, out point);
                            TSVector.Multiply(ref tSVector9, fP3, out tSVector8);
                            TSVector.Add(ref point, ref tSVector8, out point);
                            TSVector tSVector13;
                            TSVector.Multiply(ref tSVector13, fP4, out tSVector8);
                            TSVector.Add(ref point, ref tSVector8, out point);
                            TSVector.Multiply(ref tSVector2, fP, out tSVector12);
                            TSVector.Add(ref tSVector12, ref point, out point);
                            TSVector.Multiply(ref tSVector6, fP2, out tSVector8);
                            TSVector.Add(ref point, ref tSVector8, out point);
                            TSVector.Multiply(ref tSVector10, fP3, out tSVector8);
                            TSVector.Add(ref point, ref tSVector8, out point);
                            TSVector tSVector14;
                            TSVector.Multiply(ref tSVector14, fP4, out tSVector8);
                            TSVector.Add(ref point, ref tSVector8, out point);
                            TSVector.Multiply(ref point, x5 * FP.Half, out point);
                        }
                        result = flag6;
                    }
                }
            }
            return(result);
        }