Ejemplo n.º 1
0
        public void SetViewPort(Rectanglef viewPort)
        {
            //set view port

            var viewPortF = new SharpDX.Mathematics.Interop.RawViewportF()
            {
                X        = viewPort.Left,
                Y        = viewPort.Top,
                Width    = viewPort.Right - viewPort.Left,
                Height   = viewPort.Bottom - viewPort.Top,
                MinDepth = 0.0f,
                MaxDepth = 1.0f
            };

            ImmediateContext.Rasterizer.SetViewport(viewPortF);
        }
Ejemplo n.º 2
0
        private static void CheckMovement(IEnumerable <IPhysicsEntity> list, Rectanglef startRegion, ref Vector2 movement)
        {
            foreach (var wall in list)
            {
                var endRegion = new Rectanglef(startRegion.X + movement.X, startRegion.Y + movement.Y, startRegion.Width, startRegion.Height);

                var wallReg = wall.GlobalRegion;
                if (!wallReg.Intersects(endRegion))
                {
                    continue;
                }

                movement = new Vector2(CheckRight(startRegion, endRegion, wallReg) ?? movement.X, movement.Y);
                movement = new Vector2(CheckLeft(startRegion, endRegion, wallReg) ?? movement.X, movement.Y);
                movement = new Vector2(movement.X, CheckBottom(startRegion, endRegion, wallReg) ?? movement.Y);
                movement = new Vector2(movement.X, CheckTop(startRegion, endRegion, wallReg) ?? movement.Y);
            }
        }
Ejemplo n.º 3
0
    static public bool lineseg_intersect_lineseg(LineSegf l1, LineSegf l2)
    {
        Rectanglef r1 = lineseg_box(l1);
        Rectanglef r2 = lineseg_box(l2);

        if (r1.minv.x > r2.maxv.x || r1.maxv.x < r2.minv.x ||
            r1.minv.y > r2.maxv.y || r1.maxv.y < r2.minv.y)
        {
            return(false);
        }

        float d1 = point_lineseg_side(l1.vertex0, l2);
        float d2 = point_lineseg_side(l1.vertex1, l2);
        float d3 = point_lineseg_side(l2.vertex0, l1);
        float d4 = point_lineseg_side(l2.vertex1, l1);

        if (d1 * d2 < 0 && d3 * d4 < 0)
        {
            return(true);
        }
        else if (d1 == 0 && point_in_lineseg(l1.vertex0, l2))
        {
            return(true);
        }
        else if (d2 == 0 && point_in_lineseg(l1.vertex1, l2))
        {
            return(true);
        }
        else if (d3 == 0 && point_in_lineseg(l2.vertex0, l1))
        {
            return(true);
        }
        else if (d4 == 0 && point_in_lineseg(l2.vertex1, l1))
        {
            return(true);
        }

        return(false);
    }
Ejemplo n.º 4
0
        public ConsiderSearchEnemy(Rectanglef mapSize, float raderRadius)
        {
            this.mapSize = mapSize;
            curPriority  = ConsiderPriority.Vacancy;

            int gridMaxX = (int)(mapSize.Width / raderRadius) + 1;
            int gridMaxY = (int)(mapSize.Height / raderRadius) + 1;

            grids = new float[gridMaxX, gridMaxY];
            for (int i = 0; i < gridMaxX; i++)
            {
                for (int j = 0; j < gridMaxY; j++)
                {
                    grids[i, j] = initialGridTime;
                }
            }

            gridWidth  = mapSize.Width / gridMaxX;
            gridHeight = mapSize.Height / gridMaxY;


            curTime = 0;
        }
Ejemplo n.º 5
0
        private bool PointOutBorder(Vector2 oriPosInWorld, Vector2 stepX, Vector2 stepY, Point bordPointA, Rectanglef screenRect)
        {
            Vector2 PInWorld = oriPosInWorld + bordPointA.X * stepX + bordPointA.Y * stepY;

            int xW = (int)(PInWorld.X);
            int yW = (int)(PInWorld.Y);

            if (screenRect.Contains(new Vector2(xW, yW)))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 检测是否在边界矩形外
        /// </summary>
        /// <param name="BorderRect"></param>
        /// <returns></returns>
        public CollisionResult CheckOutBorder(Rectanglef BorderRect)
        {
            if (!this.mSupportIntersectDect)
            {
                throw new Exception("the sprite doesn't support IntersectDect!");
            }

            UpdateTransformBounding();

            CollisionResult result     = new CollisionResult();
            Rectanglef      screenRect = BorderRect;


            if (!this.mBounding.Intersects(screenRect))
            {
                result.IsCollided = false;
                return(result);
            }

            int widthA  = this.mTexture.Width;
            int heightA = this.mTexture.Height;

            // Calculate a matrix which transforms from A's local space into
            // world space
            Matrix transformAToWorld = mTransform;

            Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToWorld);
            Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToWorld);

            Vector2 oriPosInWorld = Vector2.Transform(Vector2.Zero, transformAToWorld);


            CircleList <BorderPoint>     list = mBorder.BorderCircle;
            CircleListNode <BorderPoint> cur  = list.First;

            bool justStart = true;
            bool find      = false;

            CircleListNode <BorderPoint> firstNode = cur;
            int length = 0;

            #region 找出第一个相交点和该连续相交线的长度
            for (int i = 0; i < list.Length; i++)
            {
                Point bordPointA = cur.value.p;

                if (PointOutBorder(oriPosInWorld, stepX, stepY, bordPointA, screenRect))
                {
                    if (!justStart)
                    {
                        if (!find)
                        {
                            find      = true;
                            firstNode = cur;
                        }
                        else
                        {
                            length++;
                        }
                    }
                    else
                    {
                        CircleListNode <BorderPoint> temp = cur.pre;

                        int leftLength = list.Length;
                        while (PointOutBorder(oriPosInWorld, stepX, stepY, temp.value.p, screenRect) && leftLength >= 0)
                        {
                            temp = temp.pre;
                            leftLength--;
                        }
                        cur = temp;
                        i--;
                        justStart = false;
                    }
                }
                else
                {
                    justStart = false;

                    if (find)
                    {
                        break;
                    }
                }

                cur = cur.next;
            }
            #endregion

            if (find)
            {
                cur = firstNode;

                for (int i = 0; i < Math.Round((float)length / 2); i++)
                {
                    cur = cur.next;
                }

                Point bordPointA = cur.value.p;
                result.IsCollided = true;
                Vector2 InterPos = Vector2.Transform(new Vector2(bordPointA.X, bordPointA.Y), mTransform);
                result.NormalVector = Vector2.Transform(mBorder.GetNormalVector(cur, mAverageSum), mTransform)
                                      - Vector2.Transform(Vector2.Zero, mTransform);
                result.NormalVector.Normalize();
                result.InterPos = InterPos;
                return(result);
            }


            // No intersection found
            result.IsCollided = false;
            return(result);
        }
Ejemplo n.º 7
0
 public ConsiderAwayFromBorder(Rectanglef mapSize)
 {
     this.mapSize = mapSize;
     curPriority  = ConsiderPriority.Vacancy;
 }
Ejemplo n.º 8
0
 public GameObject(GraphicsDeviceManager graphics, Rectanglef rect, Texture2D texture)
 {
     this.graphics = graphics;
     this.rect     = rect;
     this.texture  = texture;
 }
Ejemplo n.º 9
0
 public AICommonServer(Rectanglef mapBorder)
 {
     this.mapBorder = mapBorder;
 }
Ejemplo n.º 10
0
 static public bool lineseg_in_rectangle(LineSegf lineseg, Rectanglef rect)
 {
     return(point_in_rectangle(lineseg.vertex0, rect) && point_in_rectangle(lineseg.vertex1, rect));
 }
Ejemplo n.º 11
0
 public NavigateMap(EyeableBorderObjInfo[] objInfos, Rectanglef mapBorder, float spaceForTank)
 {
     BuildMap(objInfos, mapBorder, spaceForTank);
 }
Ejemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="borderRect">边界矩形</param>
 public BorderColChecker(Rectanglef borderRect)
 {
     method = new BorderColMethod(borderRect);
 }
Ejemplo n.º 13
0
 public GuiCardRect(Size size)
 {
     ImageRect   = new Rectanglef(3, 3, size.Width - 3, size.Height - 3);
     BDImageRect = new Rectanglef(5, 5, size.Width - 5, size.Height - 5);
     BHRect      = new Rectanglef(0, 0, size.Width, size.Height);
 }
Ejemplo n.º 14
0
 public void SizeChange(Size size)
 {
     ImageRect   = new Rectanglef(3, 3, size.Width - 3, size.Height - 3);
     BDImageRect = new Rectanglef(5, 5, size.Width - 5, size.Height - 5);
     BHRect      = new Rectanglef(0, 0, size.Width, size.Height);
 }
Ejemplo n.º 15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="borderRect">边界矩形</param>
 public Border(Rectanglef borderRect)
 {
     this.borderRect = borderRect;
     colChecker      = new BorderChecker(borderRect);
     objInfo         = new GameObjInfo("Border", "");
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 在逻辑坐标中绘制矩形
 /// </summary>
 /// <param name="rect">要绘制的矩形</param>
 /// <param name="borderWidth">矩形的边线的宽度,以像素为单位</param>
 /// <param name="color">颜色</param>
 /// <param name="layerDepth">深度,0表示最表层,1表示最深层</param>
 public void DrawRectangle(Rectanglef rect, float borderWidth, Color color, float layerDepth)
 {
     DrawRectangle(rect, borderWidth, color, layerDepth, SpriteBlendMode.AlphaBlend);
 }
Ejemplo n.º 17
0
 public ConsiderAwayFromEnemyTurret(Rectanglef mapSize)
 {
     curPriority  = ConsiderPriority.Vacancy;
     this.mapSize = mapSize;
 }
Ejemplo n.º 18
0
 public void SetBorder(Rectanglef mapBorder)
 {
     border = new Border(mapBorder.X, mapBorder.Y, mapBorder.X + mapBorder.Width, mapBorder.Y + mapBorder.Height);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// 在调用该函数之前,确保当前帧内调用过UpdateBoundRect()函数。
 /// </summary>
 /// <param name="objBoundBox"></param>
 /// <returns></returns>
 public bool InRaderRect(Rectanglef objBoundBox)
 {
     return(bouBox.Intersects(objBoundBox));
 }
Ejemplo n.º 20
0
 public NavigateMap CalNavigateMap(NaviMapConsiderObj selectFun, Rectanglef mapBorder, float spaceForTank)
 {
     return(rader.ObjMemoryKeeper.CalNavigationMap(selectFun, mapBorder, spaceForTank));
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 将Rectanglef类型转换为Rectangle类型,进行取整操作
 /// </summary>
 /// <param name="rect"></param>
 /// <returns></returns>
 public static Rectangle RectanglefToRectangle(Rectanglef rect)
 {
     return(new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height));
 }
Ejemplo n.º 22
0
        public void BuildMap(EyeableBorderObjInfo[] objInfos, Rectanglef mapBorder, float spaceForTank)
        {
            #region 对每一个BorderObj生成逻辑坐标上的凸包点集,并向外扩展

            borderLines = new List <Segment>();

            convexs = new List <GuardConvex>();
            foreach (EyeableBorderObjInfo obj in objInfos)
            {
                if (obj.ConvexHall == null || obj.IsDisappeared || obj.ConvexHall.Points == null)
                {
                    continue;
                }

                Matrix matrix = obj.EyeableInfo.CurTransMatrix;

                GraphPoint <NaviPoint>[] convexHall;

                List <BordPoint> bordPoints = obj.ConvexHall.Points;
                if (bordPoints.Count > 2)
                {
                    List <GraphPoint <NaviPoint> > list = new List <GraphPoint <NaviPoint> >();
                    for (int i = 0; i < bordPoints.Count; i++)
                    {
                        Vector2 lastPos = Vector2.Transform(ConvertHelper.PointToVector2(bordPoints[i - 1 < 0 ? bordPoints.Count - 1 : i - 1].p), matrix);
                        Vector2 curPos  = Vector2.Transform(ConvertHelper.PointToVector2(bordPoints[i].p), matrix);
                        Vector2 nextPos = Vector2.Transform(ConvertHelper.PointToVector2(bordPoints[(i + 1) % bordPoints.Count].p), matrix);

                        Vector2 v1  = curPos - lastPos;
                        Vector2 v2  = curPos - nextPos;
                        float   ang = MathTools.AngBetweenVectors(v1, v2);
                        if (ang >= MathHelper.PiOver2)
                        {
                            float   halfDes = (float)(spaceForTank / Math.Sin(ang));
                            Vector2 delta   = halfDes * Vector2.Normalize(v1) + halfDes * Vector2.Normalize(v2);
                            list.Add(new GraphPoint <NaviPoint>(
                                         new NaviPoint(obj, bordPoints[i].index, curPos + delta), new List <GraphPath <NaviPoint> >()));
                        }
                        else
                        {
                            v1.Normalize();
                            v2.Normalize();
                            Vector2 cenV   = Vector2.Normalize(v1 + v2);
                            Vector2 vertiV = new Vector2(cenV.Y, -cenV.X);
                            float   ang2   = MathHelper.PiOver4 - 0.25f * ang;
                            float   vertiL = (float)(spaceForTank * Math.Tan(ang2));

                            list.Add(new GraphPoint <NaviPoint>(
                                         new NaviPoint(obj, bordPoints[i].index, curPos + spaceForTank * cenV + vertiL * vertiV),
                                         new List <GraphPath <NaviPoint> >()));
                            list.Add(new GraphPoint <NaviPoint>(
                                         new NaviPoint(obj, bordPoints[i].index, curPos + spaceForTank * cenV - vertiL * vertiV),
                                         new List <GraphPath <NaviPoint> >()));
                        }

                        // 添加borderLine
                        borderLines.Add(new Segment(curPos, nextPos));
                    }
                    convexHall = list.ToArray();
                    convexs.Add(new GuardConvex(convexHall));
                }
                else if (bordPoints.Count == 2)
                {
                    convexHall = new GraphPoint <NaviPoint> [4];
                    Vector2 startPos = Vector2.Transform(ConvertHelper.PointToVector2(bordPoints[0].p), matrix);
                    Vector2 endPos   = Vector2.Transform(ConvertHelper.PointToVector2(bordPoints[1].p), matrix);
                    Vector2 dir      = endPos - startPos;
                    dir.Normalize();
                    Vector2 normal = new Vector2(dir.Y, -dir.X);
                    convexHall[0] = new GraphPoint <NaviPoint>(
                        new NaviPoint(obj, bordPoints[0].index, startPos - dir * spaceForTank), new List <GraphPath <NaviPoint> >());
                    convexHall[1] = new GraphPoint <NaviPoint>(
                        new NaviPoint(obj, bordPoints[0].index, startPos + spaceForTank * normal), new List <GraphPath <NaviPoint> >());
                    convexHall[2] = new GraphPoint <NaviPoint>(
                        new NaviPoint(obj, bordPoints[1].index, endPos + spaceForTank * normal), new List <GraphPath <NaviPoint> >());
                    convexHall[3] = new GraphPoint <NaviPoint>(
                        new NaviPoint(obj, bordPoints[1].index, endPos + dir * spaceForTank), new List <GraphPath <NaviPoint> >());

                    //if (float.IsNaN( convexHall[0].value.Pos.X ) || float.IsNaN( convexHall[1].value.Pos.X ))
                    //{

                    //}

                    // 添加borderLine
                    borderLines.Add(new Segment(startPos, endPos));

                    convexs.Add(new GuardConvex(convexHall));
                }
            }

            #endregion

            #region 得到警戒线

            guardLines = new List <Segment>();

            foreach (GuardConvex convex in convexs)
            {
                for (int i = 0; i < convex.points.Length; i++)
                {
                    guardLines.Add(new Segment(convex[i].value.Pos, convex[(i + 1) % convex.Length].value.Pos));

                    //if (float.IsNaN( convex[i].value.Pos.X ))
                    //{

                    //}
                }
            }

            mapBorder = new Rectanglef(mapBorder.X + spaceForTank, mapBorder.Y + spaceForTank,
                                       mapBorder.Width - 2 * spaceForTank, mapBorder.Height - 2 * spaceForTank);

            guardLines.Add(new Segment(mapBorder.UpLeft, mapBorder.UpRight));
            guardLines.Add(new Segment(mapBorder.UpRight, mapBorder.DownRight));
            guardLines.Add(new Segment(mapBorder.DownRight, mapBorder.DownLeft));
            guardLines.Add(new Segment(mapBorder.DownLeft, mapBorder.UpLeft));

            #endregion

            #region 检查凸包内部连线是否和警戒线相交,如不相交则连接该连线并计算权值

            foreach (GuardConvex convex in convexs)
            {
                for (int i = 0; i < convex.Length; i++)
                {
                    // 检查连线是否超出边界
                    if (!mapBorder.Contains(convex[i].value.Pos))
                    {
                        continue;
                    }

                    Segment link = new Segment(convex[i].value.Pos, convex[(i + 1) % convex.Length].value.Pos);


                    bool isCross = false;
                    foreach (Segment guardLine in guardLines)
                    {
                        if (link.Equals(guardLine))
                        {
                            continue;
                        }

                        if (Segment.IsCross(link, guardLine))
                        {
                            isCross = true;
                            break;
                        }
                    }

                    if (!isCross)
                    {
                        float weight = Vector2.Distance(convex[i].value.Pos, convex[(i + 1) % convex.Length].value.Pos);
                        //if (float.IsNaN( weight ))
                        //{

                        //}
                        GraphPoint <NaviPoint> .Link(convex[i], convex[(i + 1) % convex.Length], weight);
                    }
                }
            }

            #endregion

            #region 检查凸包之间连线是否与警戒线以及边界线相交,如不相交则连接并计算权值

            for (int i = 0; i < convexs.Count - 1; i++)
            {
                for (int j = i + 1; j < convexs.Count; j++)
                {
                    foreach (GraphPoint <NaviPoint> p1 in convexs[i].points)
                    {
                        // 检查连线是否超出边界
                        if (!mapBorder.Contains(p1.value.Pos))
                        {
                            continue;
                        }

                        foreach (GraphPoint <NaviPoint> p2 in convexs[j].points)
                        {
                            Segment link = new Segment(p1.value.Pos, p2.value.Pos);

                            bool isCross = false;
                            foreach (Segment guardLine in guardLines)
                            {
                                if (Segment.IsCross(link, guardLine))
                                {
                                    isCross = true;
                                    break;
                                }
                            }
                            if (!isCross)
                            {
                                foreach (Segment borderLine in borderLines)
                                {
                                    if (Segment.IsCross(link, borderLine))
                                    {
                                        isCross = true;
                                        break;
                                    }
                                }
                            }

                            if (!isCross)
                            {
                                float weight = Vector2.Distance(p1.value.Pos, p2.value.Pos);
                                //if (float.IsNaN( weight ))
                                //{

                                //}
                                GraphPoint <NaviPoint> .Link(p1, p2, weight);
                            }
                        }
                    }
                }
            }

            #endregion

            #region 整理导航图

            List <GraphPoint <NaviPoint> > points = new List <GraphPoint <NaviPoint> >();

            foreach (GuardConvex convex in convexs)
            {
                foreach (GraphPoint <NaviPoint> p in convex.points)
                {
                    points.Add(p);
                }
            }

            naviGraph = points.ToArray();

            #endregion
        }
Ejemplo n.º 23
0
 static public bool rectangle_in_rectangle(Rectanglef rect1, Rectanglef rect2)
 {
     return(point_in_rectangle(rect1.minv, rect2) && point_in_rectangle(rect1.maxv, rect2));
 }
Ejemplo n.º 24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="borderRect">边界矩形</param>
 public BorderColMethod(Rectanglef borderRect)
 {
     this.borderRect = borderRect;
 }
Ejemplo n.º 25
0
 static public bool point_in_rectangle(Vector2f pt, Rectanglef rect)
 {
     return(pt.x >= rect.minv.x && pt.x <= rect.maxv.x && pt.y >= rect.minv.y && pt.y <= rect.maxv.y);
 }