Пример #1
0
        /// <summary>
        /// Render the frame
        /// </summary>
        protected void RenderScene()
        {
            if (needsResizing)
            {
                needsResizing = false;
                renderTargetView.Dispose();
                SwapChainDescription sd = swapChain.Description;
                swapChain.ResizeBuffers(sd.BufferCount, (uint)host.ActualWidth, (uint)host.ActualHeight, sd.BufferDescription.Format, sd.Options);
                SetViews();
                // Update the projection matrix
                InitMatrices();
            }
            t = (Environment.TickCount - dwTimeStart) / 1000.0f;

            //WPF transforms used here use degrees as opposed to D3DX which uses radians in the native tutorial
            //360 degrees == 2 * Math.PI
            //world matrix rotates the first cube by t degrees
            RotateTransform3D rt1 = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), t * 60));

            // Clear the backbuffer
            device.ClearRenderTargetView(renderTargetView, backColor);

            // Clear the depth buffer to 1.0 (max depth)
            device.ClearDepthStencilView(depthStencilView, ClearOptions.Depth, 1.0f, (byte)0);

            mesh.Render(rt1.Value.ToMatrix4x4F());

            Microsoft.WindowsAPICodePack.DirectX.ErrorCode error;
            swapChain.TryPresent(1, PresentOptions.None, out error);
        }
Пример #2
0
        protected void RenderScene()
        {
            // update view variables
            xAxisRotation.Angle = XAxisSlider.Value;
            yAxisRotation.Angle = -YAxisSlider.Value;
            zAxisRotation.Angle = ZAxisSlider.Value;
            modelZoom.ScaleX    = ZoomSlider.Value / 2;
            modelZoom.ScaleY    = ZoomSlider.Value / 2;
            modelZoom.ScaleZ    = ZoomSlider.Value / 2;

            // update view
            meshManager.SetViewAndProjection(
                camera.ToViewLH().ToMatrix4x4F(),
                camera.ToPerspectiveLH(renderHost.ActualWidth / renderHost.ActualHeight).ToMatrix4x4F());

            // clear render target
            device.ClearRenderTargetView(renderTargetView, backgroundColor);

            // Clear the depth buffer to 1.0 (max depth)
            device.ClearDepthStencilView(depthStencilView, ClearOptions.Depth, 1.0f, (byte)0);

            // render mesh
            mesh.LightIntensity = 2.5f;
            mesh.Render(modelTransformGroup.Value);

            // present back buffer
            swapChain.Present(1, PresentOptions.None);
        }
        /// <summary>
        /// Render the frame
        /// </summary>
        protected void RenderScene()
        {
            if (needsResizing)
            {
                needsResizing = false;
                renderTargetView.Dispose();
                SwapChainDescription sd = swapChain.Description;
                swapChain.ResizeBuffers(sd.BufferCount, (uint)host.ActualWidth, (uint)host.ActualHeight, sd.BufferDescription.Format, sd.Options);
                SetViews();
                // Update the projection matrix
                projectionMatrix          = DXUtil.Camera.MatrixPerspectiveFovLH((float)Math.PI * 0.25f, ((float)host.ActualWidth / (float)host.ActualHeight), 0.5f, 100.0f);
                projectionVariable.Matrix = projectionMatrix;
            }
            Matrix4x4F worldMatrix;

            currentTime = (Environment.TickCount - startTime) / 1000.0f;

            //WPF transforms used here use degrees as opposed to D3DX which uses radians in the native tutorial
            //360 degrees == 2 * Math.PI
            //world matrix rotates the first cube by t degrees
            RotateTransform3D rotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), currentTime * 30));

            worldMatrix = rotateTransform.Value.ToMatrix4x4F();

            // Modify the color
            meshColor.X = ((float)Math.Sin(currentTime * 1.0f) + 1.0f) * 0.5f;
            meshColor.Y = ((float)Math.Cos(currentTime * 3.0f) + 1.0f) * 0.5f;
            meshColor.Z = ((float)Math.Sin(currentTime * 5.0f) + 1.0f) * 0.5f;

            // Clear the backbuffer
            device.ClearRenderTargetView(renderTargetView, backColor);

            //
            // Update variables that change once per frame
            //
            worldVariable.Matrix          = worldMatrix;
            meshColorVariable.FloatVector = meshColor;

            //
            // Render the cube
            //
            TechniqueDescription techDesc = technique.Description;

            for (uint p = 0; p < techDesc.Passes; ++p)
            {
                technique.GetPassByIndex(p).Apply();
                device.DrawIndexed(36, 0, 0);
            }

            swapChain.Present(0, PresentOptions.None);
        }
Пример #4
0
        /// <summary>
        /// Render the frame
        /// </summary>
        protected void RenderScene()
        {
            if (needsResizing)
            {
                needsResizing = false;
                renderTargetView.Dispose();
                SwapChainDescription sd = swapChain.Description;
                swapChain.ResizeBuffers(
                    sd.BufferCount,
                    (uint)directControl.ClientSize.Width,
                    (uint)directControl.ClientSize.Height,
                    sd.BufferDescription.Format,
                    sd.Options);
                SetViews();
                // Update the projection matrix
                InitMatrices();
            }
            int   dwCurrentTime = Environment.TickCount;
            float t             = (dwCurrentTime - dwLastTime) / 1000f;

            dwLastTime = dwCurrentTime;

            // Clear the backbuffer
            device.ClearRenderTargetView(renderTargetView, backColor);

            // Clear the depth buffer to 1.0 (max depth)
            device.ClearDepthStencilView(depthStencilView, ClearOptions.Depth, 1.0f, (byte)0);

            lock (meshLock)
            {
                if (mesh != null)
                {
                    if (cbRotate.Checked)
                    {
                        worldMatrix *= MatrixMath.MatrixRotationY(-t);
                    }
                    mesh.Render(worldMatrix);
                }
            }

            Microsoft.WindowsAPICodePack.DirectX.ErrorCode error;
            swapChain.TryPresent(1, PresentOptions.None, out error);
        }
Пример #5
0
        /// <summary>
        /// Render the frame
        /// </summary>
        protected void RenderScene()
        {
            lock (viewSync)
            {
                if (needsResizing)
                {
                    needsResizing = false;
                    renderTargetView.Dispose();
                    SwapChainDescription sd = swapChain.Description;
                    swapChain.ResizeBuffers(sd.BufferCount, (uint)directControl.ClientSize.Width, (uint)directControl.ClientSize.Height, sd.BufferDescription.Format, sd.Options);
                    SetViews();
                    // Update the projection matrix
                    effects.ProjectionMatrix = DXUtil.Camera.MatrixPerspectiveFovLH((float)Math.PI * 0.25f, ((float)this.ClientSize.Width / (float)this.ClientSize.Height), 0.1f, 4000.0f);
                }
                t = (Environment.TickCount - dwTimeStart) / 1000.0f;
                if (lastPresentTime == 0)
                {
                    lastPresentTime  = t;
                    lastPresentCount = swapChain.LastPresentCount;
                }

                if (t - lastPresentTime > 1.0f) // if one second has elapsed
                {
                    uint   currentPresentCount = swapChain.LastPresentCount;
                    uint   presentCount        = currentPresentCount - lastPresentCount;
                    float  currentframerate    = (float)presentCount / (t - lastPresentTime);
                    string fps = String.Format("{0} fps", currentframerate);
                    label1.BeginInvoke(new MethodInvoker(delegate() { label1.Text = fps; }));
                    lastPresentTime  = t;
                    lastPresentCount = currentPresentCount;
                }

                // Clear the backbuffer
                device.ClearRenderTargetView(renderTargetView, backColor);

                // Clear the depth buffer to 1.0 (max depth)
                device.ClearDepthStencilView(depthStencilView, ClearOptions.Depth, 1.0f, (byte)0);

                RenderFlag(t, t * 180 / Math.PI, flagShells);
                swapChain.Present(0, PresentOptions.None);
            }
        }
Пример #6
0
        /// <summary>
        /// Render the frame
        /// </summary>
        protected void RenderScene()
        {
            if (needsResizing)
            {
                needsResizing = false;
                renderTargetView.Dispose();
                SwapChainDescription sd = swapChain.Description;
                swapChain.ResizeBuffers(sd.BufferCount, (uint)directControl.ClientSize.Width, (uint)directControl.ClientSize.Height, sd.BufferDescription.Format, sd.Options);
                SetViews();
                // Update the projection matrix
                projectionMatrix          = DXUtil.Camera.MatrixPerspectiveFovLH((float)Math.PI * 0.5f, ((float)directControl.ClientSize.Width / (float)directControl.ClientSize.Height), 0.1f, 100.0f);
                projectionVariable.Matrix = projectionMatrix;
            }
            t = (Environment.TickCount - dwTimeStart) / 50;

            // Clear the backbuffer
            device.ClearRenderTargetView(renderTargetView, backColor);

            // Rotate the cube
            RotateTransform3D rt = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), t));

            worldMatrix = rt.Value.ToMatrix4x4F();

            //
            // Update variables that change once per frame
            //
            worldVariable.Matrix = worldMatrix;

            //
            // Render the cube
            //
            TechniqueDescription techDesc = technique.Description;

            for (uint p = 0; p < techDesc.Passes; ++p)
            {
                technique.GetPassByIndex(p).Apply();
                device.DrawIndexed(36, 0, 0);
            }

            swapChain.Present(0, PresentOptions.None);
        }
Пример #7
0
        /// <summary>
        /// Render the frame
        /// </summary>
        protected void RenderScene()
        {
            Matrix4x4F worldMatrix;

            currentTime = (Environment.TickCount - dwTimeStart) / 1000.0f;

            //WPF transforms used here use degrees as opposed to D3DX which uses radians in the native tutorial
            //360 degrees == 2 * Math.PI
            //world matrix rotates the first cube by t degrees
            RotateTransform3D rt1 = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), currentTime * 30));

            worldMatrix = rt1.Value.ToMatrix4x4F();

            // Modify the color
            meshColor.X = ((float)Math.Sin(currentTime * 1.0f) + 1.0f) * 0.5f;
            meshColor.Y = ((float)Math.Cos(currentTime * 3.0f) + 1.0f) * 0.5f;
            meshColor.Z = ((float)Math.Sin(currentTime * 5.0f) + 1.0f) * 0.5f;

            // Clear the backbuffer
            device.ClearRenderTargetView(renderTargetView, backColor);

            //
            // Update variables that change once per frame
            //
            worldVariable.Matrix          = worldMatrix;
            meshColorVariable.FloatVector = meshColor;

            //
            // Render the cube
            //
            TechniqueDescription techDesc = technique.Description;

            for (uint p = 0; p < techDesc.Passes; ++p)
            {
                technique.GetPassByIndex(p).Apply();
                device.DrawIndexed(36, 0, 0);
            }

            swapChain.Present(0, PresentOptions.None);
        }
Пример #8
0
        /// <summary>
        /// Render the frame
        /// </summary>
        protected void RenderScene()
        {
            if (needsResizing)
            {
                needsResizing = false;
                renderTargetView.Dispose();
                SwapChainDescription sd = swapChain.Description;
                swapChain.ResizeBuffers(sd.BufferCount, (uint)directControl.ClientSize.Width, (uint)directControl.ClientSize.Height, sd.BufferDescription.Format, sd.Options);
                SetViews();
            }
            // Just clear the backbuffer
            device.ClearRenderTargetView(renderTargetView, backColor);

            TechniqueDescription techDesc = technique.Description;

            for (uint p = 0; p < techDesc.Passes; ++p)
            {
                technique.GetPassByIndex(p).Apply();
                device.Draw(3, 0);
            }

            swapChain.Present(0, PresentOptions.None);
        }
Пример #9
0
 /// <summary>
 /// Render the frame
 /// </summary>
 protected void RenderScene()
 {
     // Just clear the backbuffer
     device.ClearRenderTargetView(renderTargetView, backColor);
     swapChain.Present(0, PresentOptions.None);
 }
Пример #10
0
        /// <summary>
        /// Render the frame
        /// </summary>
        protected void RenderScene()
        {
            if (needsResizing)
            {
                needsResizing = false;
                renderTargetView.Dispose();
                SwapChainDescription sd = swapChain.Description;
                swapChain.ResizeBuffers(sd.BufferCount, (uint)directControl.ClientSize.Width, (uint)directControl.ClientSize.Height, sd.BufferDescription.Format, sd.Options);
                SetViews();
                // Update the projection matrix
                projectionMatrix          = Microsoft.WindowsAPICodePack.DirectX.DirectXUtilities.Camera.MatrixPerspectiveFovLH((float)Math.PI * 0.25f, ((float)directControl.ClientSize.Width / (float)directControl.ClientSize.Height), 0.5f, 100.0f);
                projectionVariable.Matrix = projectionMatrix;
            }
            Matrix4x4F worldMatrix;

            t = (Environment.TickCount - dwTimeStart) / 50.0f;

            //WPF transforms used here use degrees as opposed to D3DX which uses radians in the native tutorial
            //360 degrees == 2 * Math.PI
            //world matrix rotates the first cube by t degrees
            RotateTransform3D rt1 = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), t));

            worldMatrix = rt1.Value.ToMatrix4x4F();

            //Setup our lighting parameters
            Vector4F[] vLightDirs =
            {
                new Vector4F(-0.577f, 0.577f, -0.577f, 1.0f),
                new Vector4F(0.0f,      0.0f,   -1.0f, 1.0f)
            };
            Vector4F[] vLightColors =
            {
                new Vector4F(0.5f, 0.5f, 0.5f, 1.0f),
                new Vector4F(0.5f, 0.0f, 0.0f, 1.0f)
            };

            //rotate the second light around the origin
            //create a rotation matrix
            RotateTransform3D rt2 = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 2, 0), -t));
            //rotate vLightDirs[1] vector using the rotation matrix
            Vector3D vDir = new Vector3D(vLightDirs[1].X, vLightDirs[1].Y, vLightDirs[1].Z);

            vDir            = rt2.Transform(vDir);
            vLightDirs[1].X = (float)vDir.X;
            vLightDirs[1].Y = (float)vDir.Y;
            vLightDirs[1].Z = (float)vDir.Z;

            // Clear the backbuffer
            device.ClearRenderTargetView(renderTargetView, backColor);

            // Clear the depth buffer to 1.0 (max depth)
            device.ClearDepthStencilView(depthStencilView, ClearOptions.Depth, 1.0f, (byte)0);

            //
            // Update variables that change once per frame
            //
            worldVariable.Matrix = worldMatrix;
            lightDirVariable.SetFloatVectorArray(vLightDirs);
            lightColorVariable.SetFloatVectorArray(vLightColors);

            //
            // Render the cube
            //
            TechniqueDescription techDesc = technique.Description;

            for (uint p = 0; p < techDesc.Passes; ++p)
            {
                technique.GetPassByIndex(p).Apply();
                device.DrawIndexed(36, 0, 0);
            }

            //
            // Render each light
            //
            TechniqueDescription techLightDesc = techniqueLight.Description;

            for (int m = 0; m < 2; m++)
            {
                Vector3F         vLightPos = new Vector3F(vLightDirs[m].X * 5, vLightDirs[m].Y * 5, vLightDirs[m].Z * 5);
                Transform3DGroup tg        = new Transform3DGroup();
                tg.Children.Add(new ScaleTransform3D(0.2, 0.2, 0.2));
                tg.Children.Add(new TranslateTransform3D(vLightPos.X, vLightPos.Y, vLightPos.Z));
                worldVariable.Matrix            = tg.Value.ToMatrix4x4F();
                outputColorVariable.FloatVector = new Vector4F(vLightColors[m].X, vLightColors[m].Y, vLightColors[m].Z, vLightColors[m].W);

                for (uint p = 0; p < techLightDesc.Passes; ++p)
                {
                    techniqueLight.GetPassByIndex(p).Apply();
                    device.DrawIndexed(36, 0, 0);
                }
            }

            swapChain.Present(0, PresentOptions.None);
        }
Пример #11
0
        /// <summary>
        /// Render the frame
        /// </summary>
        protected void RenderScene()
        {
            if (needsResizing)
            {
                needsResizing = false;
                renderTargetView.Dispose();
                SwapChainDescription sd = swapChain.Description;
                swapChain.ResizeBuffers(sd.BufferCount, (uint)directControl.ClientSize.Width, (uint)directControl.ClientSize.Height, sd.BufferDescription.Format, sd.Options);
                SetViews();
                // Update the projection matrix
                projectionMatrix          = DXUtil.Camera.MatrixPerspectiveFovLH((float)Math.PI * 0.25f, ((float)directControl.ClientSize.Width / (float)directControl.ClientSize.Height), 0.1f, 100.0f);
                projectionVariable.Matrix = projectionMatrix;
            }
            Matrix4x4F worldMatrix1;
            Matrix4x4F worldMatrix2;

            t = (Environment.TickCount - dwTimeStart) / 50.0f;

            // 1st Cube: Rotate around the origin
            //WPF transforms used here use degrees as opposed to D3DX which uses radians in the native tutorial
            //360 degrees == 2 * Math.PI
            //world1 matrix rotates the first cube by t degrees
            RotateTransform3D rt1 = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), t));

            worldMatrix1 = rt1.Value.ToMatrix4x4F();

            // 2nd Cube:  Rotate around the 1st cube
            Transform3DGroup tg = new Transform3DGroup();

            //spin the cube
            tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), -t)));
            //scale it down
            tg.Children.Add(new ScaleTransform3D(0.3, 0.3, 0.3));
            //translate it (move to orbit)
            tg.Children.Add(new TranslateTransform3D(-4, 0, 0));
            //orbit around the big cube
            tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -2 * t)));
            worldMatrix2 = tg.Value.ToMatrix4x4F();

            // Clear the backbuffer
            device.ClearRenderTargetView(renderTargetView, backColor);

            // Clear the depth buffer to 1.0 (max depth)
            device.ClearDepthStencilView(depthStencilView, ClearOptions.Depth, 1.0f, (byte)0);

            TechniqueDescription techDesc = technique.Description;

            //
            // Update variables that change once per frame
            //
            worldVariable.Matrix = worldMatrix1;

            //
            // Render the 1st cube
            //
            for (uint p = 0; p < techDesc.Passes; ++p)
            {
                technique.GetPassByIndex(p).Apply();
                device.DrawIndexed(36, 0, 0);
            }

            //
            // Render the 2nd cube
            //
            worldVariable.Matrix = worldMatrix2;
            for (uint p = 0; p < techDesc.Passes; ++p)
            {
                technique.GetPassByIndex(p).Apply();
                device.DrawIndexed(36, 0, 0);
            }

            swapChain.Present(0, PresentOptions.None);
        }