コード例 #1
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e)
        {
            SurfaceDescription desc = e.BackBufferDescription;

            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Reset items
            lightControl.OnResetDevice(desc);

            // Setup the camera's projection parameters
            float aspectRatio = (float)desc.Width / (float)desc.Height;

            if (nif != null)
            {
                camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, nif.Radius / 50, nif.Radius * 5);
            }
            else
            {
                camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 10, 4000);
            }
            camera.SetWindow(desc.Width, desc.Height);
            camera.SetButtonMasks((int)MouseButtonMask.Left, (int)MouseButtonMask.Wheel, (int)MouseButtonMask.Middle);

            // Setup UI locations
            hud.SetLocation(desc.Width - 170, 0);
            hud.SetSize(170, 170);
            sampleUi.SetLocation(desc.Width - 170, 60);
            sampleUi.SetSize(170, 300);

            e.Device.RenderState.ZBufferFunction = Compare.Less;
            if (AF == 0)
            {
                for (int i = 0; i < 3; i++)
                {
                    e.Device.SamplerState[i].MagFilter = TextureFilter.Linear;
                    e.Device.SamplerState[i].MinFilter = TextureFilter.Linear;
                }
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    e.Device.SamplerState[i].MaxAnisotropy = AF;
                    e.Device.SamplerState[i].MinFilter     = TextureFilter.Anisotropic;
                    e.Device.SamplerState[i].MagFilter     = TextureFilter.Linear;
                }
            }

            e.Device.RenderState.AlphaBlendEnable = true;
            e.Device.RenderState.AlphaTestEnable  = true;
            e.Device.RenderState.AlphaFunction    = Compare.Greater;
            e.Device.RenderState.SourceBlend      = Blend.SourceAlpha;
            e.Device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
        }
コード例 #2
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e)
        {
            SurfaceDescription desc = e.BackBufferDescription;

            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Generate the enhanced mesh
            GenerateEnhancedMesh(e.Device, numberSegments);

            // Set the fill mode
            if (isWireframe)
            {
                e.Device.RenderState.FillMode = FillMode.WireFrame;
            }
            else
            {
                e.Device.RenderState.FillMode = FillMode.Solid;
            }

            // Setup the camera's projection parameters
            float aspectRatio = (float)desc.Width / (float)desc.Height;

            camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 0.1f, 1000.0f);
            camera.SetWindow(desc.Width, desc.Height);

            // Setup UI locations
            hud.SetLocation(desc.Width - 170, 0);
            hud.SetSize(170, 170);
            sampleUi.SetLocation(desc.Width - 170, desc.Height - 350);
            sampleUi.SetSize(170, 300);
        }
コード例 #3
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e)
        {
            SurfaceDescription desc = e.BackBufferDescription;

            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Reset items
            for (int i = 0; i < MaxNumberLights; i++)
            {
                lightControl[i].OnResetDevice(desc);
            }

            // Setup the camera's projection parameters
            float aspectRatio = (float)desc.Width / (float)desc.Height;

            camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 0.1f, 5000.0f);
            camera.SetWindow(desc.Width, desc.Height);
            camera.SetButtonMasks((int)MouseButtonMask.Left, (int)MouseButtonMask.Wheel, (int)MouseButtonMask.Middle);

            // Setup UI locations
            hud.SetLocation(desc.Width - 170, 0);
            hud.SetSize(170, 170);
            sampleUi.SetLocation(desc.Width - 170, desc.Height - 300);
            sampleUi.SetSize(170, 300);
        }
コード例 #4
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e)
        {
            SurfaceDescription desc = e.BackBufferDescription;

            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Set effect variables as needed
            effect.SetValue("g_MaterialAmbientColor", new ColorValue(0.35f, 0.35f, 0.35f, 0));
            effect.SetValue("g_MaterialDiffuseColor", WhiteColor);

            // To read or write to D3DX effect variables we can use the string name
            // instead of using handles, however it improves perf to use handles since then
            // D3DX won't have to spend time doing string compares
            techniqueHandle   = effect.GetTechnique("RenderScene");
            timeHandle        = effect.GetParameter(null, "g_fTime");
            worldHandle       = effect.GetParameter(null, "g_mWorld");
            worldViewHandle   = effect.GetParameter(null, "g_mWorldViewProjection");
            meshTextureHandle = effect.GetParameter(null, "g_MeshTexture");

            // Setup the camera's projection parameters
            float aspectRatio = (float)desc.Width / (float)desc.Height;

            camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 0.1f, 1000.0f);
            camera.SetWindow(desc.Width, desc.Height);

            // Setup UI locations
            hud.SetLocation(desc.Width - 170, 0);
            hud.SetSize(170, 170);
        }
コード例 #5
0
ファイル: Simple2D.cs プロジェクト: d3x0r/xperdex
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e)
        {
            bbufferDesc = e.BackBufferDescription;
            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Setup the camera's projection parameters
            float aspectRatio = (float)bbufferDesc.Width / (float)bbufferDesc.Height;

            camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 0.1f, 1000.0f);
            camera.SetWindow(bbufferDesc.Width, bbufferDesc.Height);

            // Setup UI locations
            hud.SetLocation(bbufferDesc.Width - 170, 0);
            hud.SetSize(170, 170);
            sampleUi.SetLocation(bbufferDesc.Width - 170, bbufferDesc.Height - 350);
            sampleUi.SetSize(170, 300);

            batchSprite = new Sprite(e.Device);

            //set up the static gameboard
            UpdateVisibleTiles();

            movingSprite.SetScreenSize(bbufferDesc.Width, bbufferDesc.Height);
        }
コード例 #6
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e)
        {
            SurfaceDescription desc = e.BackBufferDescription;

            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Setup render states
            e.Device.RenderState.Lighting = false;
            e.Device.RenderState.CullMode = Cull.None;

            // Create and initialize index buffer
            ib = new IndexBuffer(typeof(short), NumberIndices, e.Device, Usage.None, Pool.Default);
            GraphicsStream data = ib.Lock(0, 0, LockFlags.None);

            for (int y = 1; y < VerticesPerEdge; y++)
            {
                for (int x = 1; x < VerticesPerEdge; x++)
                {
                    data.Write((short)((y - 1) * VerticesPerEdge + (x - 1)));
                    data.Write((short)((y - 0) * VerticesPerEdge + (x - 1)));
                    data.Write((short)((y - 1) * VerticesPerEdge + (x - 0)));

                    data.Write((short)((y - 1) * VerticesPerEdge + (x - 0)));
                    data.Write((short)((y - 0) * VerticesPerEdge + (x - 1)));
                    data.Write((short)((y - 0) * VerticesPerEdge + (x - 0)));
                }
            }
            ib.Unlock();

            // Create and initialize vertex buffer
            vb   = new VertexBuffer(typeof(Vector2), NumberVertices, e.Device, Usage.None, VertexFormats.None, Pool.Default);
            data = vb.Lock(0, 0, LockFlags.None);
            for (int y = 0; y < VerticesPerEdge; y++)
            {
                for (int x = 0; x < VerticesPerEdge; x++)
                {
                    data.Write(new Vector2(((float)x / (float)(VerticesPerEdge - 1) - 0.5f) * (float)Math.PI,
                                           ((float)y / (float)(VerticesPerEdge - 1) - 0.5f) * (float)Math.PI));
                }
            }
            vb.Unlock();

            // Setup the camera's projection parameters
            float aspectRatio = (float)desc.Width / (float)desc.Height;

            camera.SetProjectionParameters((float)Math.PI / 4.0f, aspectRatio, 0.1f, 1000.0f);
            camera.SetWindow(desc.Width, desc.Height);
            camera.MaximumRadius = 30.0f;

            // Resize the hud
            hud.SetLocation(desc.Width - 170, 0);
            hud.SetSize(170, 170);
        }
コード例 #7
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e)
        {
            SurfaceDescription desc = e.BackBufferDescription;

            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Setup the camera's projection parameters
            float aspectRatio = (float)desc.Width / (float)desc.Height;

            camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 0.1f, 1000.0f);
            camera.SetWindow(desc.Width, desc.Height);

            // Setup UI locations
            hud.SetLocation(desc.Width - 170, 0);
            hud.SetSize(170, 170);
            sampleUi.SetLocation(desc.Width - 170, desc.Height - 350);
            sampleUi.SetSize(170, 300);
        }
コード例 #8
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e)
        {
            SurfaceDescription desc = e.BackBufferDescription;

            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Setup the camera's projection parameters
            float aspectRatio = (float)desc.Width / (float)desc.Height;

            camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 0.1f, 1000.0f);
            camera.SetWindow(desc.Width, desc.Height);

            // Setup UI locations
            hud.SetLocation(desc.Width - 170, 0);
            hud.SetSize(170, 170);
            sampleUi.SetLocation(0, 0);
            sampleUi.SetSize(desc.Width, desc.Height);

            sampleUi.GetControl(StaticControl).SetLocation((desc.Width - 200) / 2, desc.Height - 300);
            sampleUi.GetControl(OutputStaticControl).SetSize(desc.Width - 170, desc.Height / 4);
            sampleUi.GetControl(EditBoxControl).SetLocation(20, desc.Height - 270);
            sampleUi.GetControl(EditBoxControl).SetSize(desc.Width - 40, 32);
            sampleUi.GetControl(SliderControl).SetLocation(10, desc.Height - 140);
            sampleUi.GetControl(CheckBoxControl).SetLocation(100, desc.Height - 50);
            sampleUi.GetControl(ClearEditControl).SetLocation(100, desc.Height - 25);
            sampleUi.GetControl(ComboBoxControl).SetLocation(20, desc.Height - 180);
            sampleUi.GetControl(RadioButton1A).SetLocation(desc.Width - 140, 110);
            sampleUi.GetControl(RadioButton1B).SetLocation(desc.Width - 140, 134);
            sampleUi.GetControl(RadioButton1C).SetLocation(desc.Width - 140, 158);
            sampleUi.GetControl(RadioButton2A).SetLocation(20, desc.Height - 100);
            sampleUi.GetControl(RadioButton2B).SetLocation(20, desc.Height - 76);
            sampleUi.GetControl(RadioButton2C).SetLocation(20, desc.Height - 52);
            sampleUi.GetControl(ListBoxControl).SetLocation(desc.Width - 400, desc.Height - 180);
            sampleUi.GetControl(ListBoxControl).SetSize(190, 96);
            sampleUi.GetControl(ListBoxControlMulti).SetLocation(desc.Width - 200, desc.Height - 180);
            sampleUi.GetControl(ListBoxControlMulti).SetSize(190, 124);
        }
コード例 #9
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        private void OnResetDevice(object sender, DeviceEventArgs e)
        {
            SurfaceDescription desc = e.BackBufferDescription;

            // Create a sprite to help batch calls when drawing many lines of text
            textSprite = new Sprite(e.Device);

            // Setup the camera's projection parameters
            float aspectRatio = (float)desc.Width / (float)desc.Height;

            camera.SetProjectionParameters((float)Math.PI / 4, aspectRatio, 0.1f, 1000.0f);
            camera.SetWindow(desc.Width, desc.Height);

            // Setup UI locations
            hud.SetLocation(desc.Width - 170, 0);
            hud.SetSize(170, 170);
            sampleUi.SetLocation(0, desc.Height - 50);
            sampleUi.SetSize(desc.Width, 50);

            // Update controls
            sampleUi.GetControl(DetailLabel).SetLocation((desc.Width - 200) / 2, 10);
            sampleUi.GetControl(UseOptimizedCheckBox).SetLocation(desc.Width - 130, 5);
            sampleUi.GetControl(Detail).SetSize(desc.Width - 20, 16);
        }