Ejemplo n.º 1
0
        private void _drawDesktopOutline(SharpDX.Direct2D1.DeviceContext d2dContext)
        {
            //BORDER
            d2dContext.Transform = Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale);
            d2dContext.DrawRectangle(
                _layoutDeviceScreenSize,
                _generalLightGrayColor,
                3
                );

            //WIDTH
            d2dContext.Transform = Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale);
            d2dContext.FillRectangle(
                new RectangleF(0, -30, 100, 30),
                _generalLightGrayColor
                );
            d2dContext.Transform = Matrix.Translation(10, 0, 0) * Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale);
            d2dContext.DrawText(_layoutDetail.Width.ToString(), _generalTextFormat, new RectangleF(0, -30, 100, 30), _generalLightWhiteColor);

            ////HEIGHT
            double angleRadians = 90 * Math.PI / 180; //90 degrees

            d2dContext.Transform = Matrix.RotationZ((float)angleRadians) * Matrix.Identity * Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale);
            d2dContext.FillRectangle(
                new RectangleF(0, 0, 100, 30),
                _generalLightGrayColor
                );
            d2dContext.Transform = Matrix.RotationZ((float)angleRadians) * Matrix.Translation(0, 10, 0) * Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale);
            d2dContext.DrawText(_layoutDetail.Height.ToString(), _generalTextFormat, new RectangleF(0, 0, 100, 30), _generalLightWhiteColor);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var imageBrush = new ImageBrush();
            imageBrush.ImageSource = _sisWrapper;
            rectangle.Fill = imageBrush;

            _sisWrapper.BeginDraw();

            var context = new SharpDX.Direct2D1.DeviceContext(new IntPtr(_sisWrapper.GetDeviceContext()));
            context.Clear(new SharpDX.Color4(0.4f, 0.3f, 0.15f, 1.0f));

            var random = new Random();
            for (int i = 0; i < 20; ++i)
            {
                var brush = new SharpDX.Direct2D1.SolidColorBrush(context, new SharpDX.Color4(
                    (float)random.NextDouble(),
                    (float)random.NextDouble(),
                    (float)random.NextDouble(),
                    1.0f));

                var left = (float)(250.0f * random.NextDouble());
                var top = (float)(250.0f * random.NextDouble());
                context.FillRectangle(new SharpDX.RectangleF(
                    left, top, left + 50.0f, top + 50.0f),
                    brush);
            }

            _sisWrapper.EndDraw();
        }
Ejemplo n.º 3
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect simple pilot 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 textFormat = new SharpDX.DirectWrite.TextFormat(device.DWriteFactory, "Arial", 16.0f);

            var blackBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.Black);
            var whiteBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.White);

            KinectSensor sensor = KinectSensor.GetDefault();
            sensor.Open();

            bool doQuit = false;

            KinectSensorColorRGBAFrameProvider provider = new KinectSensorColorRGBAFrameProvider(sensor);
            DynamicColorRGBATextureProcessor colorProcessor = new DynamicColorRGBATextureProcessor(provider, device);

            KinectPilotProcessor pilot = KinectPilotProcessor.Default;

            KinectSensorBodyFrameProvider bodyFrameProvider = new KinectSensorBodyFrameProvider(sensor);
            bodyFrameProvider.FrameReceived += (sender, args) =>
            {
                var body = args.FrameData.TrackedOnly().ClosestBodies().FirstOrDefault();
                if (body != null)
                {
                    pilot.Process(body.GetJointTable());
                }
            };

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } };

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                colorProcessor.Update(context);

                context.RenderTargetStack.Push(swapChain);

                device.Primitives.ApplyFullTri(context, colorProcessor.Texture.ShaderView);
                device.Primitives.FullScreenTriangle.Draw(context);
                context.RenderTargetStack.Pop();

                context2d.BeginDraw();

                var rect = new SharpDX.RectangleF(0, 0, 200, 130);
                context2d.FillRectangle(rect, blackBrush);
                context2d.DrawText("Elevation: " + pilot.Elevation, textFormat, rect, whiteBrush);
                rect.Top += 30;
                context2d.DrawText("Steering Y: " + pilot.SteeringY, textFormat, rect, whiteBrush);
                rect.Top += 30;
                context2d.DrawText("Steering Z: " + pilot.SterringZ, textFormat, rect, whiteBrush);
                rect.Top += 30;
                context2d.DrawText("Push: " + pilot.Push, textFormat, rect, whiteBrush);
                context2d.EndDraw();

                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();

            colorProcessor.Dispose();
            provider.Dispose();

            sensor.Close();
        }
Ejemplo n.º 4
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RenderForm form = new RenderForm("Kinect simple pilot 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 textFormat = new SharpDX.DirectWrite.TextFormat(device.DWriteFactory, "Arial", 16.0f);


            var blackBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.Black);
            var whiteBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.White);

            KinectSensor sensor = KinectSensor.GetDefault();

            sensor.Open();

            bool doQuit = false;

            KinectSensorColorRGBAFrameProvider provider       = new KinectSensorColorRGBAFrameProvider(sensor);
            DynamicColorRGBATextureProcessor   colorProcessor = new DynamicColorRGBATextureProcessor(provider, device);

            KinectPilotProcessor pilot = KinectPilotProcessor.Default;

            KinectSensorBodyFrameProvider bodyFrameProvider = new KinectSensorBodyFrameProvider(sensor);

            bodyFrameProvider.FrameReceived += (sender, args) =>
            {
                var body = args.FrameData.TrackedOnly().ClosestBodies().FirstOrDefault();
                if (body != null)
                {
                    pilot.Process(body.GetJointTable());
                }
            };

            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape)
                                                {
                                                    doQuit = true;
                                                }
            };

            RenderLoop.Run(form, () =>
            {
                if (doQuit)
                {
                    form.Dispose();
                    return;
                }

                colorProcessor.Update(context);

                context.RenderTargetStack.Push(swapChain);

                device.Primitives.ApplyFullTri(context, colorProcessor.Texture.ShaderView);
                device.Primitives.FullScreenTriangle.Draw(context);
                context.RenderTargetStack.Pop();

                context2d.BeginDraw();

                var rect = new SharpDX.RectangleF(0, 0, 200, 130);
                context2d.FillRectangle(rect, blackBrush);
                context2d.DrawText("Elevation: " + pilot.Elevation, textFormat, rect, whiteBrush);
                rect.Top += 30;
                context2d.DrawText("Steering Y: " + pilot.SteeringY, textFormat, rect, whiteBrush);
                rect.Top += 30;
                context2d.DrawText("Steering Z: " + pilot.SterringZ, textFormat, rect, whiteBrush);
                rect.Top += 30;
                context2d.DrawText("Push: " + pilot.Push, textFormat, rect, whiteBrush);
                context2d.EndDraw();


                swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
            });

            swapChain.Dispose();
            context.Dispose();
            device.Dispose();

            colorProcessor.Dispose();
            provider.Dispose();

            sensor.Close();
        }