void RenderScene() { lock (syncObject) { if (device == null) { CreateDeviceResources(); } if (!pause) { if (lastSavedDelta != 0) { startTime = Environment.TickCount - lastSavedDelta; lastSavedDelta = 0; } currentTimeVariation = (Environment.TickCount - startTime) / 6000.0f; worldMatrix = MatrixMath.MatrixTranslate(0, 0, currentTimeVariation); textBrush.Transform = Matrix3x2F.Translation(0, (4096f / 16f) * currentTimeVariation); } device.ClearDepthStencilView( depthStencilView, ClearOptions.Depth, 1, 0 ); // Clear the back buffer device.ClearRenderTargetView(renderTargetView, backColor); diffuseVariable.Resource = null; technique.GetPassByIndex(0).Apply(); // Draw the D2D content into our D3D surface RenderD2DContentIntoSurface(); diffuseVariable.Resource = textureResourceView; // Update variables worldMatrixVariable.Matrix = worldMatrix; // Set index buffer device.IA.IndexBuffer = new IndexBuffer(facesIndexBuffer, Format.R16UInt, 0); // Draw the scene technique.GetPassByIndex(0).Apply(); device.DrawIndexed((uint)Marshal.SizeOf(VertexArray.VerticesInstance), 0, 0); swapChain.Present(0, Microsoft.WindowsAPICodePack.DirectX.Graphics.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)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.5f, 100.0f); projectionVariable.Matrix = projectionMatrix; } 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); }