示例#1
0
        private static bool checkCollisionCircleWithSide(CollisionInfo collision)
        {
            CollisionCircle circle = collision.obj1 as CollisionCircle;
            CollisionSide   side   = collision.obj2 as CollisionSide;

            Logger.instance.Assert(null != circle && null != side, "Collision objects incorrect data for CircleWithSide");

            if ((side.P1 - circle.Center).Dot(side.DirOut) > circle.Radius)
            {
                return(false);
            }


            double distanceToLine     = (intersectLine(circle.Center, side.P1, side.P2) - circle.Center).Length;
            double distanceToInfinity = (side.P1 - circle.Center).Dot(side.DirOut);

            if (-circle.Radius - CollisionSide.SideWidth < distanceToInfinity && distanceToInfinity < circle.Radius &&
                distanceToLine <= distanceToInfinity + 1.0e-3)
            {
                Vector collisionPoint = circle.Center + side.DirOut * distanceToInfinity;
                collision.setCollisionData(collisionPoint, side.DirOut.Negative(), side.DirOut);
                return(true);
            }

            return(false);
        }
示例#2
0
        ///Other
        private List <ICollisionObject> objectsByTilesAndEdgesInfo(Dictionary <TilePos, TileDir[]> tilesInfo)
        {
            CollisionRect carRect = new CollisionRect(car);

            List <ICollisionObject> result = new List <ICollisionObject>();

            if (null != tilesInfo)
            {
                foreach (TilePos pos in tilesInfo.Keys)
                {
                    foreach (TileDir dir in tilesInfo[pos])
                    {
                        ICollisionObject obj = null;
                        if (dir.Correct())
                        {
                            obj = new CollisionSide(pos, dir);
                        }
                        else
                        {
                            obj = new CollisionCircle(pos, dir);
                        }

                        if (null == CollisionDetector.CheckCollision(carRect, obj))
                        {
                            result.Add(obj);
                        }
                    }
                }
            }
            return(result);
        }
示例#3
0
        private static bool checkCollisionRectWithSide(CollisionInfo collision)
        {
            CollisionRect rect = collision.obj1 as CollisionRect;
            CollisionSide side = collision.obj2 as CollisionSide;

            Logger.instance.Assert(null != rect && null != side, "Collision objects incorrect data for RectWithSide");

            if ((side.P1 - rect.Center).Dot(side.DirOut) > rect.MaxRadius)
            {
                return(false);
            }

            Vector[] points = rect.Points;

            Vector[] intersects = new Vector[4] {
                intersectLine(points[0], side.P1, side.P2),
                intersectLine(points[1], side.P1, side.P2),
                intersectLine(points[2], side.P1, side.P2),
                intersectLine(points[3], side.P1, side.P2),
            };

            double[] distances = new double[4] {
                (side.P1 - points[0]).Dot(side.DirOut),
                (side.P1 - points[1]).Dot(side.DirOut),
                (side.P1 - points[2]).Dot(side.DirOut),
                (side.P1 - points[3]).Dot(side.DirOut)
            };

            for (int i = 0; i < 4; i++)
            {
                double distanceToLine = (points[i] - intersects[i]).Length;
                if (-CollisionSide.SideWidth < distances[i] && distances[i] < 0 && distanceToLine <= Math.Abs(distances[i]) + 1.0e-3)
                {
                    collision.setCollisionData(intersects[i], side.DirOut.Negative(), side.DirOut);
                    return(true);
                }
            }

            return(false);
        }