protected override void OnDirectXRender() { var device = Device; var points = animatedDataSource.GetPoints().ToArray(); var pointList = new VertexPosition4Color[points.Length]; for (int i = 0; i < points.Length; i++) { pointList[i] = new VertexPosition4Color { Position = new Vector4(100 + 500 * (float)points[i].X, 500 + 500 * (float)points[i].Y, 0.5f, 1), Color = Color.Orange.ToArgb() }; } var lineListIndices = new short[(points.Length * 2) - 2]; // Populate the array with references to indices in the vertex buffer for (int i = 0; i < points.Length - 1; i++) { lineListIndices[i * 2] = (short)(i); lineListIndices[(i * 2) + 1] = (short)(i + 1); } Device.SetTransform(TransformState.World, Matrix.Translation(100, 0, 0)); Device.SetTransform(TransformState.View, camera.ViewMatrix); Device.SetTransform(TransformState.Projection, camera.ProjectionMatrix); device.SetRenderState(SlimDX.Direct3D9.RenderState.AntialiasedLineEnable, true); device.VertexFormat = VertexFormat.Diffuse | VertexFormat.PositionRhw; device.DrawIndexedUserPrimitives <short, VertexPosition4Color>(PrimitiveType.LineList, 0, points.Length, points.Length - 1, lineListIndices, Format.Index16, pointList, VertexPosition4Color.SizeInBytes); }
private void UpdateBounds(IPointDataSource dataSource) { if (Plotter2D != null) { var transform = GetTransform(); DataRect bounds = BoundsHelper.GetViewportBounds(dataSource.GetPoints(), transform.DataTransform); Viewport2D.SetContentBounds(this, bounds); } }
private void UpdateBounds(IPointDataSource dataSource) { if (Plotter2D != null & dataSource != null) { var transform = GetTransform(); Rect bounds = BoundsHelper.GetViewportBounds(dataSource.GetPoints(), transform.DataTransform); ContentBounds = bounds; } }
private void CompositionTarget_Rendering(object sender, EventArgs e) { if (counter++ % 2 == 0) { return; } //Debug.WriteLine(watch.ElapsedMilliseconds); if (sizeChanged) { pp.BackBufferWidth = (int)ActualWidth; pp.BackBufferHeight = (int)ActualHeight; //Device.Reset(pp); sizeChanged = false; } Result result; if (d3dimage.IsFrontBufferAvailable) { result = Device.TestCooperativeLevel(); if (result.IsFailure) { throw new Direct3D9Exception(); } d3dimage.Lock(); Device.SetRenderState(RenderState.CullMode, Cull.None); Device.SetRenderState(RenderState.ZEnable, true); Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(1, 1, 1, 1), 1.0f, 0); Device.BeginScene(); var points = animatedDataSource.GetPoints().ToArray(); var pointList = new VertexPositionColor[points.Length]; //phase += 0.01; //if (phase > 2 * Math.PI) // phase -= 2 * Math.PI; //for (int i = 0; i < animatedX.Length; i++) //{ // animatedX[i] = 2 * Math.PI * i / animatedX.Length; // if (i % 2 == 0) // animatedY[i] = Math.Sin(animatedX[i] + phase); // else // animatedY[i] = -Math.Sin(animatedX[i] + phase); //} for (int i = 0; i < points.Length; i++) { pointList[i] = new VertexPositionColor { Position = new Vector4(100 + 500 * (float)points[i].X, 500 + 500 * (float)points[i].Y, 0.5f, 1), Color = Color.Orange.ToArgb() }; } var lineListIndices = new short[(points.Length * 2) - 2]; // Populate the array with references to indices in the vertex buffer for (int i = 0; i < points.Length - 1; i++) { lineListIndices[i * 2] = (short)(i); lineListIndices[(i * 2) + 1] = (short)(i + 1); } device.SetRenderState(RenderState.AntialiasedLineEnable, true); device.VertexFormat = VertexFormat.Diffuse | VertexFormat.PositionRhw; device.DrawIndexedUserPrimitives <short, VertexPositionColor>(PrimitiveType.LineList, 0, points.Length, points.Length - 1, lineListIndices, Format.Index16, pointList, 20); //pointList, //0, // vertex buffer offset to add to each element of the index buffer //8, // number of vertices in pointList //lineListIndices, // the index buffer //0, // first index element to read //7 // number of primitives to draw //); Device.EndScene(); Device.Present(); d3dimage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, Device.GetBackBuffer(0, 0).ComPointer); d3dimage.AddDirtyRect(new Int32Rect(0, 0, d3dimage.PixelWidth, d3dimage.PixelHeight)); d3dimage.Unlock(); } }
private void UpdateBounds(IPointDataSource dataSource) { if (Plotter2D != null & dataSource!=null) { var transform = GetTransform(); Rect bounds = BoundsHelper.GetViewportBounds(dataSource.GetPoints(), transform.DataTransform); ContentBounds = bounds; } }