コード例 #1
0
ファイル: CollisionSystem.cs プロジェクト: yuruyigit/TrueSync
        private void DetectSoftRigid(RigidBody rigidBody, SoftBody softBody)
        {
            bool flag = rigidBody.Shape is Multishape;

            if (flag)
            {
                Multishape multishape = rigidBody.Shape as Multishape;
                multishape = multishape.RequestWorkingClone();
                TSBBox boundingBox = softBody.BoundingBox;
                boundingBox.InverseTransform(ref rigidBody.position, ref rigidBody.orientation);
                int        num  = multishape.Prepare(ref boundingBox);
                List <int> @new = this.potentialTriangleLists.GetNew();
                softBody.dynamicTree.Query(@new, ref rigidBody.boundingBox);
                foreach (int current in @new)
                {
                    SoftBody.Triangle userData = softBody.dynamicTree.GetUserData(current);
                    for (int i = 0; i < num; i++)
                    {
                        multishape.SetCurrentShape(i);
                        TSVector tSVector;
                        TSVector tSVector2;
                        FP       penetration;
                        bool     flag2 = XenoCollide.Detect(multishape, userData, ref rigidBody.orientation, ref TSMatrix.InternalIdentity, ref rigidBody.position, ref TSVector.InternalZero, out tSVector, out tSVector2, out penetration);
                        bool     flag3 = flag2;
                        if (flag3)
                        {
                            int index = CollisionSystem.FindNearestTrianglePoint(softBody, current, ref tSVector);
                            this.RaiseCollisionDetected(rigidBody, softBody.VertexBodies[index], ref tSVector, ref tSVector, ref tSVector2, penetration);
                        }
                    }
                }
                @new.Clear();
                this.potentialTriangleLists.GiveBack(@new);
                multishape.ReturnWorkingClone();
            }
            else
            {
                List <int> new2 = this.potentialTriangleLists.GetNew();
                softBody.dynamicTree.Query(new2, ref rigidBody.boundingBox);
                foreach (int current2 in new2)
                {
                    SoftBody.Triangle userData2 = softBody.dynamicTree.GetUserData(current2);
                    TSVector          tSVector3;
                    TSVector          tSVector4;
                    FP   penetration2;
                    bool flag4 = XenoCollide.Detect(rigidBody.Shape, userData2, ref rigidBody.orientation, ref TSMatrix.InternalIdentity, ref rigidBody.position, ref TSVector.InternalZero, out tSVector3, out tSVector4, out penetration2);
                    bool flag5 = flag4;
                    if (flag5)
                    {
                        int index2 = CollisionSystem.FindNearestTrianglePoint(softBody, current2, ref tSVector3);
                        this.RaiseCollisionDetected(rigidBody, softBody.VertexBodies[index2], ref tSVector3, ref tSVector3, ref tSVector4, penetration2);
                    }
                }
                new2.Clear();
                this.potentialTriangleLists.GiveBack(new2);
            }
        }
コード例 #2
0
ファイル: CollisionSystem.cs プロジェクト: yuruyigit/TrueSync
        private void DetectRigidRigid(RigidBody body1, RigidBody body2)
        {
            bool flag  = body1.Shape is Multishape;
            bool flag2 = body2.Shape is Multishape;
            bool flag3 = this.speculativeContacts || body1.EnableSpeculativeContacts || body2.EnableSpeculativeContacts;
            bool flag4 = !flag && !flag2;

            if (flag4)
            {
                TSVector tSVector;
                TSVector value;
                FP       fP;
                bool     flag5 = XenoCollide.Detect(body1.Shape, body2.Shape, ref body1.orientation, ref body2.orientation, ref body1.position, ref body2.position, out tSVector, out value, out fP);
                if (flag5)
                {
                    TSVector tSVector2;
                    TSVector tSVector3;
                    this.FindSupportPoints(body1, body2, body1.Shape, body2.Shape, ref tSVector, ref value, out tSVector2, out tSVector3);
                    this.RaiseCollisionDetected(body1, body2, ref tSVector2, ref tSVector3, ref value, fP);
                }
                else
                {
                    bool flag6 = flag3;
                    if (flag6)
                    {
                        TSVector value2;
                        TSVector value3;
                        bool     flag7 = GJKCollide.ClosestPoints(body1.Shape, body2.Shape, ref body1.orientation, ref body2.orientation, ref body1.position, ref body2.position, out value2, out value3, out value);
                        if (flag7)
                        {
                            TSVector value4 = value3 - value2;
                            bool     flag8  = value4.sqrMagnitude < (body1.sweptDirection - body2.sweptDirection).sqrMagnitude;
                            if (flag8)
                            {
                                fP = value4 * value;
                                bool flag9 = fP < FP.Zero;
                                if (flag9)
                                {
                                    this.RaiseCollisionDetected(body1, body2, ref value2, ref value3, ref value, fP);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                bool flag10 = flag & flag2;
                if (flag10)
                {
                    Multishape multishape  = body1.Shape as Multishape;
                    Multishape multishape2 = body2.Shape as Multishape;
                    multishape  = multishape.RequestWorkingClone();
                    multishape2 = multishape2.RequestWorkingClone();
                    TSBBox boundingBox = body2.boundingBox;
                    boundingBox.InverseTransform(ref body1.position, ref body1.orientation);
                    int num = multishape.Prepare(ref boundingBox);
                    boundingBox = body1.boundingBox;
                    boundingBox.InverseTransform(ref body2.position, ref body2.orientation);
                    int  num2   = multishape2.Prepare(ref boundingBox);
                    bool flag11 = num == 0 || num2 == 0;
                    if (flag11)
                    {
                        multishape.ReturnWorkingClone();
                        multishape2.ReturnWorkingClone();
                    }
                    else
                    {
                        for (int i = 0; i < num; i++)
                        {
                            multishape.SetCurrentShape(i);
                            for (int j = 0; j < num2; j++)
                            {
                                multishape2.SetCurrentShape(j);
                                TSVector tSVector;
                                TSVector value;
                                FP       fP;
                                bool     flag12 = XenoCollide.Detect(multishape, multishape2, ref body1.orientation, ref body2.orientation, ref body1.position, ref body2.position, out tSVector, out value, out fP);
                                if (flag12)
                                {
                                    TSVector tSVector4;
                                    TSVector tSVector5;
                                    this.FindSupportPoints(body1, body2, multishape, multishape2, ref tSVector, ref value, out tSVector4, out tSVector5);
                                    this.RaiseCollisionDetected(body1, body2, ref tSVector4, ref tSVector5, ref value, fP);
                                }
                                else
                                {
                                    bool flag13 = flag3;
                                    if (flag13)
                                    {
                                        TSVector value5;
                                        TSVector value6;
                                        bool     flag14 = GJKCollide.ClosestPoints(multishape, multishape2, ref body1.orientation, ref body2.orientation, ref body1.position, ref body2.position, out value5, out value6, out value);
                                        if (flag14)
                                        {
                                            TSVector value7 = value6 - value5;
                                            bool     flag15 = value7.sqrMagnitude < (body1.sweptDirection - body2.sweptDirection).sqrMagnitude;
                                            if (flag15)
                                            {
                                                fP = value7 * value;
                                                bool flag16 = fP < FP.Zero;
                                                if (flag16)
                                                {
                                                    this.RaiseCollisionDetected(body1, body2, ref value5, ref value6, ref value, fP);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        multishape.ReturnWorkingClone();
                        multishape2.ReturnWorkingClone();
                    }
                }
                else
                {
                    bool      flag17 = body2.Shape is Multishape;
                    RigidBody rigidBody;
                    RigidBody rigidBody2;
                    if (flag17)
                    {
                        rigidBody  = body2;
                        rigidBody2 = body1;
                    }
                    else
                    {
                        rigidBody2 = body2;
                        rigidBody  = body1;
                    }
                    Multishape multishape3 = rigidBody.Shape as Multishape;
                    multishape3 = multishape3.RequestWorkingClone();
                    TSBBox boundingBox2 = rigidBody2.boundingBox;
                    boundingBox2.InverseTransform(ref rigidBody.position, ref rigidBody.orientation);
                    int  num3   = multishape3.Prepare(ref boundingBox2);
                    bool flag18 = num3 == 0;
                    if (flag18)
                    {
                        multishape3.ReturnWorkingClone();
                    }
                    else
                    {
                        for (int k = 0; k < num3; k++)
                        {
                            multishape3.SetCurrentShape(k);
                            TSVector tSVector;
                            TSVector value;
                            FP       fP;
                            bool     flag19 = XenoCollide.Detect(multishape3, rigidBody2.Shape, ref rigidBody.orientation, ref rigidBody2.orientation, ref rigidBody.position, ref rigidBody2.position, out tSVector, out value, out fP);
                            if (flag19)
                            {
                                TSVector tSVector6;
                                TSVector tSVector7;
                                this.FindSupportPoints(rigidBody, rigidBody2, multishape3, rigidBody2.Shape, ref tSVector, ref value, out tSVector6, out tSVector7);
                                bool flag20 = this.useTerrainNormal && multishape3 is TerrainShape;
                                if (flag20)
                                {
                                    (multishape3 as TerrainShape).CollisionNormal(out value);
                                    TSVector.Transform(ref value, ref rigidBody.orientation, out value);
                                }
                                else
                                {
                                    bool flag21 = this.useTriangleMeshNormal && multishape3 is TriangleMeshShape;
                                    if (flag21)
                                    {
                                        (multishape3 as TriangleMeshShape).CollisionNormal(out value);
                                        TSVector.Transform(ref value, ref rigidBody.orientation, out value);
                                    }
                                }
                                this.RaiseCollisionDetected(rigidBody, rigidBody2, ref tSVector6, ref tSVector7, ref value, fP);
                            }
                            else
                            {
                                bool flag22 = flag3;
                                if (flag22)
                                {
                                    TSVector value8;
                                    TSVector value9;
                                    bool     flag23 = GJKCollide.ClosestPoints(multishape3, rigidBody2.Shape, ref rigidBody.orientation, ref rigidBody2.orientation, ref rigidBody.position, ref rigidBody2.position, out value8, out value9, out value);
                                    if (flag23)
                                    {
                                        TSVector value10 = value9 - value8;
                                        bool     flag24  = value10.sqrMagnitude < (body1.sweptDirection - body2.sweptDirection).sqrMagnitude;
                                        if (flag24)
                                        {
                                            fP = value10 * value;
                                            bool flag25 = fP < FP.Zero;
                                            if (flag25)
                                            {
                                                this.RaiseCollisionDetected(rigidBody, rigidBody2, ref value8, ref value9, ref value, fP);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        multishape3.ReturnWorkingClone();
                    }
                }
            }
        }
コード例 #3
0
        public override bool Raycast(RigidBody body, TSVector rayOrigin, TSVector rayDirection, out TSVector normal, out FP fraction)
        {
            fraction = FP.MaxValue;
            normal   = TSVector.zero;
            bool flag = !body.BoundingBox.RayIntersect(ref rayOrigin, ref rayDirection);
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                bool flag2 = body.Shape is Multishape;
                if (flag2)
                {
                    Multishape multishape = (body.Shape as Multishape).RequestWorkingClone();
                    bool       flag3      = false;
                    TSVector   tSVector;
                    TSVector.Subtract(ref rayOrigin, ref body.position, out tSVector);
                    TSVector.Transform(ref tSVector, ref body.invOrientation, out tSVector);
                    TSVector tSVector2;
                    TSVector.Transform(ref rayDirection, ref body.invOrientation, out tSVector2);
                    int num = multishape.Prepare(ref tSVector, ref tSVector2);
                    for (int i = 0; i < num; i++)
                    {
                        multishape.SetCurrentShape(i);
                        FP       fP;
                        TSVector tSVector3;
                        bool     flag4 = GJKCollide.Raycast(multishape, ref body.orientation, ref body.invOrientation, ref body.position, ref rayOrigin, ref rayDirection, out fP, out tSVector3);
                        if (flag4)
                        {
                            bool flag5 = fP < fraction;
                            if (flag5)
                            {
                                bool flag6 = this.useTerrainNormal && multishape is TerrainShape;
                                if (flag6)
                                {
                                    (multishape as TerrainShape).CollisionNormal(out tSVector3);
                                    TSVector.Transform(ref tSVector3, ref body.orientation, out tSVector3);
                                    tSVector3.Negate();
                                }
                                else
                                {
                                    bool flag7 = this.useTriangleMeshNormal && multishape is TriangleMeshShape;
                                    if (flag7)
                                    {
                                        (multishape as TriangleMeshShape).CollisionNormal(out tSVector3);
                                        TSVector.Transform(ref tSVector3, ref body.orientation, out tSVector3);
                                        tSVector3.Negate();
                                    }
                                }
                                normal   = tSVector3;
                                fraction = fP;
                                flag3    = true;
                            }
                        }
                    }
                    multishape.ReturnWorkingClone();
                    result = flag3;
                }
                else
                {
                    result = GJKCollide.Raycast(body.Shape, ref body.orientation, ref body.invOrientation, ref body.position, ref rayOrigin, ref rayDirection, out fraction, out normal);
                }
            }
            return(result);
        }