/// <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);
        }
Beispiel #2
0
        private void RenderFlag(float t, double a, int shells)
        {
            TechniqueDescription techDesc = effects.Technique.Description;

            for (int x = -shells; x <= shells; x++)
            {
                for (int z = -shells; z <= shells; z++)
                {
                    float    height     = ((float)Math.Sin(0.5 * (x + 4 * t)) + (float)Math.Cos(0.25 * (z + 2 * t)));
                    Vector4F vBaseColor = new Vector4F(0.0f, 0.0f, 0.0f, 1.0f);
                    if (x < 0 && z > 0)
                    {
                        vBaseColor.X = 0.75f + 0.125f * height; //red
                    }
                    else if (x > 0 && z > 0)
                    {
                        vBaseColor.Y = 0.75f + 0.125f * height; //green
                    }
                    else if (x < 0 && z < 0)
                    {
                        vBaseColor.Z = 0.75f + 0.125f * height; //blue
                    }
                    else if (x > 0 && z < 0)
                    {//yellow
                        vBaseColor.X = 0.75f + 0.125f * height;
                        vBaseColor.Y = 0.75f + 0.125f * height;
                    }
                    else
                    {
                        continue;
                    }
                    effects.BaseColor = vBaseColor;

                    float yScale = 5f + 0.5f * height;
                    effects.WorldMatrix =
                        MatrixMath.MatrixScale(0.35f, yScale, 0.35f) *
                        MatrixMath.MatrixTranslate(x, yScale - 10, z);

                    for (uint p = 0; p < techDesc.Passes; ++p)
                    {
                        effects.Technique.GetPassByIndex(p).Apply();
                        device.DrawIndexed(36, 0, 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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #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.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);
        }