/// <summary> /// Handles the Paint event of the renderControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param> void renderControl_Paint(object sender, PaintEventArgs e) { try { RenderTarget2D.BeginDraw(); RenderTarget2D.Clear(Color.White); RenderTarget2D.DrawLine(new Vector2(0, 0), new Vector2(renderControl.ClientSize.Width, renderControl.ClientSize.Height), SceneColorBrush); RenderTarget2D.DrawLine(new Vector2(0, renderControl.ClientSize.Height), new Vector2(renderControl.ClientSize.Width, 0), SceneColorBrush); RenderTarget2D.DrawTextLayout(new Vector2(0, 0), CurrentTextLayout, SceneColorBrush); RenderTarget2D.EndDraw(); } catch (Exception ex) { LogException(ex); } }
protected override void Draw(DemoTime time) { var now = DateTime.Now; // Don't over-render, it costs CPU and that's energy var delta = (int)(now - lastFrame).TotalMilliseconds; if (delta < msPerFrame) { System.Threading.Thread.Sleep(msPerFrame - delta); } lastFrame = now; base.Draw(time); // Update WorldViewProj Matrix var viewProj = Matrix.Multiply(view, proj); var worldViewProj = Matrix.Translation(new Vector3(0, (float)(instruments.pitch * 0.5 / Math.PI), 0)) * Matrix.RotationZ(instruments.roll) * viewProj; // Matrix.RotationX(time) * Matrix.RotationY(time * 2) * Matrix.RotationZ(time * .7f) worldViewProj.Transpose(); context.UpdateSubresource(ref worldViewProj, contantBuffer); // var attitude = adhrs.RawRead(); if (attitude.Count() > 0) { lastRead = now; instruments.SetFromAhrs(attitude); } if ((now - lastRead).TotalSeconds > 1.2) { RenderTarget2D.DrawLine(new Vector2(0, 0), new Vector2(Stock.ClientRectangle.Width, Stock.ClientRectangle.Height), errorBrush, 3.0f); RenderTarget2D.DrawLine(new Vector2(Stock.ClientRectangle.Width, 0), new Vector2(0, Stock.ClientRectangle.Height), errorBrush, 3.0f); } context.Draw(36, 0); instruments.Draw(RenderTarget2D, instrumentColorBrush); }