//--------------------------------------------------------------------------------------------------------- //from:起点;to:终点;waypoint:所有视线途经位点 public LOS_RESULT LOS_Test(Vector2 from, Vector2 to, out List <WayPoint> waypoint) { Belong_Status ret; Debug.WriteLine("----------------------------------------------------"); //////////////////////////////////////////////////////////////////////////////////////// Polygon dstpoly; Debug.Write("(目标) "); ret = RelaxPostion(ref to, out dstpoly); //松弛目标点 if (ret != Belong_Status.Polygon || !dstpoly.enterable) { waypoint = null; return(LOS_RESULT.FAILED); //目标点不合法 } int dstidx = dstpoly.idx; //关键!目标点所处的多边形 //////////////////////////////////////////////////////////////////////////////////////// Polygon srcpoly; Debug.Write("(源点) "); ret = RelaxPostion(ref from, out srcpoly); //松弛源点 if (ret != Belong_Status.Polygon || !srcpoly.enterable) { waypoint = null; return(LOS_RESULT.FAILED); //源点不合法 } //////////////////////////////////////////////////////////////////////////////////////// w = new List <WayPoint>(); w.Add(new WayPoint(from, -1)); //这是对的! PrintDebugPosition(-1, from); //////////////////////////////////////////////////////////////////////////////////////// Vector2 n0 = to - from; n0.Normalize(); //////////////////////////////////////////////////////////////////////////////////////// LOS_RESULT los = LOS_RESULT.FAILED; if (!FloatEqual(n0.LengthSq(), 0)) //from/to两点不容许重合 { Debug.Assert(ret == Belong_Status.Polygon); los = StartLOS_P(n0, from, srcpoly, dstidx); //此刻from在srcpoly内部 } if (los == LOS_RESULT.CLEAR) { w.Add(new WayPoint(to, dstidx)); PrintDebugPosition(dstidx, to); } Debug.WriteLine(string.Format("({0}) 共计 {1} 个位点", los.ToString(), w.Count)); Debug.WriteLine("----------------------------------------------------"); waypoint = w; return(los); }