Beispiel #1
0
        private bool Draw3D()
        {
            if( device == null )
                return false;

            int code;
            device.CheckCooperativeLevel( out code );

            switch( (ResultCode)code )
            {
            case ResultCode.Success:
                break;

            case ResultCode.DeviceLost:
                HandleDeviceLost();
                return false;

            case ResultCode.DeviceNotReset:
                ResetDevice();
                break;

            default:
                return false;
            }

            if( isLost )
                return false;

            device.BeginScene();

            DXPaintEventArgs args = new DXPaintEventArgs( device );
            OnPaint3D( args );

            device.EndScene();

            if( args.Draw2D )
                return false;

            try
            {
                device.Present();
            }
            catch( DriverInternalErrorException )
            {
                isLost = true;
                return false;
            }
            catch
            {
                return false;
            }

            return true;
        }
Beispiel #2
0
        private void pn3D_Paint3D( object sender, DXPaintEventArgs e )
        {
            Device dev = pn3D.Device;

            defState.Apply();

            Matrix view, projection;

            view = cam.ViewMatrix;
            cam.ComputeProjectionMatrix( 0.01F, 500.0F, out projection );

            switch( viewMode )
            {
            case Mode.Depth:
                dev.VertexShader = depthVs;
                depthVsConsts.SetValue( dev, EffectHandle.FromString( "mv" ), view );
                depthVsConsts.SetValue( dev, EffectHandle.FromString( "mvp" ), view * projection );

                dev.PixelShader = depthPs;
                break;

            case Mode.Normals:
                dev.VertexShader = normVs;
                normVsConsts.SetValue( dev, EffectHandle.FromString( "mvp" ), view * projection );

                dev.PixelShader = normPs;
                break;
            }

            //do model 1
            using( Surface surf = depthTex1.GetSurfaceLevel( 0 ) )
                dev.SetRenderTarget( 0, surf );
            dev.Clear( ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0F, 0 );

            model1DXData.BindModelData();
            model1DXData.Draw( model1.Model.Lods[0] );

            //do model 2
            using( Surface surf = depthTex2.GetSurfaceLevel( 0 ) )
                dev.SetRenderTarget( 0, surf );
            dev.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0F, 0 );

            model2DXData.BindModelData();
            model2DXData.Draw( model2.Model.Lods[0] );

            //clear out old state
            dev.VertexShader = null;
            dev.SetStreamSource( 0, null, 0 );
            dev.Indices = null;

            //draw difference
            using( Surface surf = dev.GetBackBuffer( 0, 0, BackBufferType.Mono ) )
                dev.SetRenderTarget( 0, surf );

            dev.PixelShader = delptaPs;
            deltaPsConsts.SetValue( dev, EffectHandle.FromString( "scale" ), trkScale.Value * 0.125F );
            deltaPsConsts.SetValue( dev, EffectHandle.FromString( "power" ), trkPower.Value * 1.0F );

            dev.SetTexture( 0, depthTex1 );
            dev.SetTexture( 1, depthTex2 );

            dev.Transform.World = Matrix.Identity;
            dev.Transform.View = Matrix.Identity;
            dev.Transform.Projection = Matrix.Identity;

            dev.RenderState.ZBufferEnable = false;
            dev.RenderState.MultiSampleAntiAlias = false;

            DrawFSQuad();
        }
Beispiel #3
0
 protected virtual void OnPaint3D( DXPaintEventArgs e )
 {
     if( Paint3D != null )
         Paint3D( this, e );
 }
Beispiel #4
0
        private void pn3D_Paint3D( object sender, DXPaintEventArgs e )
        {
            if( model.Model == null )
            {
                pn3D.Text = "No model loaded.";
                e.Draw2D = true;
                return;
            }

            Device dev = e.Device;

            defState.Apply();

            dev.Clear( ClearFlags.Target | ClearFlags.ZBuffer,
                pnPreviewOpts.BackgroundColor, 1.0F, 0 );

            Matrix view, projection;
            GetCameraMatrices( out view, out projection );

            dev.Transform.Projection = projection;
            dev.Transform.View = view;
            dev.Transform.World = Matrix.Identity;

            switch( previewMode )
            {
            case PreviewMode.Surfaces:
                DrawSurfacesView();
                break;

            case PreviewMode.Skeleton:
                DrawSkeletonView();
                break;

            case PreviewMode.Topology:
                DrawTopologyView();
                break;

            case PreviewMode.Bounds:
                DrawBoundsView();
                break;

            case PreviewMode.Shaded:
                DrawShadedView();
                break;

            default:
                pn3D.Text = "Unknown preview mode.";
                e.Draw2D = true;
                return;
            }

            if( pnPreviewOpts.EnableGroundPlane )
                DrawGroundPlane();
        }