Exemplo n.º 1
0
        private void prepareTrain(CSubPath navPath, int fromIndex = 0)
        {
            mTopSpeed = Math.Max(0, Math.Min(Math.Pow(2, CGisDataSettings.AppSpeed) * 20, 350));

            double[][] mm, mx, my, mz, md;
            mx = new double[5][];
            my = new double[5][];
            mz = new double[5][];
            md = new double[5][];
            mm = new double[5][];
            double[] ms = { 0, 37, 86, 135, 172 };

            fromIndex = Math.Max(fromIndex, 0);
            fromIndex = Math.Min(fromIndex, navPath.mPointCount - 3);


            for (int i = 0; i < mDynamicTrain.Length; i++)
            {
                // 由起始计算路径
                if (fromIndex == 0)
                {
                    mDistoNext = navPath.mLength;
                    ModelInfo.Helper.CSubLine.getSubLineByMileage(-ms[i], navPath.mLength - ms[i], mStepm / 2, navPath.mm, navPath.mx, navPath.my, navPath.mz, navPath.md,
                                                                  out mm[i], out mx[i], out my[i], out mz[i], out md[i], true);
                }
                else // 由中途计算路径
                {
                    mDistoNext = rm.Last() - rm[fromIndex];
                    ModelInfo.Helper.CSubLine.getSubLineByMileage(rm[fromIndex] - ms[i], rm.Last() - ms[i], mStepm / 2, rm, rx, ry, rz, rd,
                                                                  out mm[i], out mx[i], out my[i], out mz[i], out md[i], true);
                }
            }

            mTrainWayPointTotal = mm[0].Length;
            mTrainWayPointCount = 0;

            rm = new double[mTrainWayPointTotal];
            rx = new double[mTrainWayPointTotal];
            ry = new double[mTrainWayPointTotal];
            rz = new double[mTrainWayPointTotal];
            rd = new double[mTrainWayPointTotal];
            mm[0].CopyTo(rm, 0);
            mx[0].CopyTo(rx, 0);
            my[0].CopyTo(ry, 0);
            mz[0].CopyTo(rz, 0);
            md[0].CopyTo(rd, 0);
            //mDynamicTrain.Acceleration = 1;
            double localspeed;

            for (int j = 0; j < mDynamicTrain.Length; j++)
            {
                for (int i = 0; i < mTrainWayPointTotal; i++)
                {
#if DEBUG
                    //Console.WriteLine(curIndex + "\t" + mx[i] + "\t" + my[i] + "\t" + mz[i] + "\t" + md[i]);
                    //ModelInfo.Helper.LogHelper.WriteLog(curIndex + "\t" + mx[i] + "\t" + my[i] + "\t" + mz[i] + "\t" + md[i]);
                    mDynamicTrain[j].Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(mx[j][i], my[j][i], mz[j][i], mTopSpeed, md[j][i]));
#else
                    // 逐渐加速,减速
                    localspeed = Math.Min(5 + (mTrainWayPointTotal - Math.Abs(mTrainWayPointTotal - i / 2)) * 10, mTopSpeed);
                    mDynamicTrain[j].Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(mx[j][i], my[j][i], mz[j][i], localspeed, md[j][i]));
#endif
                }

                mDynamicTrain[j].CircularRoute = false;
                mDynamicTrain[j].Pause         = false;
                mDynamicTrain[j].RestartRoute();
            }
            for (int i = 0; i < mTrainWayPointTotal; i++)
            {
                mVirtualObj.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(mx[4][i], my[4][i], mz[4][i] + 20, mTopSpeed, md[4][i]));
            }
            mVirtualWayPointCount     = mTrainWayPointTotal;
            mVirtualObj.CircularRoute = false;
            mVirtualObj.Pause         = false;
            mVirtualObj.RestartRoute();
            //mVirtualObj.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(fromX, fromY, fromZ + 150, speed));
            //mVirtualObj.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(midx, midy, midz + 150, speed));
            //mVirtualObj.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(mNavigationList[mNavNextIndex].Longitude, mNavigationList[mNavNextIndex].Latitude, mNavigationList[mNavNextIndex].Altitude + 150, speed));


            //if (mTrainWayPointTotal  < 15)
            //{
            //    sgworld.Navigate.FlyTo(mDynamicTrain[0], ActionCode.AC_FOLLOWBEHINDANDABOVE);
            //}
            //else
            //    sgworld.Navigate.FlyTo(mDynamicTrain[0], ActionCode.AC_FOLLOWCOCKPIT);
            if (mTrainWayPointTotal < 15)
            {
                sgworld.Navigate.FlyTo(mVirtualObj, ActionCode.AC_FOLLOWBEHINDANDABOVE);
            }
            else
            {
                sgworld.Navigate.FlyTo(mVirtualObj, ActionCode.AC_FOLLOWCOCKPIT);
            }
        }
Exemplo n.º 2
0
        public bool startNextPresentation()
        {
            bool fromCurrent = true;

            if (mNavigationList == null || mNavigationList.Count == 0)
            {
                return(false);
            }

            readyForNext = false;

            // 屏幕中心坐标
            IPosition66 cp = sgworld.Window.CenterPixelToWorld().Position;
            // 视点坐标
            IPosition66 viewp = sgworld.Navigate.GetPosition(AltitudeTypeCode.ATC_TERRAIN_RELATIVE);

            //起点与目标点距离
            double len1 = mNavigationList[mNavIndex].getUTMDistance(cp.X, cp.Y) + viewp.Altitude;

            //如果漫游起点距离屏幕中心过远,从当前点漫游到起点
            double fromX, fromY, fromZ;

            //if (mRan.Next(1,20) == 10)
            //{
            //    fromX = 118.6;
            //    fromY = 36.6;
            //    fromZ = 400000;
            //    fromCurrent = false;

            //}
            //else
            if (len1 > 5000)
            {
                fromX       = cp.X;
                fromY       = cp.Y;
                fromZ       = viewp.Altitude;
                fromCurrent = false;
            }
            else  //否则从极点到下一点
            {
                fromX = mNavigationList[mNavIndex].Longitude;
                fromY = mNavigationList[mNavIndex].Latitude;
                fromZ = mNavigationList[mNavIndex].Altitude;
            }

            double length = mNavigationList[mNavNextIndex].getUTMDistance(fromX, fromY);

#if DEBUG
            Console.WriteLine(mNavNextIndex + " 目的地 " + mNavigationList[mNavNextIndex].ToString());
#endif
            if (length < 50)
            {
                ReachOnePlace();
                return(true);
            }

            mTopSpeed = Math.Max(0, Math.Min(Math.Pow(2, CGisDataSettings.AppSpeed) * 20, 350));
            double speed = Math.Min(length / 3.5, mTopSpeed);

            clearTrain();

            isOnOneWay   = true;
            mVirtualOnly = false;

            if (!fromCurrent || length > 30000)
            {
                double x, y;

                x = (fromX + mNavigationList[mNavNextIndex].Longitude) / 2;
                y = (fromY + mNavigationList[mNavNextIndex].Latitude) / 2;
                for (int i = mPresentation.Steps.Count - 1; i >= 0; i--)
                {
                    mPresentation.DeleteStep(i);
                }

                mPresentation.CreateLocationStep(PresentationStepContinue.PSC_WAIT, 1, "Starting",
                                                 sgworld.Creator.CreatePosition(fromX, fromY, 0, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, -89, 0, Math.Max(350, fromZ)));

                // 如果距离过长,先到世界中心,再到当前工点
                mPresentation.CreateCaptionStep(PresentationStepContinue.PSC_WAIT, 0, "Txt", "开始漫游", 3);
                if (length > 60000)
                {
                    mPresentation.CreateLocationStep(PresentationStepContinue.PSC_WAIT, 1, "Ending",
                                                     sgworld.Creator.CreatePosition(118.6, 36.6, 0, AltitudeTypeCode.ATC_TERRAIN_RELATIVE,
                                                                                    341, -90.0, 0, 445000));
                }
                else
                {
                    mPresentation.CreateLocationStep(PresentationStepContinue.PSC_WAIT, 1, "Ending",
                                                     sgworld.Creator.CreatePosition(x, y, 0, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, -89, 0, Math.Max(length, 5000)));
                }
                mPresentation.CreateLocationStep(PresentationStepContinue.PSC_WAIT, 1, "Ended",
                                                 sgworld.Creator.CreatePosition(mNavigationList[mNavNextIndex].Longitude, mNavigationList[mNavNextIndex].Latitude, 350, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, -89, 0, 0));

                updatePresentationSpeed(mPresentation);

                mPresentation.Play(0);
                //mVirtualObj.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(mPlaceList[nextIndex].Longitude, mPlaceList[nextIndex].Latitude, mPlaceList[nextIndex].Altitude + 150));

                return(true);
            }
            //isPresentation = true;

            //sgworld.OnObjectAction += Sgworld_OnObjectAction;

            mStepm   = length < 250 ? length / 5 : speed;
            mNavPath = new CSubPath(CRailwayLineList.gRealConnection, mNavigationList[mNavIndex].DKCode, mNavigationList[mNavIndex].Mileage,
                                    mNavigationList[mNavNextIndex].DKCode, mNavigationList[mNavNextIndex].Mileage, 10);

            if (!mNavPath.hasPath)
            {
                // 如果没有路径,直接飞过去
                double midx, midy, midz;
                midx = (fromX + mNavigationList[mNavNextIndex].Longitude) / 2;
                midy = (fromY + mNavigationList[mNavNextIndex].Latitude) / 2;
                midz = (fromZ + mNavigationList[mNavNextIndex].Altitude) / 2;
                mVirtualWayPointCount = 3;
                mVirtualObj.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(fromX, fromY, fromZ + 150, speed));
                mVirtualObj.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(midx, midy, midz + 150, speed));
                mVirtualObj.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(mNavigationList[mNavNextIndex].Longitude, mNavigationList[mNavNextIndex].Latitude, mNavigationList[mNavNextIndex].Altitude + 150, speed));
#if DEBUG
                ModelInfo.Helper.LogHelper.WriteLog(mNavIndex + "\t" + midx + "\t" + midy + "\t" + midz);
#endif
                mVirtualOnly = true;
                mVirtualObj.CircularRoute = false;
                mVirtualObj.Pause         = false;
                mVirtualObj.RestartRoute();
                sgworld.Navigate.FlyTo(mVirtualObj, ActionCode.AC_FOLLOWABOVE);
                // ReachOnePlace();
                return(true);
            }

            panelInfo.Visible = true;
            prepareTrain(mNavPath, 0);
//            double[][] mm,mx, my, mz, md;
//            mx = new double[5][];
//            my = new double[5][];
//            mz = new double[5][];
//            md = new double[5][];
//            mm = new double[5][];
//            double[] ms = { 0, 37, 86, 135, 172 };
//            //mx[0] = mNavPath.mx;
//            //my[0] = mNavPath.my;
//            //mz[0] = mNavPath.mz;
//            //md[0] = mNavPath.md;
//            mTrainWayPointTotal = mTrainWayPointCount = mNavPath.mPointCount;
//            mDistoNext = mNavPath.mLength;
//            for (int i = 0; i< 5; i++)
//            {
//                ModelInfo.Helper.CSubLine.getSubLineByMileage(-ms[i], mNavPath.mLength-ms[i], mStepm, mNavPath.mm, mNavPath.mx, mNavPath.my, mNavPath.mz, mNavPath.md,
//                    out mm[i], out mx[i], out my[i], out mz[i], out md[i], true);

//            }

//            //mDynamicTrain.Acceleration = 1;
//            double localspeed;
//            for (int j = 0; j < 5; j++)
//            {
//                for (int i = 0; i < mTrainWayPointCount; i++)
//                {
//                    // 逐渐加速,减速
//                    localspeed = Math.Min(5 + (mTrainWayPointCount - Math.Abs(mTrainWayPointCount - i / 2)) * 10, speed);
//#if DEBUG
//                    //Console.WriteLine(curIndex + "\t" + mx[i] + "\t" + my[i] + "\t" + mz[i] + "\t" + md[i]);
//                    //ModelInfo.Helper.LogHelper.WriteLog(curIndex + "\t" + mx[i] + "\t" + my[i] + "\t" + mz[i] + "\t" + md[i]);
//                    mDynamicTrain[j].Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(mx[j][i], my[j][i], mz[j][i], speed, md[j][i]));
//#else
//                mDynamicTrain.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(mx[j][i], my[j][i], mz[j][i], localspeed, md[j][i]));
//#endif
//                }

//                mDynamicTrain[j].CircularRoute = false;
//                mDynamicTrain[j].Pause = false;
//                mDynamicTrain[j].RestartRoute();
//            }
//            if (mTrainWayPointTotal < 15)
//            {
//                sgworld.Navigate.FlyTo(mDynamicTrain[0], ActionCode.AC_FOLLOWBEHINDANDABOVE);
//            }
//            else
//                sgworld.Navigate.FlyTo(mDynamicTrain[0], ActionCode.AC_FOLLOWCOCKPIT);


            return(true);
        }