public WorldSurfaceRenderer(uint samplesPerTile, double distanceAboveSeaLevel, World parentWorld)
        {
            m_SamplesPerTile = samplesPerTile;
            m_ParentWorld = parentWorld;
            m_DistanceAboveSeaLevel = distanceAboveSeaLevel;

            double tileSize = 180.0f/m_NumberRootTilesHigh;

            m_RootSurfaceTiles = new SurfaceTile[m_NumberRootTilesHigh*(m_NumberRootTilesHigh*2)];
            for (int i = 0; i < m_NumberRootTilesHigh; i++) {
                for (int j = 0; j < m_NumberRootTilesHigh*2; j++) {
                    m_RootSurfaceTiles[i*m_NumberRootTilesHigh*2 + j] = new SurfaceTile((i + 1)*tileSize - 90.0f, i*tileSize - 90.0f, j*tileSize - 180.0f, (j + 1)*tileSize - 180.0f, 0, this);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates the specified draw args.
        /// </summary>
        /// <param name="drawArgs">Draw args.</param>
        public void Update(DrawArgs drawArgs)
        {
            try {
                if (!m_Initialized) {
                    Initialize(drawArgs);
                }

                float scaleFactor = 1f/(m_ParentWorldSurfaceRenderer.SamplesPerTile);
                float latrange = (float) Math.Abs(m_North - m_South);
                float lonrange = (float) Math.Abs(m_East - m_West);

                int thisVertexDensityElevatedPlus3 = ((int) m_ParentWorldSurfaceRenderer.SamplesPerTile/2 + 3);

                scaleFactor = (float) 1/(m_ParentWorldSurfaceRenderer.SamplesPerTile);
                latrange = (float) Math.Abs(m_North - m_South);
                lonrange = (float) Math.Abs(m_East - m_West);

                double centerLatitude = 0.5*(m_North + m_South);
                double centerLongitude = 0.5*(m_East + m_West);
                double tileSize = (m_North - m_South);

                if (m_VerticalExaggeration != World.Settings.VerticalExaggeration) {
                    //	buildTerrainMesh();
                }

                if (drawArgs.WorldCamera.TrueViewRange < Angle.FromDegrees(3.0f*tileSize) && MathEngine.SphericalDistance(Angle.FromDegrees(centerLatitude), Angle.FromDegrees(centerLongitude), drawArgs.WorldCamera.Latitude, drawArgs.WorldCamera.Longitude) < Angle.FromDegrees(2.9f*tileSize)
                    && drawArgs.WorldCamera.ViewFrustum.Intersects(m_BoundingBox)) {
                    if (m_NorthWestChild == null || m_NorthEastChild == null || m_SouthWestChild == null
                        || m_SouthEastChild == null) {
                        ComputeChildrenTiles(drawArgs);
                    }
                    else {
                        if (m_NorthEastChild != null) {
                            m_NorthEastChild.Update(drawArgs);
                        }
                        if (m_NorthWestChild != null) {
                            m_NorthWestChild.Update(drawArgs);
                        }
                        if (m_SouthEastChild != null) {
                            m_SouthEastChild.Update(drawArgs);
                        }
                        if (m_SouthWestChild != null) {
                            m_SouthWestChild.Update(drawArgs);
                        }
                    }
                }
                else {
                    if (m_NorthWestChild != null) {
                        m_NorthWestChild.Dispose();
                        m_NorthWestChild = null;
                    }

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

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

                    if (m_SouthWestChild != null) {
                        m_SouthWestChild.Dispose();
                        m_SouthWestChild = null;
                    }
                }
            }
            catch (ThreadAbortException) {}
            catch (Exception ex) {
                Log.Write(ex);
            }
        }
Beispiel #3
0
        private void ComputeChildrenTiles(DrawArgs drawArgs)
        {
            if (m_NorthWestChild == null) {
                SurfaceTile nwc = new SurfaceTile(m_North, 0.5f*(m_South + m_North), m_West, 0.5f*(m_West + m_East), m_Level + 1, m_ParentWorldSurfaceRenderer);

                nwc.Initialize(drawArgs);
                m_NorthWestChild = nwc;
            }

            if (m_NorthEastChild == null) {
                SurfaceTile nec = new SurfaceTile(m_North, 0.5f*(m_South + m_North), 0.5f*(m_West + m_East), m_East, m_Level + 1, m_ParentWorldSurfaceRenderer);

                nec.Initialize(drawArgs);
                m_NorthEastChild = nec;
            }

            if (m_SouthWestChild == null) {
                SurfaceTile swc = new SurfaceTile(0.5f*(m_South + m_North), m_South, m_West, 0.5f*(m_West + m_East), m_Level + 1, m_ParentWorldSurfaceRenderer);

                swc.Initialize(drawArgs);
                m_SouthWestChild = swc;
            }

            if (m_SouthEastChild == null) {
                SurfaceTile sec = new SurfaceTile(0.5f*(m_South + m_North), m_South, 0.5f*(m_West + m_East), m_East, m_Level + 1, m_ParentWorldSurfaceRenderer);

                sec.Initialize(drawArgs);
                m_SouthEastChild = sec;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Disposes this instance. Releases any resources from the graphics device, also disposes of "child" surface tiles.
        /// </summary>
        public void Dispose()
        {
            m_Initialized = false;
            m_BoundingBox = null;

            if (m_Device != null) {
                m_Device.DeviceReset -= new EventHandler(OnDeviceReset);
                m_Device.Disposing -= new EventHandler(OnDeviceDispose);

                OnDeviceDispose(m_Device, null);
            }

            if (m_NorthWestChild != null) {
                m_NorthWestChild.Dispose();
                m_NorthWestChild = null;
            }
            if (m_NorthEastChild != null) {
                m_NorthEastChild.Dispose();
                m_NorthEastChild = null;
            }
            if (m_SouthWestChild != null) {
                m_SouthWestChild.Dispose();
                m_SouthWestChild = null;
            }
            if (m_SouthEastChild != null) {
                m_SouthEastChild.Dispose();
                m_SouthEastChild = null;
            }
        }