Exemple #1
0
        /// <summary>
        ///进行射线追踪
        /// </summary>
        /// <param name="ter">地形</param>
        /// <param name="rxBall">接收球</param>
        ///  <param name="buildings">建筑物</param>
        /// <param name="rayBeamAngle">射线束的夹角</param>
        /// <returns>交点</returns>
        public List <Node> GetCrossNodes(Terrain ter, ReceiveBall rxBall, City buildings, double rayBeamAngle)
        {
            //获取左右两条射线的追踪结果
            List <Node> leftCrossNodes  = new LineRay(this.leftRay, this.leftFatherNode).GetCrossNodes(ter, rxBall, buildings, rayBeamAngle);
            List <Node> rightCrossNodes = new LineRay(this.rightRay, this.leftFatherNode).GetCrossNodes(ter, rxBall, buildings, rayBeamAngle);

            //把结果放入Dictionary中
            if (leftCrossNodes.Count == 0)
            {
                rayCrossNodes.Add(this.leftRay, null);
            }
            else
            {
                rayCrossNodes.Add(this.leftRay, leftCrossNodes[0]);
            }

            if (rightCrossNodes.Count == 0)
            {
                rayCrossNodes.Add(this.rightRay, null);
            }
            else
            {
                rayCrossNodes.Add(this.rightRay, rightCrossNodes[0]);
            }
            //
            HandleCrossNodes(this.luanchRay, this.rayCrossNodes, ter, rxBall, buildings, rayBeamAngle);
            //若射线面打到接收球上,其他交点舍去,不再追踪,同时把空的交点删去
            List <Node> crossNodes = this.rayCrossNodes.Values.ToList();

            for (int i = crossNodes.Count - 1; i >= 0; i--)
            {
                if (crossNodes[i] == null)//交点是null,删去
                {
                    crossNodes.RemoveAt(i);
                    continue;
                }
                if (crossNodes[i].NodeStyle == NodeStyle.Rx)
                {
                    return(new List <Node> {
                        crossNodes[i]
                    });
                }
            }
            return(crossNodes);
        }
Exemple #2
0
        /// <summary>
        ///在两条射线中间生成一条新的射线
        /// </summary>
        /// <param name="outRay">从射线面发出的射线</param>
        /// <param name="rayCrossNode">射线与交点的dictionary</param>
        /// <param name="ter">地形</param>
        /// <param name="rxBall">接收球</param>
        ///  <param name="buildings">建筑物</param>
        /// <param name="rayBeamAngle">射线束的夹角</param>
        /// <returns></returns>
        private void SetNewMiddleRay(List <RayInfo> outRay, Dictionary <RayInfo, Node> rayCrossNode, Terrain ter, ReceiveBall rxBall, City buildings, double rayBeamAngle, ref int i)
        {
            Point       lineMiddlePoint = rayCrossNode[outRay[i]].Position.GetMiddlePointInTwoPoints(rayCrossNode[outRay[i + 1]].Position);
            RayInfo     newRay          = new RayInfo(this.launchPoint, lineMiddlePoint);
            Node        lineNode        = this.GetLineNode(newRay);
            List <Node> newCrossNode    = new LineRay(newRay, lineNode).GetCrossNodes(ter, rxBall, buildings, rayBeamAngle);

            if (newCrossNode.Count == 0)
            {
                rayCrossNode.Add(newRay, null);
            }
            else
            {
                rayCrossNode.Add(newRay, newCrossNode[0]);
                this.lineNodes.Add(newCrossNode[0], lineNode);
            }
            outRay.Insert(i + 1, newRay);
            i--;
        }