Exemplo n.º 1
0
        protected virtual void CreateMesh(GeographicBoundingBox geographicBoundingBox, int meshPointCount, ref CustomVertex.PositionColoredTextured[] vertices, ref short[] indices)
        {
            int    upperBound  = meshPointCount - 1;
            float  scaleFactor = (float)1 / upperBound;
            double latrange    = Math.Abs(geographicBoundingBox.North - geographicBoundingBox.South);
            double lonrange;

            if (geographicBoundingBox.West < geographicBoundingBox.East)
            {
                lonrange = geographicBoundingBox.East - geographicBoundingBox.West;
            }
            else
            {
                lonrange = 360.0f + geographicBoundingBox.East - geographicBoundingBox.West;
            }

            double layerRadius = this.m_parentProjectedLayer.World.EquatorialRadius;

            int opacityColor = Color.FromArgb(
                //m_parentProjectedLayer.Opacity,
                0, 0, 0).ToArgb();

            vertices = new CustomVertex.PositionColoredTextured[meshPointCount * meshPointCount];
            for (int i = 0; i < meshPointCount; i++)
            {
                for (int j = 0; j < meshPointCount; j++)
                {
                    double height = 0;
                    if (this.m_parentProjectedLayer.World.TerrainAccessor != null)
                    {
                        height = this.m_verticalExaggeration * this.m_parentProjectedLayer.World.TerrainAccessor.GetElevationAt(
                            (double)geographicBoundingBox.North - scaleFactor * latrange * i,
                            (double)geographicBoundingBox.West + scaleFactor * lonrange * j,
                            (double)upperBound / latrange);
                    }

                    Vector3 pos = MathEngine.SphericalToCartesian(
                        geographicBoundingBox.North - scaleFactor * latrange * i,
                        geographicBoundingBox.West + scaleFactor * lonrange * j,
                        layerRadius + height);

                    vertices[i * meshPointCount + j].X = pos.X;
                    vertices[i * meshPointCount + j].Y = pos.Y;
                    vertices[i * meshPointCount + j].Z = pos.Z;

                    vertices[i * meshPointCount + j].Tu    = j * scaleFactor;
                    vertices[i * meshPointCount + j].Tv    = i * scaleFactor;
                    vertices[i * meshPointCount + j].Color = opacityColor;
                }
            }

            indices = new short[2 * upperBound * upperBound * 3];
            for (int i = 0; i < upperBound; i++)
            {
                for (int j = 0; j < upperBound; j++)
                {
                    indices[(2 * 3 * i * upperBound) + 6 * j]     = (short)(i * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 1] = (short)((i + 1) * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 2] = (short)(i * meshPointCount + j + 1);

                    indices[(2 * 3 * i * upperBound) + 6 * j + 3] = (short)(i * meshPointCount + j + 1);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 4] = (short)((i + 1) * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 5] = (short)((i + 1) * meshPointCount + j + 1);
                }
            }
        }
Exemplo n.º 2
0
        public void Update(DrawArgs drawArgs)
        {
            try
            {
                double centerLatitude  = 0.5 * (this.m_geographicBoundingBox.North + this.m_geographicBoundingBox.South);
                double centerLongitude = 0.5 * (this.m_geographicBoundingBox.West + this.m_geographicBoundingBox.East);
                double tileSize        = this.m_geographicBoundingBox.North - this.m_geographicBoundingBox.South;

                if (!this.m_Initialized)
                {
                    if (drawArgs.WorldCamera.ViewRange * 0.5f < Angle.FromDegrees(ShapeTileArgs.TileDrawDistance * tileSize) &&
                        MathEngine.SphericalDistance(Angle.FromDegrees(centerLatitude), Angle.FromDegrees(centerLongitude),
                                                     drawArgs.WorldCamera.Latitude, drawArgs.WorldCamera.Longitude) < Angle.FromDegrees(ShapeTileArgs.TileSpreadFactor * tileSize * 1.25f) &&
                        drawArgs.WorldCamera.ViewFrustum.Intersects(this.BoundingBox)
                        )
                    {
                        this.Initialize(drawArgs);
                    }
                }

                if (this.m_Initialized)
                {
                    if (this.m_LastUpdate < this.m_parentProjectedLayer.LastUpdate)
                    {
                        this.UpdateImageLayers(drawArgs);
                    }

                    if (this.m_NwImageLayer != null)
                    {
                        this.m_NwImageLayer.Update(drawArgs);
                    }
                    if (this.m_NeImageLayer != null)
                    {
                        this.m_NeImageLayer.Update(drawArgs);
                    }
                    if (this.m_SwImageLayer != null)
                    {
                        this.m_SwImageLayer.Update(drawArgs);
                    }
                    if (this.m_SeImageLayer != null)
                    {
                        this.m_SeImageLayer.Update(drawArgs);
                    }

                    if (
                        drawArgs.WorldCamera.ViewRange < Angle.FromDegrees(ShapeTileArgs.TileDrawDistance * tileSize) &&
                        MathEngine.SphericalDistance(Angle.FromDegrees(centerLatitude), Angle.FromDegrees(centerLongitude),
                                                     drawArgs.WorldCamera.Latitude, drawArgs.WorldCamera.Longitude) < Angle.FromDegrees(ShapeTileArgs.TileSpreadFactor * tileSize) &&
                        drawArgs.WorldCamera.ViewFrustum.Intersects(this.BoundingBox)
                        )
                    {
                        if (this.m_NorthEastChild == null && this.m_NorthWestChild == null && this.m_SouthEastChild == null && this.m_SouthWestChild == null)
                        {
                            this.ComputeChildren(drawArgs);
                        }
                        else
                        {
                            if (this.m_NorthEastChild != null)
                            {
                                this.m_NorthEastChild.Update(drawArgs);
                            }

                            if (this.m_NorthWestChild != null)
                            {
                                this.m_NorthWestChild.Update(drawArgs);
                            }

                            if (this.m_SouthEastChild != null)
                            {
                                this.m_SouthEastChild.Update(drawArgs);
                            }

                            if (this.m_SouthWestChild != null)
                            {
                                this.m_SouthWestChild.Update(drawArgs);
                            }
                        }
                    }
                    else
                    {
                        if (this.m_NorthWestChild != null)
                        {
                            this.m_NorthWestChild.Dispose();
                            this.m_NorthWestChild = null;
                        }

                        if (this.m_NorthEastChild != null)
                        {
                            this.m_NorthEastChild.Dispose();
                            this.m_NorthEastChild = null;
                        }

                        if (this.m_SouthEastChild != null)
                        {
                            this.m_SouthEastChild.Dispose();
                            this.m_SouthEastChild = null;
                        }

                        if (this.m_SouthWestChild != null)
                        {
                            this.m_SouthWestChild.Dispose();
                            this.m_SouthWestChild = null;
                        }
                    }
                }

                if (this.m_Initialized)
                {
                    if (drawArgs.WorldCamera.ViewRange > Angle.FromDegrees(ShapeTileArgs.TileDrawDistance * tileSize * 1.5f) ||
                        MathEngine.SphericalDistance(Angle.FromDegrees(centerLatitude), Angle.FromDegrees(centerLongitude), drawArgs.WorldCamera.Latitude, drawArgs.WorldCamera.Longitude) > Angle.FromDegrees(ShapeTileArgs.TileSpreadFactor * tileSize * 1.5f))
                    {
                        if (this.Level != 0)
                        {
                            //{
                            this.Dispose();
                        }
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Exemplo n.º 3
0
        private void UpdateTexturedVertices()
        {
            if (m_altitudeMode == AltitudeMode.ClampedToGround)
            {
                if (m_lineString != null)
                {
                    m_lineString.Remove = true;
                    m_lineString        = null;
                }

                m_lineString                  = new LineString();
                m_lineString.Coordinates      = Points;
                m_lineString.Color            = LineColor;
                m_lineString.LineWidth        = LineWidth;
                m_lineString.ParentRenderable = this;
                this.World.ProjectedVectorRenderer.Add(m_lineString);

                if (m_wallVertices != null)
                {
                    m_wallVertices = null;
                }

                return;
            }

            if (m_extrude || m_altitudeMode == AltitudeMode.RelativeToGround)
            {
                m_wallVertices = new CustomVertex.PositionColoredTextured[m_numPoints * 2];
            }

            float textureCoordIncrement = 1.0f / (float)(m_numPoints - 1);

            m_verticalExaggeration = World.Settings.VerticalExaggeration;
            int vertexColor = m_polygonColor.ToArgb();

            m_topVertices = new CustomVertex.PositionColored[m_numPoints];

            for (int i = 0; i < m_numPoints; i++)
            {
                double terrainHeight = 0;
                if (m_altitudeMode == AltitudeMode.RelativeToGround)
                {
                    if (World.TerrainAccessor != null)
                    {
                        terrainHeight = World.TerrainAccessor.GetElevationAt(
                            m_points[i].Y,
                            m_points[i].X,
                            (100.0 / DrawArgs.Camera.ViewRange.Degrees)
                            );
                    }
                }

                Vector3 xyzVertex = MathEngine.SphericalToCartesian(
                    m_points[i].Y,
                    m_points[i].X,
                    m_verticalExaggeration * (m_distanceAboveSurface + terrainHeight + m_points[i].Z) + World.EquatorialRadius
                    );

                m_topVertices[i].X     = xyzVertex.X;
                m_topVertices[i].Y     = xyzVertex.Y;
                m_topVertices[i].Z     = xyzVertex.Z;
                m_topVertices[i].Color = m_lineColor.ToArgb();

                if (m_extrude || m_altitudeMode == AltitudeMode.RelativeToGround)
                {
                    m_wallVertices[2 * i].X     = xyzVertex.X;
                    m_wallVertices[2 * i].Y     = xyzVertex.Y;
                    m_wallVertices[2 * i].Z     = xyzVertex.Z;
                    m_wallVertices[2 * i].Color = vertexColor;
                    m_wallVertices[2 * i].Tu    = i * textureCoordIncrement;
                    m_wallVertices[2 * i].Tv    = 1.0f;

                    xyzVertex = MathEngine.SphericalToCartesian(
                        m_points[i].Y,
                        m_points[i].X,
                        m_verticalExaggeration * (m_distanceAboveSurface + terrainHeight) + World.EquatorialRadius
                        );

                    m_wallVertices[2 * i + 1].X     = xyzVertex.X;
                    m_wallVertices[2 * i + 1].Y     = xyzVertex.Y;
                    m_wallVertices[2 * i + 1].Z     = xyzVertex.Z;
                    m_wallVertices[2 * i + 1].Color = vertexColor;
                    m_wallVertices[2 * i + 1].Tu    = i * textureCoordIncrement;
                    m_wallVertices[2 * i + 1].Tv    = 0.0f;
                }
            }
        }