Пример #1
0
        private void UpdateVertices()
        {
            m_verticalExaggeration = World.Settings.VerticalExaggeration;

            CPoint2D[] polygonVertices = new CPoint2D[m_polygonPoints.Length];
            for (int i = 0; i < polygonVertices.Length; i++)
            {
                polygonVertices[i] = new CPoint2D(m_polygonPoints[i].X, m_polygonPoints[i].Y);
            }

            CPolygonShape cutPolygon = new CPolygonShape(polygonVertices);

            cutPolygon.CutEar();

            ArrayList vertexList = new ArrayList();

            for (int i = 0; i < cutPolygon.NumberOfPolygons; i++)
            {
                int nPoints = cutPolygon.Polygons(i).Length;

                for (int j = 0; j < nPoints; j++)
                {
                    Point3d point = new Point3d(cutPolygon.Polygons(i)[j].X, cutPolygon.Polygons(i)[j].Y, 0);

                    foreach (Point3d sourcePoint in m_polygonPoints)
                    {
                        if (sourcePoint.X.Equals(point.X) &&
                            sourcePoint.Y.Equals(point.Y))
                        {
                            point.Z = sourcePoint.Z;
                            break;
                        }
                    }

                    vertexList.Add(point);
                }
            }

            if (m_extrudeHeight > 0)
            {
                CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[vertexList.Count * 2];
                int polygonColor = Color.FromArgb(Opacity, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();
                int vertexOffset = vertices.Length / 2;

                // build bottom vertices
                for (int i = 0; i < vertices.Length / 2; i++)
                {
                    Point3d sphericalPoint = (Point3d)vertexList[i];
                    Vector3 xyzVector      = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration * (sphericalPoint.Z + m_distanceAboveSurface));

                    vertices[i].Color = polygonColor;
                    vertices[i].X     = xyzVector.X;
                    vertices[i].Y     = xyzVector.Y;
                    vertices[i].Z     = xyzVector.Z;
                }

                //build top vertices
                for (int i = vertexOffset; i < vertices.Length; i++)
                {
                    Point3d sphericalPoint = (Point3d)vertexList[i - vertexOffset];
                    Vector3 xyzVector      = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration * (sphericalPoint.Z + m_distanceAboveSurface + m_extrudeHeight));

                    vertices[i].Color = polygonColor;
                    vertices[i].X     = xyzVector.X;
                    vertices[i].Y     = xyzVector.Y;
                    vertices[i].Z     = xyzVector.Z;
                }

                m_vertices = vertices;
            }
            else
            {
                CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[vertexList.Count];
                int polygonColor = Color.FromArgb(Opacity, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();

                for (int i = 0; i < vertices.Length; i++)
                {
                    Point3d sphericalPoint = (Point3d)vertexList[i];
                    Vector3 xyzVector      = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration * (sphericalPoint.Z + m_distanceAboveSurface));

                    vertices[i].Color = polygonColor;
                    vertices[i].X     = xyzVector.X;
                    vertices[i].Y     = xyzVector.Y;
                    vertices[i].Z     = xyzVector.Z;
                }

                m_vertices = vertices;
            }

            if (m_extrudeHeight > 0 || m_outline)
            {
                Point3d[] linePoints = new Point3d[m_polygonPoints.Length + 1];
                for (int i = 0; i < m_polygonPoints.Length; i++)
                {
                    linePoints[i] = m_polygonPoints[i];
                }

                linePoints[linePoints.Length - 1] = m_polygonPoints[0];

                m_lineFeature = new LineFeature(Name, World, linePoints, m_polygonColor);
                m_lineFeature.ExtrudeHeight          = m_extrudeHeight;
                m_lineFeature.DistanceAboveSurface   = m_distanceAboveSurface;
                m_lineFeature.ExtrudeUpwards         = m_extrudeUpwards;
                m_lineFeature.MinimumDisplayAltitude = m_minimumDisplayAltitude;
                m_lineFeature.MaximumDisplayAltitude = m_maximumDisplayAltitude;
                m_lineFeature.Opacity      = Opacity;
                m_lineFeature.Outline      = m_outline;
                m_lineFeature.OutlineColor = m_outlineColor;
            }
            else
            {
                if (m_lineFeature != null)
                {
                    m_lineFeature.Dispose();
                    m_lineFeature = null;
                }
            }
        }
Пример #2
0
        private static void addLineFeature(XPathNodeIterator iter, World parentWorld, RenderableObjectList parentRenderable)
        {
            if (iter.Count > 0) {
                while (iter.MoveNext()) {
                    string name = getInnerTextFromFirstChild(iter.Current.Select("Name"));

                    string distanceAboveSurfaceString = getInnerTextFromFirstChild(iter.Current.Select("DistanceAboveSurface"));
                    string minimumDisplayAltitudeString = getInnerTextFromFirstChild(iter.Current.Select("MinimumDisplayAltitude"));
                    string maximumDisplayAltitudeString = getInnerTextFromFirstChild(iter.Current.Select("MaximumDisplayAltitude"));
                    string opacityString = getInnerTextFromFirstChild(iter.Current.Select("Opacity"));
                    string extrudeHeightString = getInnerTextFromFirstChild(iter.Current.Select("ExtrudeHeight"));
                    string extrudeUpwardsString = getInnerTextFromFirstChild(iter.Current.Select("ExtrudeUpwards"));
                    string imageUri = getInnerTextFromFirstChild(iter.Current.Select("ImageUri"));
                    string outlineString = getInnerTextFromFirstChild(iter.Current.Select("Outline"));

                    XPathNodeIterator posListIter = iter.Current.Select("LineString/posList");
                    posListIter.MoveNext();

                    string lineString = getInnerTextFromFirstChild(posListIter);

                    string[] lineParts = lineString.Split(' ');
                    Point3d[] points = new Point3d[lineParts.Length];

                    for (int i = 0; i < lineParts.Length; i++) {
                        string[] pointParts = lineParts[i].Split(',');
                        points[i] = new Point3d();
                        points[i].X = ParseDouble(pointParts[0]);
                        points[i].Y = ParseDouble(pointParts[1]);

                        if (pointParts.Length > 2) {
                            points[i].Z = ParseDouble(pointParts[2]);
                        }
                    }

                    Color c = Color.Black;
                    Color outlineColor = Color.Black;

                    if (iter.Current.Select("RGBColor").Count > 0) {
                        c = getColor(iter.Current.Select("RGBColor"));
                    }

                    if (iter.Current.Select("FeatureColor").Count > 0) {
                        c = getColor(iter.Current.Select("FeatureColor"));
                    }

                    if (iter.Current.Select("OutlineColor").Count > 0) {
                        outlineColor = getColor(iter.Current.Select("OutlineColor"));
                    }

                    LineFeature lf = null;

                    if (imageUri != null
                        && imageUri.Length > 0) {
                        lf = new LineFeature(name, parentWorld, points, imageUri);
                    }
                    else {
                        lf = new LineFeature(name, parentWorld, points, c);
                    }

                    lf.OutlineColor = outlineColor;

                    if (outlineString != null
                        && outlineString.Length > 0) {
                        lf.Outline = ParseBool(outlineString);
                    }

                    if (extrudeHeightString != null
                        && extrudeHeightString.Length > 0) {
                        lf.ExtrudeHeight = ParseDouble(extrudeHeightString);
                    }

                    if (opacityString != null
                        && opacityString.Length > 0) {
                        lf.Opacity = byte.Parse(opacityString);
                    }

                    if (distanceAboveSurfaceString != null
                        && distanceAboveSurfaceString.Length > 0) {
                        lf.DistanceAboveSurface = ParseDouble(distanceAboveSurfaceString);
                    }

                    if (minimumDisplayAltitudeString != null
                        && minimumDisplayAltitudeString.Length > 0) {
                        lf.MinimumDisplayAltitude = ParseDouble(minimumDisplayAltitudeString);
                    }

                    if (maximumDisplayAltitudeString != null
                        && maximumDisplayAltitudeString.Length > 0) {
                        lf.MaximumDisplayAltitude = ParseDouble(maximumDisplayAltitudeString);
                    }

                    if (extrudeUpwardsString != null
                        && extrudeUpwardsString.Length > 0) {
                        lf.ExtrudeUpwards = ParseBool(extrudeUpwardsString);
                    }

                    addExtendedInformation(iter.Current.Select("ExtendedInformation"), lf);

                    string infoUri = iter.Current.GetAttribute("InfoUri", "");

                    if (infoUri != null
                        && infoUri.Length > 0) {
                        if (lf.MetaData.Contains("InfoUri")) {
                            lf.MetaData["InfoUri"] = infoUri;
                        }
                        else {
                            lf.MetaData.Add("InfoUri", infoUri);
                        }
                    }

                    lf.MetaData.Add("XmlSource", (string) parentRenderable.MetaData["XmlSource"]);
                    lf.ParentList = parentRenderable;

                    if (World.Settings.useDefaultLayerStates) {
                        lf.IsOn = ParseBool(iter.Current.GetAttribute("ShowAtStartup", ""));
                    }
                    else {
                        lf.IsOn = IsLayerOn(lf);
                    }
                    parentRenderable.ChildObjects.Add(lf);

                    parentRenderable.RenderPriority = RenderPriority.LinePaths;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Helper class that updates history trail and model position
        /// </summary>
        protected virtual void updateSubObjects()
        {
            if (IsSurfaceTrack)
            {
                Altitude = 0;
                IsAGL    = true; // force this just in case so we aren't under terrain
            }

            // Save current values
            PosData pos = new PosData();

            pos.lat        = Latitude;
            pos.lon        = Longitude;
            pos.alt        = Altitude;
            pos.spd        = Speed;
            pos.hdg        = Rotation.Degrees;
            pos.sourceTime = m_sourceTime;
            pos.updateTime = m_updateTime;

            try
            {
                m_history.AddFirst(pos);

                if (m_history.Count > MaxPoints)
                {
                    m_history.RemoveLast();
                }

                // Add to line feature
                if (RenderTrail && m_lineFeature == null)
                {
                    m_lineFeature           = new LineFeature(name + "_trail", DrawArgs.CurrentWorldStatic, null, null);
                    m_lineFeature.LineColor = System.Drawing.Color.White;
                    m_lineFeature.MaxPoints = MaxPoints;

                    if (IsAGL)
                    {
                        m_lineFeature.AltitudeMode = AltitudeMode.RelativeToGround;
                    }
                    else
                    {
                        m_lineFeature.AltitudeMode = AltitudeMode.Absolute;
                    }

                    m_lineFeature.Opacity   = 128;
                    m_lineFeature.LineWidth = 3;

                    if (IsSurfaceTrack)
                    {
                        m_lineFeature.Extrude       = false;
                        m_lineFeature.ExtrudeHeight = 0;
                        m_lineFeature.LineWidth     = 1;
                    }
                    else
                    {
                        m_lineFeature.Extrude         = true;
                        m_lineFeature.ExtrudeHeight   = 1;
                        m_lineFeature.LineWidth       = 1;
                        m_lineFeature.ExtrudeToGround = false;
                    }
                }

                if (RenderTrail)
                {
                    m_lineFeature.AddPoint(Longitude, Latitude, Altitude);
                }

                if (RenderModel && m_modelFeature != null)
                {
                    m_modelFeature.Longitude = (float)Longitude;
                    m_modelFeature.Latitude  = (float)Latitude;
                    m_modelFeature.Altitude  = (float)Altitude;

                    float rot = (float)(180 - Rotation.Degrees);
                    if (rot < 0)
                    {
                        rot += 360;
                    }
                    m_modelFeature.RotZ = rot;
                }
            }
            catch
            {
            }
        }
Пример #4
0
        private void UpdateVertices()
        {
            m_verticalExaggeration = World.Settings.VerticalExaggeration;

            CPoint2D[] polygonVertices = new CPoint2D[m_polygonPoints.Length];
            for (int i = 0; i < polygonVertices.Length; i++) {
                polygonVertices[i] = new CPoint2D(m_polygonPoints[i].X, m_polygonPoints[i].Y);
            }

            CPolygonShape cutPolygon = new CPolygonShape(polygonVertices);
            cutPolygon.CutEar();

            ArrayList vertexList = new ArrayList();

            for (int i = 0; i < cutPolygon.NumberOfPolygons; i++) {
                int nPoints = cutPolygon.Polygons(i).Length;

                for (int j = 0; j < nPoints; j++) {
                    Point3d point = new Point3d(cutPolygon.Polygons(i)[j].X, cutPolygon.Polygons(i)[j].Y, 0);

                    foreach (Point3d sourcePoint in m_polygonPoints) {
                        if (sourcePoint.X.Equals(point.X)
                            && sourcePoint.Y.Equals(point.Y)) {
                            point.Z = sourcePoint.Z;
                            break;
                        }
                    }

                    vertexList.Add(point);
                }
            }

            if (m_extrudeHeight > 0) {
                CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[vertexList.Count*2];
                int polygonColor = Color.FromArgb(Opacity, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();
                int vertexOffset = vertices.Length/2;

                // build bottom vertices
                for (int i = 0; i < vertices.Length/2; i++) {
                    Point3d sphericalPoint = (Point3d) vertexList[i];
                    Vector3 xyzVector = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration*(sphericalPoint.Z + m_distanceAboveSurface));

                    vertices[i].Color = polygonColor;
                    vertices[i].X = xyzVector.X;
                    vertices[i].Y = xyzVector.Y;
                    vertices[i].Z = xyzVector.Z;
                }

                //build top vertices
                for (int i = vertexOffset; i < vertices.Length; i++) {
                    Point3d sphericalPoint = (Point3d) vertexList[i - vertexOffset];
                    Vector3 xyzVector = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration*(sphericalPoint.Z + m_distanceAboveSurface + m_extrudeHeight));

                    vertices[i].Color = polygonColor;
                    vertices[i].X = xyzVector.X;
                    vertices[i].Y = xyzVector.Y;
                    vertices[i].Z = xyzVector.Z;
                }

                m_vertices = vertices;
            }
            else {
                CustomVertex.PositionNormalColored[] vertices = new CustomVertex.PositionNormalColored[vertexList.Count];
                int polygonColor = Color.FromArgb(Opacity, m_polygonColor.R, m_polygonColor.G, m_polygonColor.B).ToArgb();

                for (int i = 0; i < vertices.Length; i++) {
                    Point3d sphericalPoint = (Point3d) vertexList[i];
                    Vector3 xyzVector = MathEngine.SphericalToCartesian(sphericalPoint.Y, sphericalPoint.X, World.EquatorialRadius + m_verticalExaggeration*(sphericalPoint.Z + m_distanceAboveSurface));

                    vertices[i].Color = polygonColor;
                    vertices[i].X = xyzVector.X;
                    vertices[i].Y = xyzVector.Y;
                    vertices[i].Z = xyzVector.Z;
                }

                m_vertices = vertices;
            }

            if (m_extrudeHeight > 0 || m_outline) {
                Point3d[] linePoints = new Point3d[m_polygonPoints.Length + 1];
                for (int i = 0; i < m_polygonPoints.Length; i++) {
                    linePoints[i] = m_polygonPoints[i];
                }

                linePoints[linePoints.Length - 1] = m_polygonPoints[0];

                m_lineFeature = new LineFeature(Name, World, linePoints, m_polygonColor);
                m_lineFeature.ExtrudeHeight = m_extrudeHeight;
                m_lineFeature.DistanceAboveSurface = m_distanceAboveSurface;
                m_lineFeature.ExtrudeUpwards = m_extrudeUpwards;
                m_lineFeature.MinimumDisplayAltitude = m_minimumDisplayAltitude;
                m_lineFeature.MaximumDisplayAltitude = m_maximumDisplayAltitude;
                m_lineFeature.Opacity = Opacity;
                m_lineFeature.Outline = m_outline;
                m_lineFeature.OutlineColor = m_outlineColor;
            }
            else {
                if (m_lineFeature != null) {
                    m_lineFeature.Dispose();
                    m_lineFeature = null;
                }
            }
        }