/// <summary>
 ///     Calculate range, altitude delta and bearing
 /// </summary>
 /// <param name="battery"></param>
 /// <param name="target"></param>
 public static Output1 Calculate1(Coords battery, Coords target)
 {
     var output = new Output1();
     double a = target.X - battery.X;
     double b = target.Y - battery.Y;
     output.Range = 10*Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
     output.DeltaAlt = target.Z - battery.Z;
     if (Math.Abs(a) > double.Epsilon)
     {
         output.Bearing = -Math.Atan(b/a)*(180/Math.PI) + 180 - 90*Math.Sign(a);
     }
     else if (b < 0)
     {
         output.Bearing = 180;
     }
     else
     {
         output.Bearing = 0;
     }
     return output;
 }
 public HttpStatusCode CodeFor(Output1 output)
 {
     return HttpStatusCode.Unused;
 }
Exemple #3
0
        public void Start()
        {
            _run = true;
            Factory1 factory = new Factory1();
            //Get first adapter
            Adapter1 adapter = factory.GetAdapter1(0);

            //Get device from adapter
            SharpDX.Direct3D11.Device device = new SharpDX.Direct3D11.Device(adapter);
            //Get front buffer of the adapter
            Output  output  = adapter.GetOutput(0);
            Output1 output1 = output.QueryInterface <Output1>();

            // Width/Height of desktop to capture
            int width  = output.Description.DesktopBounds.Right;
            int height = output.Description.DesktopBounds.Bottom;

            // Create Staging texture CPU-accessible
            Texture2DDescription textureDesc = new Texture2DDescription
            {
                CpuAccessFlags    = CpuAccessFlags.Read,
                BindFlags         = BindFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Width             = width,
                Height            = height,
                OptionFlags       = ResourceOptionFlags.None,
                MipLevels         = 1,
                ArraySize         = 1,
                SampleDescription = { Count = 1, Quality = 0 },
                Usage             = ResourceUsage.Staging
            };
            Texture2D screenTexture = new Texture2D(device, textureDesc);

            Task.Factory.StartNew(() =>
            {
                // Duplicate the output
                using (OutputDuplication duplicatedOutput = output1.DuplicateOutput(device))
                {
                    //try
                    //{



                    Thread.Sleep(2000);
                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    SharpDX.DXGI.Resource screenResource;
                    OutputDuplicateFrameInformation duplicateFrameInformation;

                    // Try to get duplicated frame within given time is ms
                    duplicatedOutput.AcquireNextFrame(15, out duplicateFrameInformation, out screenResource);

                    // copy resource into memory that can be accessed by the CPU
                    using (var screenTexture2D = screenResource.QueryInterface <Texture2D>())
                    {
                        device.ImmediateContext.CopyResource(screenTexture2D, screenTexture);
                    }

                    // Get the desktop capture texture
                    var mapSource = device.ImmediateContext.MapSubresource(screenTexture, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None);

                    // Create Drawing.Bitmap
                    using (var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb))
                    {
                        var boundsRect = new Rectangle(0, 0, width, height);

                        // Copy pixels from screen capture Texture to GDI bitmap
                        var mapDest   = bitmap.LockBits(boundsRect, ImageLockMode.WriteOnly, bitmap.PixelFormat);
                        var sourcePtr = mapSource.DataPointer;
                        var destPtr   = mapDest.Scan0;
                        for (int y = 0; y < height; y++)
                        {
                            // Copy a single line
                            Utilities.CopyMemory(destPtr, sourcePtr, width * 4);

                            // Advance pointers
                            sourcePtr = IntPtr.Add(sourcePtr, mapSource.RowPitch);
                            destPtr   = IntPtr.Add(destPtr, mapDest.Stride);
                        }

                        // Release source and dest locks
                        bitmap.UnlockBits(mapDest);
                        device.ImmediateContext.UnmapSubresource(screenTexture, 0);

                        bitmap.Save("inputOG.png", ImageFormat.Png);
                        //using (var ms = new MemoryStream())
                        //{
                        //    bitmap.Save(ms, ImageFormat.Bmp);
                        //    ScreenRefreshed?.Invoke(this, ms.ToArray());
                        //    _init = true;
                        //}
                    }
                    screenResource.Dispose();
                    duplicatedOutput.ReleaseFrame();


                    Console.WriteLine(sw.Elapsed.TotalMilliseconds);

                    //}
                    //catch (SharpDXException e)
                    //{
                    //    if (e.ResultCode.Code != SharpDX.DXGI.ResultCode.WaitTimeout.Result.Code)
                    //    {
                    //        Trace.TraceError(e.Message);
                    //        Trace.TraceError(e.StackTrace);
                    //    }
                    //}
                }
            });
        }
Exemple #4
0
 public override int GetHashCode()
 {
     return(Output1.GetHashCode() + Output2.GetHashCode());
 }
Exemple #5
0
 public override bool Equals(object other)
 {
     // LUCENENET specific - simplified expression
     return(ReferenceEquals(other, this) || (other is Pair pair && Output1.Equals(pair.Output1) && Output2.Equals(pair.Output2)));
 }
 public HttpStatusCode CodeFor(Output1 output)
 {
     return(HttpStatusCode.Unused);
 }