/// <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); }
/// <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); }