示例#1
0
        public static void GetLocation(float radius, ref Vector3 vertexCoordinate, out Orientation orientation)
        {
            orientation = new Orientation();
            //Set up the base vertex
            //Suppose the vertex(0,0) is (startLongitude, 0N): 0N is definitely true;
            float startLongitude = -90;

            //Calculate Latitude: + N; - S
            orientation.latitude = MathHelper.RadiansToDegrees((float) Math.Asin(vertexCoordinate.Y/radius));
            //Calculate Longitude: x + (30E,180E,150W); x- W; z + (0+30 ; z- 180
            //x^2+z^2
            float currentRadius =
                (float) Math.Sqrt(vertexCoordinate.X*vertexCoordinate.X + vertexCoordinate.Z*vertexCoordinate.Z);
            orientation.longitude = (vertexCoordinate.Z >= 0)
                                        ? (360 +
                                           MathHelper.RadiansToDegrees(
                                               (float) Math.Asin(vertexCoordinate.X/currentRadius)) + startLongitude)%
                                          360
                                        : 180 -
                                          MathHelper.RadiansToDegrees(
                                              (float) Math.Asin(vertexCoordinate.X/currentRadius)) + startLongitude;
        }
示例#2
0
        bool LocationFromScreen(int x, int y, out Orientation orient)
        {
            Vector3 vectorOut;//=new Vector3();
            orient = new Orientation();
            var vectorIn = new Vector3(x, glControl1.Height - y, 0);
            Glu.UnProject(vectorIn, _viewmodelMatrix, _projectionMatrix, _viewportMatrix, out vectorOut);
            float radius = _earth.Radius;
            double sum = radius * radius - vectorOut.X * vectorOut.X - vectorOut.Y * vectorOut.Y;
            if (sum >= 0)
            {
                vectorOut.Z = (float)Math.Sqrt(sum);
                Matrix4 earthVert = Matrix4.Invert(FloatToMatrix4(_earthViewMatrix));
                Vector3 newVec = Vector3.Transform(vectorOut, earthVert);

                Earth.GetLocation(radius, ref newVec, out orient);
                _fonts.Text = orient + "  " + vectorOut;

            }
            else
            {
                _fonts.Text = vectorIn + "  " + "Out of the sphere";
                return false;
            }
            //vectorOut.X = vectorOut.X / radius;
            //vectorOut.Y = vectorOut.Y / radius;
            //vectorOut.Z = vectorOut.Z / radius;
            return true;
        }
示例#3
0
        //Transform orientation in Earth to position to draw terrain
        Vector3 GetTerrainPosition(Orientation orient)
        {
            Vector3 vec, winVec, winLocation;
            Earth.GetPosition(_earth.Radius, ref orient, out vec);
            Vector3 vec1 = Vector3.Transform(vec, FloatToMatrix4(_earthViewMatrix));// + "  " + newVec.ToString()

            Glu.Project(vec1, _viewmodelMatrix, _projectionMatrix, _viewportMatrix, out winVec);
            winVec.Z = 0.99f; //Depth in projection view
            Glu.UnProject(winVec, _viewmodelMatrix, _terrainProjectionMatrix, _viewportMatrix, out winLocation);
            return winLocation;
        }
示例#4
0
        /// <summary>
        /// Get vertexPosition on the Earth
        /// </summary>
        /// <param name="radius"></param>
        /// <param name="orientation"></param>
        /// <param name="vertexCoordinate"></param>
        public static void GetPosition(float radius, ref Orientation orientation, out Vector3 vertexCoordinate)
        {
            vertexCoordinate = new Vector3();
            //Set up the base vertex
            //Suppose the vertex(0,0) is (startLongitude, 0N): 0N is definitely true;
            float startLongitude = -90;
            float bigSin = (float) Math.Sin(MathHelper.DegreesToRadians(orientation.latitude));
            vertexCoordinate.Y = bigSin*radius;

            float currentRadius = radius*(float) Math.Sqrt(1 - bigSin*bigSin);
            float theta = orientation.longitude - startLongitude;
            float smallSin = (float) Math.Sin(MathHelper.DegreesToRadians(theta));
            vertexCoordinate.X = smallSin*currentRadius;
            vertexCoordinate.Z = -currentRadius*(float) Math.Sqrt(1 - smallSin*smallSin);
        }