public Particle(float x, float y, Vector3D dest,float vel, int lifeSpan,Color4 color, float size = 0.5f) { Location = new Vector3D(x, y, 0); Velocity = vel; LifeSpan = lifeSpan; Color = color; Dest = dest; el = new SharpDX.Direct2D1.Ellipse(new DrawingPointF(x, y), size, size); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); RenderForm form = new RenderForm("Kinect color sample"); RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport); RenderContext context = new RenderContext(device); DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle); //Allow to draw using direct2d on top of swapchain var context2d = new SharpDX.Direct2D1.DeviceContext(swapChain.Texture.QueryInterface<SharpDX.DXGI.Surface>()); //Call release on texture since queryinterface does an addref Marshal.Release(swapChain.Texture.NativePointer); var whiteBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.White); KinectSensor sensor = KinectSensor.GetDefault(); sensor.Open(); KinectBody[] bodyFrame = null; KinectSensorBodyFrameProvider bodyProvider = new KinectSensorBodyFrameProvider(sensor); bool doQuit = false; bool doUpload = false; ColorRGBAFrameData currentData = null; DynamicColorRGBATexture colorTexture = new DynamicColorRGBATexture(device); KinectSensorColorRGBAFrameProvider provider = new KinectSensorColorRGBAFrameProvider(sensor); provider.FrameReceived += (sender, args) => { currentData = args.FrameData; doUpload = true; }; form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } }; FaceFrameResult frameResult = null; SingleFaceProcessor faceProcessor = new SingleFaceProcessor(sensor); faceProcessor.FaceResultAcquired += (sender, args) => { frameResult = args.FrameResult; }; Func<PointF, Vector2> map = new Func<PointF, Vector2>((p) => { float x = p.X / 1920.0f * (float)swapChain.Width; float y = p.Y / 1080.0f * (float)swapChain.Height; return new Vector2(x,y); }); Func<float,float, Vector2> mapxy = new Func<float,float, Vector2>((px,py) => { float x = px / 1920.0f * (float)swapChain.Width; float y = py / 1080.0f * (float)swapChain.Height; return new Vector2(x,y); }); bodyProvider.FrameReceived += (sender, args) => { bodyFrame = args.FrameData; var body = bodyFrame.TrackedOnly().ClosestBodies().FirstOrDefault(); if (body != null) { faceProcessor.AssignBody(body); } else { faceProcessor.Suspend(); } }; RenderLoop.Run(form, () => { if (doQuit) { form.Dispose(); return; } if (doUpload) { colorTexture.Copy(context, currentData); } context.RenderTargetStack.Push(swapChain); device.Primitives.ApplyFullTri(context, colorTexture.ShaderView); device.Primitives.FullScreenTriangle.Draw(context); context.RenderTargetStack.Pop(); if (frameResult != null) { context2d.BeginDraw(); var colorBound = frameResult.FaceBoundingBoxInColorSpace; RectangleF rect = new RectangleF(); Vector2 topLeft = mapxy(colorBound.Left, colorBound.Top); Vector2 bottomRight = mapxy(colorBound.Right, colorBound.Bottom); rect.Top = topLeft.Y; rect.Bottom = bottomRight.Y; rect.Left = topLeft.X; rect.Right = bottomRight.X; context2d.DrawRectangle(rect, whiteBrush, 3.0f); foreach (PointF point in frameResult.FacePointsInColorSpace.Values) { var ellipse = new SharpDX.Direct2D1.Ellipse() { Point = map(point), RadiusX = 5, RadiusY = 5 }; context2d.FillEllipse(ellipse, whiteBrush); } context2d.EndDraw(); } swapChain.Present(0, SharpDX.DXGI.PresentFlags.None); }); swapChain.Dispose(); context.Dispose(); device.Dispose(); colorTexture.Dispose(); provider.Dispose(); bodyProvider.Dispose(); faceProcessor.Dispose(); whiteBrush.Dispose(); context2d.Dispose(); sensor.Close(); }
public override void OnRender(ChartControl chartControl, ChartScale chartScale) { if (firstTime && DrawingState == DrawingState.Normal) { firstTime = false; Cbi.License.Log("TimeCycles"); } ChartPanel chartPanel = chartControl.ChartPanels[PanelIndex]; ChartBars chartBars = GetChartBars(); int startX = Convert.ToInt32(StartAnchor.GetPoint(chartControl, chartPanel, chartScale).X); diameter = Math.Abs(startX - Convert.ToInt32(EndAnchor.GetPoint(chartControl, chartPanel, chartScale).X)); radius = Convert.ToInt32(diameter / 2.0); if (radius <= 0) { return; } UpdateAnchors(chartControl, chartBars, startX); if (anchorBars.Count <= 2) { return; } RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; OutlineStroke.RenderTarget = RenderTarget; // dont bother with an area brush if we're doing a hit test (software) render pass. we do not render area then. // this allows us to select something behind our area brush (like NT7) bool renderArea = false; if (!IsInHitTest && AreaBrush != null) { if (areaBrushDevice.Brush == null) { Brush brushCopy = areaBrush.Clone(); brushCopy.Opacity = areaOpacity / 100d; areaBrushDevice.Brush = brushCopy; } areaBrushDevice.RenderTarget = RenderTarget; renderArea = true; } else { areaBrushDevice.RenderTarget = null; areaBrushDevice.Brush = null; } for (int i = 0; i < anchorBars.Count - 1; i++) { SharpDX.Direct2D1.Ellipse ellipse = new SharpDX.Direct2D1.Ellipse(new SharpDX.Vector2(anchorBars[i] + radius, chartPanel.Y + chartPanel.H), radius, radius); if (renderArea) { RenderTarget.FillEllipse(ellipse, areaBrushDevice.BrushDX); } SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : OutlineStroke.BrushDX; RenderTarget.DrawEllipse(ellipse, tmpBrush); } }