示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="lonLat"></param>
        /// <returns></returns>
        bool ScreenToSpherical(float x, float y, out DVector2 lonLat)
        {
            var w = viewportWidth;
            var h = viewportHeight;

            var nearPoint = new DVector3(x, y, frustumZNear);
            var farPoint  = new DVector3(x, y, frustumZFar);


            var vm  = DMatrix.LookAtRH(cameraPosition, DVector3.Zero, DVector3.UnitY);
            var mVP = vm * projMatrix;

            var near = DVector3.Unproject(nearPoint, 0, 0, w, h, frustumZNear, frustumZFar, mVP);
            var far  = DVector3.Unproject(farPoint, 0, 0, w, h, frustumZNear, frustumZFar, mVP);

            lonLat = DVector2.Zero;

            DVector3[] res;

            if (LineIntersection(near, far, Config.earthRadius, out res))
            {
                CartesianToSpherical(res[0], out lonLat.X, out lonLat.Y);
                return(true);
            }

            return(false);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void InputDeviceOnMouseDown(object sender, Frame.MouseEventArgs args)
        {
            if (args.Key != Keys.LeftButton)
            {
                return;
            }

            var w = viewportWidth;
            var h = viewportHeight;

            var pos = new Vector2(args.X, args.Y);

            var nearPoint = new DVector3(pos.X, pos.Y, frustumZNear);
            var farPoint  = new DVector3(pos.X, pos.Y, frustumZFar);

            var vm  = DMatrix.LookAtRH(cameraPosition, DVector3.Zero, DVector3.UnitY);
            var mVP = vm * projMatrix;

            var near = DVector3.Unproject(nearPoint, 0, 0, w, h, frustumZNear, frustumZFar, mVP);
            var far  = DVector3.Unproject(farPoint, 0, 0, w, h, frustumZNear, frustumZFar, mVP);

            DVector3[] res;

            if (LineIntersection(near, far, Config.earthRadius, out res))
            {
                if (res.Length > 0)
                {
                    double lon, lat;

                    CartesianToSpherical(res[0], out lon, out lat);

                    var lonLat = new DVector2(DMathUtil.RadiansToDegrees(lon), DMathUtil.RadiansToDegrees(lat));

                    Console.WriteLine(lonLat);
                }
            }
        }