예제 #1
0
        public WindowsMixedRealityGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
            : base(device, presentationParameters)
        {
            holographicSpace = HolographicSpace.CreateForCoreWindow(CoreWindow.GetForCurrentThread());
            CoreWindow.GetForCurrentThread().Activate();

            Device3         d3DDevice        = device.NativeDevice.QueryInterface <Device3>();
            IDirect3DDevice d3DInteropDevice = null;

            // Acquire the DXGI interface for the Direct3D device.
            using (var dxgiDevice = d3DDevice.QueryInterface <SharpDX.DXGI.Device3>())
            {
                // Wrap the native device using a WinRT interop object.
                uint hr = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out IntPtr pUnknown);

                if (hr == 0)
                {
                    d3DInteropDevice = Marshal.GetObjectForIUnknown(pUnknown) as IDirect3DDevice;
                    Marshal.Release(pUnknown);
                }
            }

            holographicSpace.SetDirect3D11Device(d3DInteropDevice);

            BeginDraw(null);
            ResizeDepthStencilBuffer(backBuffer.Width, backBuffer.Height, 0);

            // Set a dummy back buffer as we use a seperate one for each eye.
            BackBuffer = Texture.New(GraphicsDevice, backBuffer.Description, null);
        }
예제 #2
0
        async void HolographicSpace_CameraAdded(HolographicSpace sender, HolographicSpaceCameraAddedEventArgs args)
        {
            if (!appInited)
            {
                await window.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                {
                    SpatialMappingManager = new SpatialMappingManager();
                    VoiceManager          = new VoiceManager();

                    if (options == null)
                    {
                        options = new ApplicationOptions();
                    }

                    //override some options:
                    options.LimitFps = false;
                    options.Width    = (int)args.Camera.RenderTargetSize.Width;
                    options.Height   = (int)args.Camera.RenderTargetSize.Height;

                    Game = (StereoApplication)Activator.CreateInstance(holoAppType, options);
                    Game.Run();
                    GesturesManager = new GesturesManager(Game, ReferenceFrame);
                    AppStarted?.Invoke(Game);
                    appInited = true;
                });
            }
        }
예제 #3
0
 /// <summary>
 /// Called when the CoreWindow object is created (or re-created).
 /// </summary>
 public void SetWindow(CoreWindow window)
 {
     window.KeyDown           += this.OnKeyPressed;
     window.Closed            += this.OnWindowClosed;
     window.VisibilityChanged += this.OnVisibilityChanged;
     HolographicSpace          = HolographicSpace.CreateForCoreWindow(window);
 }
예제 #4
0
        /// <summary>
        /// Called when the CoreWindow object is created (or re-created).
        /// </summary>
        public void SetWindow(CoreWindow window)
        {
            // Register for keypress notifications.
            window.KeyDown += this.OnKeyPressed;

            // Register for notification that the app window is being closed.
            window.Closed += this.OnWindowClosed;

            // Register for notifications that the app window is losing focus.
            window.VisibilityChanged += this.OnVisibilityChanged;

            // Create a holographic space for the core window for the current view.
            // Presenting holographic frames that are created by this holographic space will put
            // the app into exclusive mode.
            holographicSpace = HolographicSpace.CreateForCoreWindow(window);

            // The DeviceResources class uses the preferred DXGI adapter ID from the holographic
            // space (when available) to create a Direct3D device. The HolographicSpace
            // uses this ID3D11Device to create and manage device-based resources such as
            // swap chains.
            deviceResources.SetHolographicSpace(holographicSpace);

            // The main class uses the holographic space for updates and rendering.
            main.SetHolographicSpace(holographicSpace);
        }
        public HolographicGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters, HolographicSpace holographicSpace)
            : base(device, presentationParameters)
        {
            if (GraphicsDevice.RenderTargetViewAllocator.DescriptorHeap.Description.DescriptorCount != BufferCount)
            {
                GraphicsDevice.RenderTargetViewAllocator.Dispose();
                GraphicsDevice.RenderTargetViewAllocator = new DescriptorAllocator(GraphicsDevice, DescriptorHeapType.RenderTargetView, descriptorCount: BufferCount);
            }

            using (IDXGIDevice dxgiDevice = GraphicsDevice.NativeDirect3D11Device.QueryInterface <IDXGIDevice>())
            {
                IDirect3DDevice direct3DInteropDevice = Direct3DInterop.CreateDirect3DDevice(dxgiDevice);

                HolographicSpace = holographicSpace;
                HolographicSpace.SetDirect3D11Device(direct3DInteropDevice);
            }

            HolographicDisplay = HolographicDisplay.GetDefault();
            SpatialStationaryFrameOfReference = HolographicDisplay.SpatialLocator.CreateStationaryFrameOfReferenceAtCurrentLocation();

            HolographicFrame      = HolographicSpace.CreateNextFrame();
            HolographicSurface    = HolographicFrame.GetRenderingParameters(HolographicFrame.CurrentPrediction.CameraPoses[0]).Direct3D11BackBuffer;
            HolographicBackBuffer = GetHolographicBackBuffer();

            renderTarget           = CreateRenderTarget();
            direct3D11RenderTarget = CreateDirect3D11RenderTarget();
        }
예제 #6
0
        public void SetHolographicSpace(HolographicSpace holographicSpace)
        {
            // Cache the holographic space. Used to re-initalize during device-lost scenarios.
            this.holographicSpace = holographicSpace;

            InitializeUsingHolographicSpace();
        }
        public void OnCameraAdded(
            HolographicSpace sender,
            HolographicSpaceCameraAddedEventArgs args
            )
        {
            Deferral deferral = args.GetDeferral();
            HolographicCamera holographicCamera = args.Camera;

            Task task1 = new Task(() =>
            {
                //
                // TODO: Allocate resources for the new camera and load any content specific to
                //       that camera. Note that the render target size (in pixels) is a property
                //       of the HolographicCamera object, and can be used to create off-screen
                //       render targets that match the resolution of the HolographicCamera.
                //

                // Create device-based resources for the holographic camera and add it to the list of
                // cameras used for updates and rendering. Notes:
                //   * Since this function may be called at any time, the AddHolographicCamera function
                //     waits until it can get a lock on the set of holographic camera resources before
                //     adding the new camera. At 60 frames per second this wait should not take long.
                //   * A subsequent Update will take the back buffer from the RenderingParameters of this
                //     camera's CameraPose and use it to create the ID3D11RenderTargetView for this camera.
                //     Content can then be rendered for the HolographicCamera.
                deviceResources.AddHolographicCamera(holographicCamera);

                // Holographic frame predictions will not include any information about this camera until
                // the deferral is completed.
                deferral.Complete();
            });
            task1.Start();
        }
예제 #8
0
        public void SetHolographicSpace(HolographicSpace holographicSpace)
        {
            this.holographicSpace = holographicSpace;

            //
            // TODO: Add code here to initialize your content.
            //
            // <<NEW>> Set up Event Sub Send
            this.eventHubSend = new EventHubSend();
            // try to send message as test
            Debug.WriteLine("EventHubSendStart:call");
            this.eventHubSend.EventHubSendStart();

#if DRAW_SAMPLE_CONTENT
            // Initialize the sample hologram.
            spinningCubeRenderer = new SpinningCubeRenderer(deviceResources);

            spatialInputHandler = new SpatialInputHandler();
#endif

            // Use the default SpatialLocator to track the motion of the device.
            locator = SpatialLocator.GetDefault();

            // Be able to respond to changes in the positional tracking state.
            locator.LocatabilityChanged += this.OnLocatabilityChanged;

            // Respond to camera added events by creating any resources that are specific
            // to that camera, such as the back buffer render target view.
            // When we add an event handler for CameraAdded, the API layer will avoid putting
            // the new camera in new HolographicFrames until we complete the deferral we created
            // for that handler, or return from the handler without creating a deferral. This
            // allows the app to take more than one frame to finish creating resources and
            // loading assets for the new holographic camera.
            // This function should be registered before the app creates any HolographicFrames.
            holographicSpace.CameraAdded += this.OnCameraAdded;

            // Respond to camera removed events by releasing resources that were created for that
            // camera.
            // When the app receives a CameraRemoved event, it releases all references to the back
            // buffer right away. This includes render target views, Direct2D target bitmaps, and so on.
            // The app must also ensure that the back buffer is not attached as a render target, as
            // shown in DeviceResources.ReleaseResourcesForBackBuffer.
            holographicSpace.CameraRemoved += this.OnCameraRemoved;

            // The simplest way to render world-locked holograms is to create a stationary reference frame
            // when the app is launched. This is roughly analogous to creating a "world" coordinate system
            // with the origin placed at the device's position as the app is launched.
            referenceFrame = locator.CreateStationaryFrameOfReferenceAtCurrentLocation();

            // Notes on spatial tracking APIs:
            // * Stationary reference frames are designed to provide a best-fit position relative to the
            //   overall space. Individual positions within that reference frame are allowed to drift slightly
            //   as the device learns more about the environment.
            // * When precise placement of individual holograms is required, a SpatialAnchor should be used to
            //   anchor the individual hologram to a position in the real world - for example, a point the user
            //   indicates to be of special interest. Anchor positions do not drift, but can be corrected; the
            //   anchor will use the corrected position starting in the next frame after the correction has
            //   occurred.
        }
예제 #9
0
        public HolographicGameContext(HolographicSpace?holographicSpace = null, CoreWindow?control = null)
            : base(control ?? CoreWindow.GetForCurrentThread())
        {
            HolographicSpace = holographicSpace ?? HolographicSpace.CreateForCoreWindow(Control);

            PresentationParameters.BackBufferWidth  = (int)Control.Bounds.Width;
            PresentationParameters.BackBufferHeight = (int)Control.Bounds.Width;
        }
예제 #10
0
        public FingerTracking(SpatialStationaryFrameOfReference referenceFrame, HolographicSpace holographicSpace)
        {
            this.referenceFrame   = referenceFrame;
            this.holographicSpace = holographicSpace;

            interactionManager = SpatialInteractionManager.GetForCurrentView();
            interactionManager.SourceUpdated += this.sourceUpdate;
        }
예제 #11
0
 /// <summary>
 /// Called when the CoreWindow object is created (or re-created).
 /// </summary>
 public void SetWindow(CoreWindow window)
 {
     window.KeyDown           += OnKeyDown;
     window.KeyUp             += OnKeyUp;
     window.Closed            += OnWindowClosed;
     window.VisibilityChanged += this.OnVisibilityChanged;
     HolographicSpace          = HolographicSpace.CreateForCoreWindow(window);
     WindowIsSet?.Invoke(window);
 }
예제 #12
0
        public void SetHolographicSpace(HolographicSpace holographicSpace)
        {
            this.holographicSpace = holographicSpace;

            //Task.Factory.StartNew(RunAppScript).Wait();
            try
            {
                host      = new ChakraHost();
                appScript = System.IO.File.ReadAllText(@"Assets/js/app.js");
                host.SetHolographicSpace(this.holographicSpace);
                host.RunScript(appScript);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            };

            // Use the default SpatialLocator to track the motion of the device.
            locator = SpatialLocator.GetDefault();

            // Be able to respond to changes in the positional tracking state.
            locator.LocatabilityChanged += this.OnLocatabilityChanged;

            // Respond to camera added events by creating any resources that are specific
            // to that camera, such as the back buffer render target view.
            // When we add an event handler for CameraAdded, the API layer will avoid putting
            // the new camera in new HolographicFrames until we complete the deferral we created
            // for that handler, or return from the handler without creating a deferral. This
            // allows the app to take more than one frame to finish creating resources and
            // loading assets for the new holographic camera.
            // This function should be registered before the app creates any HolographicFrames.
            holographicSpace.CameraAdded += this.OnCameraAdded;

            // Respond to camera removed events by releasing resources that were created for that
            // camera.
            // When the app receives a CameraRemoved event, it releases all references to the back
            // buffer right away. This includes render target views, Direct2D target bitmaps, and so on.
            // The app must also ensure that the back buffer is not attached as a render target, as
            // shown in DeviceResources.ReleaseResourcesForBackBuffer.
            holographicSpace.CameraRemoved += this.OnCameraRemoved;

            // The simplest way to render world-locked holograms is to create a stationary reference frame
            // when the app is launched. This is roughly analogous to creating a "world" coordinate system
            // with the origin placed at the device's position as the app is launched.
            referenceFrame = locator.CreateStationaryFrameOfReferenceAtCurrentLocation();

            // Notes on spatial tracking APIs:
            // * Stationary reference frames are designed to provide a best-fit position relative to the
            //   overall space. Individual positions within that reference frame are allowed to drift slightly
            //   as the device learns more about the environment.
            // * When precise placement of individual holograms is required, a SpatialAnchor should be used to
            //   anchor the individual hologram to a position in the real world - for example, a point the user
            //   indicates to be of special interest. Anchor positions do not drift, but can be corrected; the
            //   anchor will use the corrected position starting in the next frame after the correction has
            //   occurred.
        }
예제 #13
0
        public void SetHolographicSpace(HolographicSpace holographicSpace)
        {
            this.holographicSpace = holographicSpace;

            //
            // TODO: Add code here to initialize your content.
            //

#if DRAW_SAMPLE_CONTENT
            // Initialize the sample hologram.
            spinningCubeRenderer = new SpinningCubeRenderer(deviceResources);

            spatialInputHandler = new SpatialInputHandler();
#endif

            if (canGetDefaultHolographicDisplay)
            {
                // Subscribe for notifications about changes to the state of the default HolographicDisplay
                // and its SpatialLocator.
                HolographicSpace.IsAvailableChanged += this.OnHolographicDisplayIsAvailableChanged;
            }

            // Acquire the current state of the default HolographicDisplay and its SpatialLocator.
            OnHolographicDisplayIsAvailableChanged(null, null);

            // Respond to camera added events by creating any resources that are specific
            // to that camera, such as the back buffer render target view.
            // When we add an event handler for CameraAdded, the API layer will avoid putting
            // the new camera in new HolographicFrames until we complete the deferral we created
            // for that handler, or return from the handler without creating a deferral. This
            // allows the app to take more than one frame to finish creating resources and
            // loading assets for the new holographic camera.
            // This function should be registered before the app creates any HolographicFrames.
            holographicSpace.CameraAdded += this.OnCameraAdded;

            // Respond to camera removed events by releasing resources that were created for that
            // camera.
            // When the app receives a CameraRemoved event, it releases all references to the back
            // buffer right away. This includes render target views, Direct2D target bitmaps, and so on.
            // The app must also ensure that the back buffer is not attached as a render target, as
            // shown in DeviceResources.ReleaseResourcesForBackBuffer.
            holographicSpace.CameraRemoved += this.OnCameraRemoved;

            // Notes on spatial tracking APIs:
            // * Stationary reference frames are designed to provide a best-fit position relative to the
            //   overall space. Individual positions within that reference frame are allowed to drift slightly
            //   as the device learns more about the environment.
            // * When precise placement of individual holograms is required, a SpatialAnchor should be used to
            //   anchor the individual hologram to a position in the real world - for example, a point the user
            //   indicates to be of special interest. Anchor positions do not drift, but can be corrected; the
            //   anchor will use the corrected position starting in the next frame after the correction has
            //   occurred.
        }
예제 #14
0
        private void ApplicationView_Activated(CoreApplicationView sender, IActivatedEventArgs e)
        {
            if (HolographicApplicationPreview.IsCurrentViewPresentedOnHolographicDisplay())
            {
                HolographicSpace holographicSpace = HolographicSpace.CreateForCoreWindow(sender.CoreWindow);

                gameContext = new HolographicGameContext(holographicSpace);
            }
            else
            {
                gameContext = new CoreWindowGameContext();
            }

            sender.CoreWindow.Activate();
        }
예제 #15
0
        /// <summary>
        /// Camera removed
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="args">The args</param>
        public void OnCameraRemoved(HolographicSpace sender, HolographicSpaceCameraRemovedEventArgs args)
        {
            Task task2 = new Task(() =>
            {
            });

            task2.Start();

            // Before letting this callback return, ensure that all references to the back buffer
            // are released.
            // Since this function may be called at any time, the RemoveHolographicCamera function
            // waits until it can get a lock on the set of holographic camera resources before
            // deallocating resources for this camera. At 60 frames per second this wait should
            // not take long.
            this.deviceResources.RemoveHolographicCamera(args.Camera);
        }
예제 #16
0
        /// <summary>
        /// Called when the CoreWindow object is created (or re-created).
        /// </summary>
        public void SetWindow(CoreWindow window)
        {
            ApplicationView.GetForCurrentView().Consolidated += AppView_Consolidated;

            // Register event handlers for app lifecycle.
            CoreApplication.Suspending += this.OnSuspending;
            CoreApplication.Resuming   += this.OnResuming;

            // Register for keypress notifications.
            window.KeyDown += this.OnKeyPressed;

            // Register for notification that the app window is being closed.
            window.Closed += this.OnWindowClosed;

            // Register for notifications that the app window is losing focus.
            window.VisibilityChanged += this.OnVisibilityChanged;

            // At this point we have access to the device and we can create device-dependent
            // resources.
            deviceResources = new DeviceResources();

            main = new _360VideoPlaybackMain(deviceResources);

            // Create a holographic space for the core window for the current view.
            // Presenting holographic frames that are created by this holographic space will put
            // the app into exclusive mode.
            holographicSpace = HolographicSpace.CreateForCoreWindow(window);

            // The DeviceResources class uses the preferred DXGI adapter ID from the holographic
            // space (when available) to create a Direct3D device. The HolographicSpace
            // uses this ID3D11Device to create and manage device-based resources such as
            // swap chains.
            deviceResources.SetHolographicSpace(holographicSpace);

            // The main class uses the holographic space for updates and rendering.
            main.SetHolographicSpace(holographicSpace);

            MediaSource source = MediaSource.CreateFromUri(sourceUri);

            mediaPlayer.MediaOpened += MediaPlayer_MediaOpened;
            mediaPlayer.Source       = source;// Windows.Media.Core.MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/video.mp4"));

            mediaPlayer.IsVideoFrameServerEnabled = true;
            mediaPlayer.IsLoopingEnabled          = true;
        }
예제 #17
0
        public void SetHolographicSpace(HolographicSpace holographicSpace)
        {
            this.holographicSpace = holographicSpace;

#if DRAW_SAMPLE_CONTENT
            // Initialize the sample hologram.
            var gap  = 0.016f;
            var size = .15f;
            quadRendererR = new QuadRenderer(deviceResources, size, new Vector3(gap, -size / 4, -.2f), "Guitar_R_001.jpg");
            quadRendererL = new QuadRenderer(deviceResources, size, new Vector3(-(size + gap), -size / 4, -.2f), "Guitar_L_001.jpg");

            spatialInputHandler = new SpatialInputHandler();
#endif

            // Respond to camera added events by creating any resources that are specific
            // to that camera, such as the back buffer render target view.
            // When we add an event handler for CameraAdded, the API layer will avoid putting
            // the new camera in new HolographicFrames until we complete the deferral we created
            // for that handler, or return from the handler without creating a deferral. This
            // allows the app to take more than one frame to finish creating resources and
            // loading assets for the new holographic camera.
            // This function should be registered before the app creates any HolographicFrames.
            holographicSpace.CameraAdded += this.OnCameraAdded;

            // Respond to camera removed events by releasing resources that were created for that
            // camera.
            // When the app receives a CameraRemoved event, it releases all references to the back
            // buffer right away. This includes render target views, Direct2D target bitmaps, and so on.
            // The app must also ensure that the back buffer is not attached as a render target, as
            // shown in DeviceResources.ReleaseResourcesForBackBuffer.
            holographicSpace.CameraRemoved += this.OnCameraRemoved;

            // Notes on spatial tracking APIs:
            // * Stationary reference frames are designed to provide a best-fit position relative to the
            //   overall space. Individual positions within that reference frame are allowed to drift slightly
            //   as the device learns more about the environment.
            // * When precise placement of individual holograms is required, a SpatialAnchor should be used to
            //   anchor the individual hologram to a position in the real world - for example, a point the user
            //   indicates to be of special interest. Anchor positions do not drift, but can be corrected; the
            //   anchor will use the corrected position starting in the next frame after the correction has
            //   occurred.
        }
예제 #18
0
        /// <summary>
        /// Called when the CoreWindow object is created (or re-created).
        /// </summary>
        public void SetWindow(CoreWindow window)
        {
            // Register for keypress notifications.
            window.KeyDown += this.OnKeyPressed;

            // Register for notification that the app window is being closed.
            window.Closed += this.OnWindowClosed;

            // Register for notifications that the app window is losing focus.
            window.VisibilityChanged += this.OnVisibilityChanged;

            // Create a holographic space for the core window for the current view.
            // Presenting holographic frames that are created by this holographic space will put
            // the app into exclusive mode.
            this.holographicSpace = HolographicSpace.CreateForCoreWindow(window);

            // The main class uses the holographic space for updates and rendering.
            this.main.SetHolographicSpace(this.holographicSpace);
            this.main.Initialize();
        }
예제 #19
0
        private void InitializeHolographicSpace(CoreWindow targetWindow)
        {
            // Create the holographic space
            m_holoSpace = HolographicSpace.CreateForCoreWindow(targetWindow);

            // The holographic space might need to determine which adapter supports
            // holograms, in which case it will specify a non-zero PrimaryAdapterId.
            int   shiftPos = sizeof(uint);
            ulong id       = (ulong)m_holoSpace.PrimaryAdapterId.LowPart | (((ulong)m_holoSpace.PrimaryAdapterId.HighPart) << shiftPos);

            // Get the device with the luid or get the default device of the current system
            if (id != 0)
            {
                m_hostDevice = GraphicsCore.Current.TryGetDeviceByLuid((long)id);
            }
            if (m_hostDevice == null)
            {
                m_hostDevice = GraphicsCore.Current.DefaultDevice;
            }

            // Acquire the DXGI interface for the Direct3D device.
            D3D11.Device3 d3dDevice = m_hostDevice.Device3D11_3;
            using (var dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device3>())
            {
                // Wrap the native device using a WinRT interop object.
                IntPtr pUnknown;
                UInt32 hr = NativeMethods.CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out pUnknown);
                if (hr == 0)
                {
                    m_d3dInteropDevice = (MS_D3D11.IDirect3DDevice)Marshal.GetObjectForIUnknown(pUnknown);
                    Marshal.Release(pUnknown);
                }

                // Store a pointer to the DXGI adapter.
                // This is for the case of no preferred DXGI adapter, or fallback to WARP.
                m_dxgiAdapter = dxgiDevice.Adapter.QueryInterface <SharpDX.DXGI.Adapter3>();
            }

            // Set the Direct3D device on the holographic space
            m_holoSpace.SetDirect3D11Device(m_d3dInteropDevice);
        }
예제 #20
0
        /// <summary>
        /// Set holographic space
        /// </summary>
        /// <param name="holographicSpace">The holographic space</param>
        public void SetHolographicSpace(HolographicSpace holographicSpace)
        {
            // The DeviceResources class uses the preferred DXGI adapter ID from the holographic
            // space (when available) to create a Direct3D device. The HolographicSpace
            // uses this ID3D11Device to create and manage device-based resources such as
            // swap chains.
            this.deviceResources.SetHolographicSpace(holographicSpace);

            this.holographicSpace = holographicSpace;

            // Use the default SpatialLocator to track the motion of the device.
            this.locator = SpatialLocator.GetDefault();

            // Be able to respond to changes in the positional tracking state.
            this.locator.LocatabilityChanged += this.OnLocatabilityChanged;

            // Respond to camera added events by creating any resources that are specific
            // to that camera, such as the back buffer render target view.
            // When we add an event handler for CameraAdded, the API layer will avoid putting
            // the new camera in new HolographicFrames until we complete the deferral we created
            // for that handler, or return from the handler without creating a deferral. This
            // allows the app to take more than one frame to finish creating resources and
            // loading assets for the new holographic camera.
            // This function should be registered before the app creates any HolographicFrames.
            holographicSpace.CameraAdded += this.OnCameraAdded;

            // Respond to camera removed events by releasing resources that were created for that
            // camera.
            // When the app receives a CameraRemoved event, it releases all references to the back
            // buffer right away. This includes render target views, Direct2D target bitmaps, and so on.
            // The app must also ensure that the back buffer is not attached as a render target, as
            // shown in DeviceResources.ReleaseResourcesForBackBuffer.
            holographicSpace.CameraRemoved += this.OnCameraRemoved;

            // The simplest way to render world-locked holograms is to create a stationary reference frame
            // when the app is launched. This is roughly analogous to creating a "world" coordinate system
            // with the origin placed at the device's position as the app is launched.
            this.ReferenceFrame = this.locator.CreateStationaryFrameOfReferenceAtCurrentLocation();
        }
예제 #21
0
        public void OnCameraRemoved(
            HolographicSpace sender,
            HolographicSpaceCameraRemovedEventArgs args
            )
        {
            var task2 = new Task(() => {
                //
                // TODO: Asynchronously unload or deactivate content resources (not back buffer
                //       resources) that are specific only to the camera that was removed.
                //
            });

            task2.Start();

            // Before letting this callback return, ensure that all references to the back buffer
            // are released.
            // Since this function may be called at any time, the RemoveHolographicCamera function
            // waits until it can get a lock on the set of holographic camera resources before
            // deallocating resources for this camera. At 60 frames per second this wait should
            // not take long.
            _deviceResources.RemoveHolographicCamera(args.Camera);
        }
예제 #22
0
        public unsafe void Run()
        {
            LoadAssets(new[] { assetsPakName == null ? null : assetsPakName + ".pak" });
            CoreWindow.GetForCurrentThread().CustomProperties.Add("HolographicSpace", HolographicSpace);
            InitializeSpace();
            InteractionManager = SpatialInteractionManager.GetForCurrentView();
            InteractionManager.InteractionDetected += (s, e) => GesturesManager?.HandleInteraction(e.Interaction);

            while (!windowClosed)
            {
                if (assetsLoaded && !appInited)
                {
                    SpatialMappingManager = new SpatialMappingManager();
                    appInited             = true;
                    Game = (HoloApplication)Activator.CreateInstance(holoAppType, assetsPakName, false);
                    Game.Run();
                    Game.Engine.PostUpdate += e => currentFrame?.UpdateCurrentPrediction();
                    GesturesManager         = new GesturesManager(Game, ReferenceFrame);
                }

                if (windowVisible && (null != HolographicSpace))
                {
                    if (Game != null)
                    {
                        currentFrame = HolographicSpace.CreateNextFrame();

                        var prediction = currentFrame.CurrentPrediction;
                        if (prediction.CameraPoses.Count < 1)
                        {
                            continue;
                        }
                        var cameraPose = prediction.CameraPoses[0];

                        var viewBox = cameraPose.TryGetViewTransform(ReferenceFrame.CoordinateSystem);
                        if (viewBox != null)
                        {
                            Matrix4x4 leftViewMatrixDx  = viewBox.Value.Left;
                            Matrix4x4 rightViewMatrixDx = viewBox.Value.Right;
                            Matrix4x4 leftProjMatrixDx  = cameraPose.ProjectionTransform.Left;
                            Matrix4x4 rightProjMatrixDx = cameraPose.ProjectionTransform.Right;

                            Matrix4 leftViewMatrixUrho  = *(Matrix4 *)(void *)&leftViewMatrixDx;
                            Matrix4 rightViewMatrixUrho = *(Matrix4 *)(void *)&rightViewMatrixDx;
                            Matrix4 leftProjMatrixUrho  = *(Matrix4 *)(void *)&leftProjMatrixDx;
                            Matrix4 rightProjMatrixUrho = *(Matrix4 *)(void *)&rightProjMatrixDx;
                            Game.UpdateStereoView(leftViewMatrixUrho, rightViewMatrixUrho, leftProjMatrixUrho, rightProjMatrixUrho);
                        }

                        var parameters = currentFrame.GetRenderingParameters(cameraPose);
                        if (Game.FocusWorldPoint != Vector3.Zero)
                        {
                            parameters.SetFocusPoint(ReferenceFrame.CoordinateSystem,
                                                     new System.Numerics.Vector3(
                                                         Game.FocusWorldPoint.X,
                                                         Game.FocusWorldPoint.Y,
                                                         -Game.FocusWorldPoint.Z));                //LH->RH
                        }
                        Game.Engine.RunFrame();
                        currentFrame.PresentUsingCurrentPrediction(HolographicFramePresentWaitBehavior.WaitForFrameToFinish);
                    }
                    CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);
                }
                else
                {
                    CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessOneAndAllPending);
                }
            }
        }
 public override void BeginDraw(CommandList commandList)
 {
     HolographicFrame      = HolographicSpace.CreateNextFrame();
     HolographicBackBuffer = GetHolographicBackBuffer();
 }
예제 #24
0
 public void SetHolographicSpace(HolographicSpace holographicSpace)
 {
     window.holographicSpace = holographicSpace;
 }
예제 #25
0
        public unsafe void Run()
        {
            AppStarting?.Invoke();
            ReferenceFrame = SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation();

            var coreWindow = CoreWindow.GetForCurrentThread();

            coreWindow.CustomProperties.Add(nameof(HolographicSpace), HolographicSpace);

            InitializeSpace();
            InteractionManager = SpatialInteractionManager.GetForCurrentView();
            InteractionManager.InteractionDetected += (s, e) => GesturesManager?.HandleInteraction(e.Interaction);

            while (!windowClosed)
            {
                if (!appInited)
                {
                    SpatialMappingManager = new SpatialMappingManager();
                    VoiceManager          = new VoiceManager();
                    appInited             = true;

                    if (options == null)
                    {
                        options = new ApplicationOptions();
                    }

                    //override some options:
                    options.LimitFps = false;
                    options.Width    = 1268;                  //TODO: find system
                    options.Height   = 720;

                    Game = (HoloApplication)Activator.CreateInstance(holoAppType, options);
                    Game.Run();
                    GesturesManager = new GesturesManager(Game, ReferenceFrame);
                    AppStarted?.Invoke(Game);
                }

                if (windowVisible && (null != HolographicSpace))
                {
                    if (Game != null)
                    {
                        CurrentFrame = HolographicSpace.CreateNextFrame();
                        CurrentFrame.UpdateCurrentPrediction();
                        var prediction = CurrentFrame.CurrentPrediction;
                        if (prediction.CameraPoses.Count < 1)
                        {
                            continue;
                        }
                        var cameraPose = prediction.CameraPoses[0];

                        var viewBox = cameraPose.TryGetViewTransform(ReferenceFrame.CoordinateSystem);
                        if (viewBox != null)
                        {
                            Matrix4x4 leftViewMatrixDx  = viewBox.Value.Left;
                            Matrix4x4 rightViewMatrixDx = viewBox.Value.Right;
                            Matrix4x4 leftProjMatrixDx  = cameraPose.ProjectionTransform.Left;
                            Matrix4x4 rightProjMatrixDx = cameraPose.ProjectionTransform.Right;

                            Matrix4 leftViewMatrixUrho  = *(Matrix4 *)(void *)&leftViewMatrixDx;
                            Matrix4 rightViewMatrixUrho = *(Matrix4 *)(void *)&rightViewMatrixDx;
                            Matrix4 leftProjMatrixUrho  = *(Matrix4 *)(void *)&leftProjMatrixDx;
                            Matrix4 rightProjMatrixUrho = *(Matrix4 *)(void *)&rightProjMatrixDx;
                            Game.UpdateStereoView(leftViewMatrixUrho, rightViewMatrixUrho, leftProjMatrixUrho, rightProjMatrixUrho);
                        }

                        var parameters = CurrentFrame.GetRenderingParameters(cameraPose);
                        if (Game.FocusWorldPoint != Vector3.Zero)
                        {
                            parameters.SetFocusPoint(ReferenceFrame.CoordinateSystem,
                                                     new System.Numerics.Vector3(
                                                         Game.FocusWorldPoint.X,
                                                         Game.FocusWorldPoint.Y,
                                                         -Game.FocusWorldPoint.Z));                //LH->RH
                        }
                        Game.Engine.RunFrame();
                        CurrentFrame.PresentUsingCurrentPrediction(HolographicFramePresentWaitBehavior.WaitForFrameToFinish);
                    }
                    CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);
                }
                else
                {
                    CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessOneAndAllPending);
                }
            }
        }
예제 #26
0
        /// <summary>
        /// Called when the CoreWindow object is created (or re-created).
        /// </summary>
        public void SetWindow(CoreWindow window)
        {
            // Register for keypress notifications.
            window.KeyDown += this.OnKeyPressed;

            // Register for notification that the app window is being closed.
            window.Closed += this.OnWindowClosed;

            // Register for notifications that the app window is losing focus.
            window.VisibilityChanged += this.OnVisibilityChanged;

            // Create a holographic space for the core window for the current view.
            // Presenting holographic frames that are created by this holographic space will put
            // the app into exclusive mode.
            this.holographicSpace = HolographicSpace.CreateForCoreWindow(window);

            // The main class uses the holographic space for updates and rendering.
            this.main.SetHolographicSpace(this.holographicSpace);
            this.main.Initialize();
        }
예제 #27
0
        public unsafe void Run()
        {
            AppStarting?.Invoke();
            ReferenceFrame = SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation();

            var coreWindow = CoreWindow.GetForCurrentThread();

            coreWindow.CustomProperties.Add(nameof(HolographicSpace), HolographicSpace);

            InitializeSpace();
            HolographicSpace.CameraAdded += HolographicSpace_CameraAdded;
            InteractionManager            = SpatialInteractionManager.GetForCurrentView();
            if (InteractionManager != null)
            {
                InteractionManager.InteractionDetected += (s, e) => GesturesManager?.HandleInteraction(e.Interaction);
            }

            while (!windowClosed)
            {
                if (appInited && windowVisible && (null != HolographicSpace))
                {
                    if (Game != null)
                    {
                        CurrentFrame = HolographicSpace.CreateNextFrame();
                        CurrentFrame.UpdateCurrentPrediction();
                        var prediction = CurrentFrame.CurrentPrediction;
                        if (prediction.CameraPoses.Count < 1)
                        {
                            continue;
                        }
                        var cameraPose = prediction.CameraPoses[0];

                        var viewBox = cameraPose.TryGetViewTransform(ReferenceFrame.CoordinateSystem);
                        if (viewBox != null)
                        {
                            Matrix4x4 leftViewMatrixDx  = viewBox.Value.Left;
                            Matrix4x4 rightViewMatrixDx = viewBox.Value.Right;
                            Matrix4x4 leftProjMatrixDx  = cameraPose.ProjectionTransform.Left;
                            Matrix4x4 rightProjMatrixDx = cameraPose.ProjectionTransform.Right;

                            Matrix4 leftViewMatrixUrho  = *(Matrix4 *)(void *)&leftViewMatrixDx;
                            Matrix4 rightViewMatrixUrho = *(Matrix4 *)(void *)&rightViewMatrixDx;
                            Matrix4 leftProjMatrixUrho  = *(Matrix4 *)(void *)&leftProjMatrixDx;
                            Matrix4 rightProjMatrixUrho = *(Matrix4 *)(void *)&rightProjMatrixDx;
                            Game.UpdateStereoView(leftViewMatrixUrho, rightViewMatrixUrho, leftProjMatrixUrho, rightProjMatrixUrho);
                        }

                        var parameters = CurrentFrame.GetRenderingParameters(cameraPose);
                        if (Game.FocusWorldPoint != Vector3.Zero)
                        {
                            parameters.SetFocusPoint(ReferenceFrame.CoordinateSystem,
                                                     new System.Numerics.Vector3(
                                                         Game.FocusWorldPoint.X,
                                                         Game.FocusWorldPoint.Y,
                                                         -Game.FocusWorldPoint.Z));                //LH->RH
                        }
                        Game.Engine.RunFrame();
                        CurrentFrame.PresentUsingCurrentPrediction(HolographicFramePresentWaitBehavior.WaitForFrameToFinish);
                    }
                    CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);
                }
                else
                {
                    CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessOneAndAllPending);
                }
            }
        }
예제 #28
0
        //~CanvasRenderingContextHolographicSpace()
        //{
        //    deviceContext.MakeCurrent(IntPtr.Zero);
        //    deviceContext.DeleteContext(context);
        //}

        private IntPtr CreateEglContext(HolographicSpace holographicSpace, SpatialStationaryFrameOfReference stationaryReferenceFrame)
        {
            IntPtr context;

            int[] configAttribs = new int[]
            {
                Egl.RED_SIZE, 8,
                Egl.GREEN_SIZE, 8,
                Egl.BLUE_SIZE, 8,
                Egl.ALPHA_SIZE, 8,
                Egl.DEPTH_SIZE, 8,
                Egl.STENCIL_SIZE, 8,
                Egl.NONE
            };

            int[] contextAttribs = new int[]
            {
                Egl.CONTEXT_CLIENT_VERSION, 2,
                Egl.NONE
            };

            int[] surfaceAttribs = new int[] {
                EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER, Egl.TRUE,
                Egl.NONE
            };

            int[] defaultDisplayAttribs = new int[]
            {
                EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
                EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, Egl.TRUE,
                EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, Egl.TRUE,
                Egl.NONE
            };

            int[] fl9_3DisplayAttributes = new int[]
            {
                // These can be used to request ANGLE's D3D11 renderer, with D3D11 Feature Level 9_3.
                // These attributes are used if the call to eglInitialize fails with the default display attributes.
                EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
                EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9,
                EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3,
                EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, Egl.TRUE,
                EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, Egl.TRUE,
                Egl.NONE
            };

            int[] warpDisplayAttributes = new int[]
            {
                // These attributes can be used to request D3D11 WARP.
                // They are used if eglInitialize fails with both the default display attributes and the 9_3 display attributes.
                EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
                EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE,
                EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, Egl.TRUE,
                EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, Egl.TRUE,
                Egl.NONE
            };

            int[]    configCount = new int[1];
            IntPtr[] configs     = new IntPtr[8];

            if (Egl.BindAPI(Egl.OPENGL_ES_API) == false)
            {
                throw new InvalidOperationException("No OpenGL ES API");
            }

            if ((display = Egl.GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, IntPtr.Zero, defaultDisplayAttribs)) == IntPtr.Zero)
            {
                throw new InvalidOperationException("Unable to get EGL display");
            }

            if (!Egl.Initialize(display, null, null))
            {
                if ((display = Egl.GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, IntPtr.Zero, fl9_3DisplayAttributes)) == IntPtr.Zero)
                {
                    throw new InvalidOperationException("Unable to get EGL display");
                }

                if (!Egl.Initialize(display, null, null))
                {
                    if ((display = Egl.GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, IntPtr.Zero, warpDisplayAttributes)) == IntPtr.Zero)
                    {
                        throw new InvalidOperationException("Unable to get EGL display");
                    }

                    if (!Egl.Initialize(display, null, null))
                    {
                        throw new InvalidOperationException("Unable to initialize EGL");
                    }
                }
            }

            if (!Egl.ChooseConfig(display, configAttribs, configs, 1, configCount))
            {
                throw new InvalidOperationException("Unable to choose configuration");
            }

            holographicSpaceHandle = GCHandle.Alloc(holographicSpace);
            IntPtr holographicSpacePointer = Marshal.GetIUnknownForObject(holographicSpace);

            //PropertySet surfaceCreationProperties = new PropertySet
            //{
            //    { "EGLNativeWindowTypeProperty", (IntPtr)holographicSpaceHandle }
            //};

            PropertySet surfaceCreationProperties = new PropertySet();

            surfaceCreationProperties.Add("EGLNativeWindowTypeProperty", holographicSpacePointer);

            //if (stationaryReferenceFrame != null)
            //{
            //    stationaryReferenceFrameHandle = GCHandle.Alloc(stationaryReferenceFrame);
            //    surfaceCreationProperties.Add("EGLBaseCoordinateSystemProperty", (IntPtr)stationaryReferenceFrameHandle);
            //}

            GCHandle surfaceCreationPropertiesHandle = GCHandle.Alloc(surfaceCreationProperties);

            IntPtr surfaceCreationPropertiesPointer = Marshal.GetIUnknownForObject(surfaceCreationProperties);

            if ((surface = Egl.CreateWindowSurface(display, configs[0], surfaceCreationPropertiesPointer, surfaceAttribs)) == IntPtr.Zero)
            {
                throw new InvalidOperationException("Unable to create EGL fullscreen surface");
            }

            if ((context = Egl.CreateContext(display, configs[0], IntPtr.Zero, contextAttribs)) == IntPtr.Zero)
            {
                throw new InvalidOperationException("Unable to create context");
            }

            return(context);
        }
        /// <summary>
        /// Camera added
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="args">The args</param>
        public void OnCameraAdded(HolographicSpace sender, HolographicSpaceCameraAddedEventArgs args)
        {
            Deferral deferral = args.GetDeferral();
            HolographicCamera holographicCamera = args.Camera;

            Task task1 = new Task(() =>
            {
                // Create device-based resources for the holographic camera and add it to the list of
                // cameras used for updates and rendering. Notes:
                //   * Since this function may be called at any time, the AddHolographicCamera function
                //     waits until it can get a lock on the set of holographic camera resources before
                //     adding the new camera. At 60 frames per second this wait should not take long.
                //   * A subsequent Update will take the back buffer from the RenderingParameters of this
                //     camera's CameraPose and use it to create the ID3D11RenderTargetView for this camera.
                //     Content can then be rendered for the HolographicCamera.
                deviceResources.AddHolographicCamera(holographicCamera);

                // Holographic frame predictions will not include any information about this camera until
                // the deferral is completed.
                deferral.Complete();
            });

            task1.Start();
        }
        /// <summary>
        /// Set holographic space
        /// </summary>
        /// <param name="holographicSpace">The holographic space</param>
        public void SetHolographicSpace(HolographicSpace holographicSpace)
        {
            // The DeviceResources class uses the preferred DXGI adapter ID from the holographic
            // space (when available) to create a Direct3D device. The HolographicSpace
            // uses this ID3D11Device to create and manage device-based resources such as
            // swap chains.
            this.deviceResources.SetHolographicSpace(holographicSpace);

            this.holographicSpace = holographicSpace;

            // Use the default SpatialLocator to track the motion of the device.
            this.locator = SpatialLocator.GetDefault();

            // Be able to respond to changes in the positional tracking state.
            this.locator.LocatabilityChanged += this.OnLocatabilityChanged;

            // Respond to camera added events by creating any resources that are specific
            // to that camera, such as the back buffer render target view.
            // When we add an event handler for CameraAdded, the API layer will avoid putting
            // the new camera in new HolographicFrames until we complete the deferral we created
            // for that handler, or return from the handler without creating a deferral. This
            // allows the app to take more than one frame to finish creating resources and
            // loading assets for the new holographic camera.
            // This function should be registered before the app creates any HolographicFrames.
            holographicSpace.CameraAdded += this.OnCameraAdded;

            // Respond to camera removed events by releasing resources that were created for that
            // camera.
            // When the app receives a CameraRemoved event, it releases all references to the back
            // buffer right away. This includes render target views, Direct2D target bitmaps, and so on.
            // The app must also ensure that the back buffer is not attached as a render target, as
            // shown in DeviceResources.ReleaseResourcesForBackBuffer.
            holographicSpace.CameraRemoved += this.OnCameraRemoved;

            // The simplest way to render world-locked holograms is to create a stationary reference frame
            // when the app is launched. This is roughly analogous to creating a "world" coordinate system
            // with the origin placed at the device's position as the app is launched.
            this.ReferenceFrame = this.locator.CreateStationaryFrameOfReferenceAtCurrentLocation();
        }
        public void OnCameraRemoved(HolographicSpace sender, HolographicSpaceCameraRemovedEventArgs args)
        {
            Task task2 = new Task(() =>
            {
            });
            task2.Start();

            // Before letting this callback return, ensure that all references to the back buffer
            // are released.
            // Since this function may be called at any time, the RemoveHolographicCamera function
            // waits until it can get a lock on the set of holographic camera resources before
            // deallocating resources for this camera. At 60 frames per second this wait should
            // not take long.
            this.deviceResources.RemoveHolographicCamera(args.Camera);
        }