void DrawingSurfaceLoaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (GraphicsDeviceManager.Current.RenderMode != RenderMode.Hardware)
                {
                    if (GraphicsDeviceManager.Current.RenderModeReason == RenderModeReason.SecurityBlocked)
                    {
                        throw new SecurityException();
                    }
                }

                if (!contentLoaded)
                {
                    Earth.LoadContent();
                    Sun.LoadContent();
                    contentLoaded = true;
                }
            }
            catch (Exception)
            {
                MessageBox.Show(@"Could not initialize the 3D rendering. Please ensure 3D rendering is allowed.

1. Right click on your Silverlight plugin.
2. Go to the permissions tab.
3. Find the domain that hosts the XAP file.
4. Mark the XAP-Domain and click Allow.");
            }
        }
        void DrawingSurfaceDraw(object sender, DrawEventArgs e)
        {
            try
            {
                var scaledDeltaSeconds = e.DeltaTime.TotalSeconds * rotationSpeed;
                totalElapsedTime += TimeSpan.FromSeconds(scaledDeltaSeconds);

                GraphicsDeviceManager.Current.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, TransparentColor, 1.0f, 0);

                Sun.Draw(GraphicsDeviceManager.Current.GraphicsDevice, totalElapsedTime, camera);
                Earth.LightPosition = Sun.Position;
                Earth.Draw(GraphicsDeviceManager.Current.GraphicsDevice, totalElapsedTime, camera);

                e.InvalidateSurface();
            }
            catch (Exception)
            {
                MessageBox.Show(@"Could not initialize the 3D rendering. Please ensure 3D rendering is allowed.

1. Right click on your Silverlight plugin.
2. Go to the permissions tab.
3. Find the domain that hosts the XAP file.
4. Mark the XAP-Domain and click Allow.");
            }
        }
      public MainPage()
      {
         InitializeComponent();

         totalElapsedTime = TimeSpan.FromSeconds(0.0);
         rotationSpeed = 2.0;

         // Create camera and models
         camera = new Camera((float)ds.Width / (float)ds.Height);
         Earth = new Earth();
         Sun = new Sun { IsVisible = false, Transform = Matrix.CreateTranslation(-4, 0, 0) };

         DataContext = this;
      }
        public MainPage()
        {
            InitializeComponent();

            totalElapsedTime = TimeSpan.FromSeconds(0.0);
            rotationSpeed    = 2.0;

            // Create camera and models
            camera = new Camera((float)ds.Width / (float)ds.Height);
            Earth  = new Earth();
            Sun    = new Sun {
                IsVisible = false, Transform = Matrix.CreateTranslation(-4, 0, 0)
            };

            DataContext = this;
        }