Beispiel #1
0
 // Load WorldSettings to form controls
 private void InitForm()
 {
     suspendEvents         = true;
     chkSunShading.Checked = World.Settings.EnableSunShading;
     chkSunFixed.Checked   = !World.Settings.SunSynchedWithTime;
     tbSunHeading.Value    = (int)MathEngine.RadiansToDegrees(World.Settings.SunHeading);
     tbSunElevation.Value  = (int)MathEngine.RadiansToDegrees(World.Settings.SunElevation);
     this.btnLightColorPicker.BackColor = World.Settings.LightColor;
     this.btnShadeColorPicker.BackColor = World.Settings.ShadingAmbientColor;
     suspendEvents = false;
     FormChanged(null, null);
 }
Beispiel #2
0
            public LightDialog(string Name)
            {
                InitializeComponent();
                this.Text = Name;

                // Backup some values if we want to be able to cancel changes
                EnableSunShadingBack   = World.Settings.EnableSunShading;
                SunSynchedWithTimeBack = World.Settings.SunSynchedWithTime;
                SunHeadingBack         = World.Settings.SunHeading;
                SunElevationBack       = World.Settings.SunElevation;
                // Init form values
                suspendEvents         = true;
                chkSunShading.Checked = World.Settings.EnableSunShading;
                chkSunFixed.Checked   = !World.Settings.SunSynchedWithTime;
                tbSunHeading.Value    = (int)MathEngine.RadiansToDegrees(World.Settings.SunHeading);
                tbSunElevation.Value  = (int)MathEngine.RadiansToDegrees(World.Settings.SunElevation);
                suspendEvents         = false;
            }
Beispiel #3
0
 public void UpdateTerrainElevation(TerrainAccessor terrainAccessor)
 {
     // Update camera terrain elevation
     if (terrainAccessor != null)
     {
         if (Altitude < 300000)
         {
             if (System.DateTime.Now - this.lastElevationUpdate > TimeSpan.FromMilliseconds(500))
             {
                 float elevation;
                 // Under camera target
                 elevation        = terrainAccessor.GetCachedElevationAt(Latitude.Degrees, Longitude.Degrees);
                 TerrainElevation = float.IsNaN(elevation) ? (short)0 : (short)elevation;
                 // Under the camera itself
                 Vector3 cameraPos   = Position;
                 Vector3 cameraCoord = MathEngine.CartesianToSpherical(cameraPos.X, cameraPos.Y, cameraPos.Z);
                 double  camLat      = MathEngine.RadiansToDegrees(cameraCoord.Y);
                 double  camLon      = MathEngine.RadiansToDegrees(cameraCoord.Z);
                 elevation = terrainAccessor.GetCachedElevationAt(camLat, camLon);
                 TerrainElevationUnderCamera = float.IsNaN(elevation) ? (short)0 : (short)elevation;
                 if (TerrainElevationUnderCamera < 0 && !World.Settings.AllowNegativeAltitude)
                 {
                     TerrainElevationUnderCamera = 0;
                 }
                 // reset timer
                 this.lastElevationUpdate = System.DateTime.Now;
             }
         }
         else
         {
             TerrainElevation            = 0;
             TerrainElevationUnderCamera = 0;
         }
     }
     else
     {
         TerrainElevation            = 0;
         TerrainElevationUnderCamera = 0;
     }
 }
Beispiel #4
0
        /// <summary>
        /// This is where we do our rendering
        /// Called from UI thread = UI code safe in this function
        /// </summary>
        public override void Render(DrawArgs drawArgs)
        {
            if (!isInitialized)
            {
                return;
            }

            // Camera & Device shortcuts ;)
            CameraBase camera = drawArgs.WorldCamera;
            Device     device = drawArgs.device;

            if (camera.Altitude > 1000e3)
            {
                return;
            }

            //double halfView = 0.5* camera.TrueViewRange.Degrees;
            double halfView = 90D - MathEngine.RadiansToDegrees(Math.Asin(camera.WorldRadius / (camera.Altitude + camera.WorldRadius)));

            double west  = camera.Longitude.Degrees - halfView;
            double east  = camera.Longitude.Degrees + halfView;
            double north = camera.Latitude.Degrees + halfView;
            double south = camera.Latitude.Degrees - halfView;

            float radius = (float)(camera.WorldRadius + FloodElevation * World.Settings.VerticalExaggeration);

            this.Name = "Flood level: " + ConvertUnits.GetDisplayString(FloodElevation);

            if (floodMesh != null)
            {
                floodMesh.Dispose();
            }
            floodMesh = MakeFloodMesh(device, radius, west, north, east, south, FloodColor);

            // Lighting setup (specular...)
            SetupLights(drawArgs);

            // save world and projection transform
            Matrix origWorld      = device.Transform.World;
            Matrix origProjection = device.Transform.Projection;

            // Save fog status
            bool origFog = device.RenderState.FogEnable;

            device.RenderState.FogEnable = false;

            // WW 1.4 Camera jitter fix (recenter)
            drawArgs.device.Transform.World = Matrix.Translation(
                (float)-drawArgs.WorldCamera.ReferenceCenter.X,
                (float)-drawArgs.WorldCamera.ReferenceCenter.Y,
                (float)-drawArgs.WorldCamera.ReferenceCenter.Z
                );


            // draw mesh
            device.SetTexture(0, null);
            device.VertexFormat = CustomVertex.PositionNormalColored.Format;
            device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
            device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
            device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
            device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;

            floodMesh.DrawSubset(0);

            // Restore device states
            device.Transform.World       = origWorld;
            device.Transform.Projection  = origProjection;
            device.RenderState.FogEnable = origFog;
        }