示例#1
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            // Setup render state
            renderState.Lighting      = true;
            renderState.DitherEnable  = true;
            renderState.ZBufferEnable = true;
            sampleState[0].MagFilter  = TextureFilter.Linear;
            sampleState[0].MinFilter  = TextureFilter.Linear;

            // Setup the light
            GraphicsUtility.InitLight(device.Lights[0], LightType.Directional, 0.0f, -0.5f, 1.0f);
            device.Lights[0].Commit();
            device.Lights[0].Enabled = true;
            renderState.Ambient      = System.Drawing.Color.FromArgb(0x00333333);

            // Set the arcball parameters
            arcBall.SetWindow(device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight,
                              0.85f);
            arcBall.Radius = objectRadius;

            // Set the projection matrix
            float fAspect = device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, objectRadius / 64.0f, objectRadius * 200.0f);

            initDone = true;
        }
示例#2
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            ourArcball.SetWindow(device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, 0.9f);

            // PROJECTION matrix for the entire scene
            // NOTE: The projection is fixed
            float fAspect = ((float)device.PresentationParameters.BackBufferWidth) / device.PresentationParameters.BackBufferHeight;

            projectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, 1.0f, 60.0f);
            projectionMatrix.Transpose(projectionMatrix);
        }
示例#3
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            isUsingHardwareNPatches = Caps.DeviceCaps.SupportsNPatches;             // Do we have hardware support?

            //enhancedMesh = systemMemoryMesh;

            // Setup render state
            renderState.Lighting      = true;
            renderState.DitherEnable  = true;
            renderState.ZBufferEnable = true;
            renderState.Ambient       = System.Drawing.Color.FromArgb(0x33333333);
            sampleState[0].MagFilter  = TextureFilter.Linear;
            sampleState[0].MinFilter  = TextureFilter.Linear;

            // Setup the light
            GraphicsUtility.InitLight(device.Lights[0], LightType.Directional, 0.0f, -1.0f, 1.0f);
            device.Lights[0].Commit();
            device.Lights[0].Enabled = true;

            GraphicsUtility.InitLight(device.Lights[1], LightType.Directional, 1.0f, 1.0f, 1.0f);
            device.Lights[1].Commit();
            device.Lights[1].Enabled = true;

            // Set the arcball parameters
            arcBall.SetWindow(device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, 0.85f);
            arcBall.Radius = 1.0f;

            // Set the projection matrix
            float fAspect = device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, objectRadius / 64.0f, objectRadius * 200.0f);

            if (isWireframe)
            {
                device.RenderState.FillMode = FillMode.WireFrame;
            }
            else
            {
                device.RenderState.FillMode = FillMode.Solid;
            }
        }
示例#4
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            // Build the device objects for the file-based objecs
            airplane.RestoreDeviceObjects(device, null);
            terrainObject.RestoreDeviceObjects(device, null);

            if ((squareVertexBuffer == null) || (squareVertexBuffer.Disposed))
            {
                // Create a big square for rendering the mirror, we don't need to recreate this every time, if the VertexBuffer
                // is destroyed (by a call to Reset for example), it will automatically be recreated and the 'Created' event fired.
                squareVertexBuffer          = new VertexBuffer(typeof(ShadowVertex), 4, device, Usage.WriteOnly, ShadowVertex.Format, Pool.Default);
                squareVertexBuffer.Created += new System.EventHandler(this.ShadowCreated);
                // Manually fire the created event the first time
                this.ShadowCreated(squareVertexBuffer, null);
            }

            // Create and set up the shine materials w/ textures
            device.Material = GraphicsUtility.InitMaterial(System.Drawing.Color.White);

            // Set up textures
            device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            device.SamplerState[0].MinFilter      = TextureFilter.Linear;
            device.SamplerState[0].MagFilter      = TextureFilter.Linear;

            // Set up misc render states
            device.RenderState.ZBufferEnable  = true;
            device.RenderState.DitherEnable   = true;
            device.RenderState.SpecularEnable = false;

            // Set the transform matrices
            Vector3 vEyePt = new Vector3(0.0f, 10.0f, -20.0f);
            Vector3 vLookatPt = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 vUpVec = new Vector3(0.0f, 1.0f, 0.0f);
            Matrix  matWorld, matView, matProj;

            matWorld = Matrix.Identity;
            matView  = Matrix.LookAtLH(vEyePt, vLookatPt, vUpVec);
            float fAspect = device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            matProj = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, 1.0f, 1000.0f);

            device.Transform.World      = matWorld;
            device.Transform.View       = matView;
            device.Transform.Projection = matProj;

            // Turn on fog
            float fFogStart = 30.0f;
            float fFogEnd   = 80.0f;

            device.RenderState.FogEnable      = true;
            device.RenderState.FogColor       = fogColor;
            device.RenderState.FogTableMode   = FogMode.None;
            device.RenderState.FogVertexMode  = FogMode.Linear;
            device.RenderState.RangeFogEnable = false;
            device.RenderState.FogStart       = fFogStart;
            device.RenderState.FogEnd         = fFogEnd;

            // Set the ArcBall parameters
            arcBall.SetWindow(device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, 2.0f);
            arcBall.Radius = 5.0f;

            device.Lights[0].Enabled    = true;
            device.RenderState.Lighting = true;
            device.RenderState.Ambient  = System.Drawing.Color.FromArgb(0x00303030);
        }