Exemple #1
0
        /// <summary>
        /// Initializes the transforms used for the 3D model.
        /// </summary>
        private void InitializeTransform()
        {
            this.Scene = new VikingXNA.Scene(Device.Viewport, this.Camera);

            // Use the world matrix to tilt the cube along x and y axes.
            //            worldMatrix = Matrix.Identity; // CreateRotationX(_CameraTilt) * Matrix.CreateRotationZ(_CameraPan);

              //          projectionMatrix = Matrix.CreateOrthographic((float)ProjectedArea.Width, (float)ProjectedArea.Height, MinDrawDistance, MaxDrawDistance);
        }
Exemple #2
0
 /// <summary>
 /// Draws the volume using the bounds and downsample onto the renderTarget.  If renderTarget is null the scene is drawn to the display
 /// </summary>
 /// <param name="graphicsDevice"></param>
 /// <param name="Bounds"></param>
 /// <param name="DownSample"></param>
 /// <param name="renderTarget"></param>
 protected virtual void Draw(Scene scene)
 {
 }
Exemple #3
0
        protected void UpdateSceneViewport(Scene scene)
        {
            Microsoft.Xna.Framework.Rectangle ClientBounds = new Microsoft.Xna.Framework.Rectangle(0,
                                                                                                   0,
                                                                                                   ClientRectangle.Width,
                                                                                                   ClientRectangle.Height);

            if (ClientBounds.Height == 0 || ClientBounds.Width == 0)
            {
                return;
            }

            if (Device == null)
            {
                return;
            }
            //Figure out how much we have to scale the downsample to keep the same scene in view if minimizing

            Viewport viewport = Device.Viewport;
            if (Device != null)
            {
                    this.Downsample = Downsample * (((double)viewport.Width * (double)viewport.Height) / ((double)ClientBounds.Width * (double)ClientBounds.Height));

                    if (viewport.Width != ClientBounds.Width ||
                        viewport.Height != ClientBounds.Height)
                    {
                        this.graphicsDeviceService.ResetDevice(ClientRectangle.Width, ClientRectangle.Height);
                    }
            }

            // this.GraphicsDevice.Viewport.Width = ClientSize.Width;
            // GraphicsDevice.Viewport.Height = ClientSize.Height;

            //Trace.WriteLine("Projection Bounds: " + ProjRect.ToString() + " Client Rect: " + ClientRectangle.ToString());

            scene.Viewport = Device.Viewport;
        }
Exemple #4
0
        protected void Draw(Scene drawnScene, RenderTarget2D renderTarget)
        {
            Device.SetRenderTarget(renderTarget);
            try
            {
                Device.Viewport = drawnScene.Viewport;
            }
            catch (ArgumentException)
            {
                UpdateSceneViewport(drawnScene);
                Device.Viewport = drawnScene.Viewport;

            }

            annotationOverlayEffect.RenderTargetSize = drawnScene.Viewport;

            #if DEBUG
            if (renderTarget != null)
            {
                Debug.Assert(renderTarget.Bounds.Width >= drawnScene.Viewport.Width &&
                             renderTarget.Bounds.Height >= drawnScene.Viewport.Height);

            }
            #endif

            if (DefaultDepthState == null || DefaultDepthState.IsDisposed)
            {
                DefaultDepthState = new DepthStencilState();

                DefaultDepthState.DepthBufferEnable = true;
                DefaultDepthState.DepthBufferFunction = CompareFunction.LessEqual;
                DefaultDepthState.StencilEnable = false;
                DefaultDepthState.DepthBufferWriteEnable = true;
            }

            Device.DepthStencilState = DefaultDepthState;

            if (DefaultBlendState == null || DefaultBlendState.IsDisposed)
            {
                DefaultBlendState = new BlendState();
                DefaultBlendState.AlphaSourceBlend = Blend.SourceAlpha;
                DefaultBlendState.AlphaDestinationBlend = Blend.InverseSourceAlpha;
                DefaultBlendState.ColorSourceBlend = Blend.SourceAlpha;
                DefaultBlendState.ColorDestinationBlend = Blend.InverseSourceAlpha;
            }

            Device.BlendState = DefaultBlendState;

            SamplerState sampleState = Device.SamplerStates[0];

            if (sampleState == null || sampleState.IsDisposed ||
                (sampleState.AddressU != TextureAddressMode.Clamp || sampleState.AddressV != TextureAddressMode.Clamp))
            {
                try
                {
                    sampleState = new SamplerState();
                    sampleState.AddressU = TextureAddressMode.Clamp;    //Compatability with Reach
                    sampleState.AddressV = TextureAddressMode.Clamp;
                    Device.SamplerStates[0] = sampleState;
                }
                catch (Exception)
                {
                    if (sampleState != null)
                    {
                        sampleState.Dispose();
                        sampleState = null;
                    }
                }
            }

            Device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, float.MaxValue, 0);

            if (Device.RasterizerState == null ||
                Device.RasterizerState.IsDisposed ||
                Device.RasterizerState.CullMode != CullMode.None)
            {
                RasterizerState rState = null;
                try
                {
                    rState = new RasterizerState();
                    rState.CullMode = CullMode.None;
                    Device.RasterizerState = rState;
                }
                catch (Exception)
                {
                    if (rState != null)
                    {
                        rState.Dispose();
                        rState = null;
                    }
                }
            }

            Matrix worldViewProj = drawnScene.WorldViewProj;

            //Enables some basic effect characteristics, such as vertex coloring and default lighting.
            basicEffect.Projection = drawnScene.Projection;
            basicEffect.View = drawnScene.Camera.View;
            basicEffect.World = drawnScene.World;

            tileLayoutEffect.WorldViewProjMatrix = worldViewProj;
            this.channelOverlayEffect.WorldViewProjMatrix = worldViewProj;
            this.mergeHSVImagesEffect.WorldViewProjMatrix = worldViewProj;
            this.annotationOverlayEffect.WorldViewProjMatrix = worldViewProj;

            if (this.spriteBatch == null || this.spriteBatch.GraphicsDevice.IsDisposed)
            {
                IGraphicsDeviceService IService = this.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
                if (IService != null)
                {
                    spriteBatch = new SpriteBatch(IService.GraphicsDevice);
                    fontArial = Content.Load<SpriteFont>(@"Arial");
                }
            }

            //            GridRectangle Bounds = VisibleBounds();

            #if !DEBUG
            try
            {
            #endif
                //Since draw can be called from other methods than paint calls,
                //such as screencaptures, increment the PaintCallRefCount here
                PaintCallRefCount++;

                // Draw the control using the GraphicsDevice.
                Draw(drawnScene);
            #if !DEBUG
            }
            catch (Exception except)
            {
                throw except;
            }
            finally
            {
            #endif
                PaintCallRefCount--;
            #if !DEBUG
            }
            #endif
        }