private void RenderToViewport(Microsoft.DirectX.Direct3D.Viewport viewport, Color color, int flip)
 {
     device.Viewport = viewport;
     device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, color, 1.0f, 0);
     device.BeginScene();
     device.Transform.View  = Matrix.Identity;
     device.Transform.World = Matrix.RotationYawPitchRoll(
         Geometry.DegreeToRadian((spinX + angle) * flip),
         Geometry.DegreeToRadian((spinY + angle) * flip),
         0.0f)
                              * Matrix.Translation(0.0f, 0.0f, 5.0f);
     device.Material = teapotMaterial;
     teapotMesh.DrawSubset(0);
     device.EndScene();
 }
示例#2
0
        public PanelSceneRegion(int x1, int y1, int x2, int y2, Scene scene)
        {
            _client_area.X      = x1;
            _client_area.Y      = y1;
            _client_area.Width  = x2 - x1;
            _client_area.Height = y2 - y1;

            _scene = scene;

            view        = new Viewport();
            view.X      = _client_area.X;
            view.Y      = _client_area.Y;
            view.Height = _client_area.Height;
            view.Width  = _client_area.Width;

            _Sticky = true;
        }
示例#3
0
        public override void OnRender(Canvas c)
        {
            Microsoft.DirectX.Direct3D.Viewport backup = c.Viewport;

            view.X      = _client_area.X;
            view.Y      = _client_area.Y;
            view.Height = _client_area.Height;
            view.Width  = _client_area.Width;

            c.Viewport = this.view;
            c.ClearDevice(Microsoft.DirectX.Direct3D.ClearFlags.Target, Color.Black, 0, 0);

            _scene.OnRender(c);

            c.Viewport = backup;
            if (Selected)
            {
                DrawBoundingBox(c);
            }
        }
        public void Render()
        {
            //create the bottom left viewport
            Microsoft.DirectX.Direct3D.Viewport bottomLeftViewport = new Microsoft.DirectX.Direct3D.Viewport();
            bottomLeftViewport.X      = 0;
            bottomLeftViewport.Y      = 0;
            bottomLeftViewport.Width  = this.ClientSize.Width / 2;
            bottomLeftViewport.Height = this.ClientSize.Height / 2;


            //create the bottom right viewport
            Microsoft.DirectX.Direct3D.Viewport bottomRightViewport = new Microsoft.DirectX.Direct3D.Viewport();
            bottomRightViewport.X      = this.ClientSize.Width / 2;
            bottomRightViewport.Y      = 0;
            bottomRightViewport.Width  = this.ClientSize.Width / 2;
            bottomRightViewport.Height = this.ClientSize.Height / 2;

            //create the top left viewport
            Microsoft.DirectX.Direct3D.Viewport topLeftViewport = new Microsoft.DirectX.Direct3D.Viewport();
            topLeftViewport.X      = 0;
            topLeftViewport.Y      = this.ClientSize.Height / 2;
            topLeftViewport.Width  = this.ClientSize.Width / 2;
            topLeftViewport.Height = this.ClientSize.Height / 2;

            //create the top right viewport
            Microsoft.DirectX.Direct3D.Viewport topRightViewport = new Microsoft.DirectX.Direct3D.Viewport();
            topRightViewport.X      = this.ClientSize.Width / 2;
            topRightViewport.Y      = this.ClientSize.Height / 2;
            topRightViewport.Width  = this.ClientSize.Width / 2;
            topRightViewport.Height = this.ClientSize.Height / 2;

            RenderToViewport(bottomLeftViewport, Color.FromArgb(255, 255, 0, 0), 1);
            RenderToViewport(bottomRightViewport, Color.FromArgb(255, 0, 255, 0), -1);
            RenderToViewport(topLeftViewport, Color.FromArgb(255, 0, 0, 255), -5);
            RenderToViewport(topRightViewport, Color.FromArgb(255, 100, 100, 100), 25);
            angle += 0.1f;

            //Copy the back buffer to the display
            device.Present();
        }
示例#5
0
 protected void StartViewport(Canvas c)
 {
     backup = c.Viewport;
     c.Viewport = PanelViewport;
 }
示例#6
0
 /// <summary>
 /// This might not make sense, revisit.
 /// </summary>
 /// <param name="c"></param>
 /// <param name="r"></param>
 protected void StartViewport(Canvas c, Rectangle r)
 {
     backup = c.Viewport;
     SetViewportDimensions(r);
     c.Viewport = PanelViewport;
 }
示例#7
0
 public PanelViewportRegion()
 {
     view = new Viewport();
     
 }
示例#8
0
 protected void StartViewport(Canvas c)
 {
     backup     = c.Viewport;
     c.Viewport = PanelViewport;
 }
示例#9
0
 /// <summary>
 /// This might not make sense, revisit.
 /// </summary>
 /// <param name="c"></param>
 /// <param name="r"></param>
 protected void StartViewport(Canvas c, Rectangle r)
 {
     backup = c.Viewport;
     SetViewportDimensions(r);
     c.Viewport = PanelViewport;
 }
示例#10
0
 public PanelViewportRegion()
 {
     view = new Viewport();
 }
示例#11
0
        public PanelSceneRegion(int x1, int y1, int x2, int y2, Scene scene)
        {
            _client_area.X = x1;
            _client_area.Y = y1;
            _client_area.Width = x2 - x1;
            _client_area.Height = y2 - y1;

            _scene = scene;

            view = new Viewport();
            view.X = _client_area.X;
            view.Y = _client_area.Y;
            view.Height = _client_area.Height;
            view.Width = _client_area.Width;

            _Sticky = true;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="viewport"></param>
        public override void SetViewport(Axiom.Core.Viewport viewport)
        {
            if (activeViewport != viewport || viewport.IsUpdated) {

                // FIXME
                // If we had a render target of texture, and are switching, grab the surface
                //try {
                //    if (activeViewport != null && activeViewport.Target is D3DRenderTexture) {
                //        D3D.Surface back1 = (D3D.Surface)activeViewport.Target.GetCustomAttribute("DDBACKBUFFER");
                //        SurfaceLoader.Save("../RenderTarget_surface1.jpg", ImageFileFormat.Jpg, back1);
                //        D3D.Surface back2 = device.GetBackBuffer(0, 0, BackBufferType.Mono);
                //        SurfaceLoader.Save("../RenderTarget_surface2.jpg", ImageFileFormat.Jpg, back2);
                //        D3D.Surface back3 = device.GetRenderTarget(0);
                //        SurfaceLoader.Save("../RenderTarget_surface3.jpg", ImageFileFormat.Jpg, back3);
                //    }
                //} catch (Exception e) {
                //    Trace.TraceWarning("Couldn't save texture: RenderTarget_surface.jpg");
                //}

                // store this viewport and it's target
                activeViewport = viewport;
                activeRenderTarget = viewport.Target;

                RenderTarget target = viewport.Target;
                // FIXME: Looks like these methods should be able to return multiple buffers
                // get the back buffer surface for this viewport
                D3D.Surface back = (D3D.Surface)activeRenderTarget.GetCustomAttribute("DDBACKBUFFER");
                if (back == null)
                    return;

                // This is useful for debugging, but it breaks the exit (since we try to write to the trace)
                // back.Disposing += this.SurfaceDisposed;

                // we cannot dipose of the back buffer in fullscreen mode, since we have a direct reference to
                // the main back buffer.  all other surfaces are safe to dispose
                // FIXME: Do I need this?  Not in Ogre, but in Axiom
                // bool disposeBackBuffer = true;
                //if (activeRenderTarget is D3DRenderWindow) {
                //    D3DRenderWindow window = activeRenderTarget as D3DRenderWindow;
                //    if (window.IsFullScreen) {
                //        disposeBackBuffer = false;
                //    }
                //}
                // be sure to destroy the surface we had
                //if (disposeBackBuffer) {
                //    back.Dispose();
                //}

                D3D.Surface depth = (D3D.Surface)activeRenderTarget.GetCustomAttribute("D3DZBUFFER");
                if (depth == null) {
               				/// No depth buffer provided, use our own
                    /// Request a depth stencil that is compatible with the format, multisample type and
                    /// dimensions of the render target.
                    SurfaceDescription srfDesc = back.Description;
                    depth = GetDepthStencilFor(srfDesc.Format, srfDesc.MultiSampleType, srfDesc.Width, srfDesc.Height);
                }

                // Bind render targets
                device.SetRenderTarget(0, back);
                // FIXME: Support multiple render targets
                //uint count = caps.NumMultiRenderTargets;
                //for (int i = 0; i < count; ++i) {
                //    device.SetRenderTarget(i, back[i]);
                //}

                // set the render target and depth stencil for the surfaces beloning to the viewport
                device.DepthStencilSurface = depth;

                // set the culling mode, to make adjustments required for viewports
                // that may need inverted vertex winding or texture flipping
                this.CullingMode = cullingMode;

                D3D.Viewport d3dvp = new D3D.Viewport();

                // set viewport dimensions
                d3dvp.X = viewport.ActualLeft;
                d3dvp.Y = viewport.ActualTop;
                d3dvp.Width = viewport.ActualWidth;
                d3dvp.Height = viewport.ActualHeight;

                if (target.RequiresTextureFlipping) {
                    // Convert "top-left" to "bottom-left"
                    d3dvp.Y = target.Height - d3dvp.Height - d3dvp.Y;
                }

                // Z-values from 0.0 to 1.0 (TODO: standardize with OpenGL)
                d3dvp.MinZ = 0.0f;
                d3dvp.MaxZ = 1.0f;

                // set the current D3D viewport
                device.Viewport = d3dvp;

                // clear the updated flag
                viewport.IsUpdated = false;
            }
        }