Example #1
0
    public string CreateAnchor(Vec3 at, string id = null)
    {
        string anchorID = id == null
                        ? Guid.NewGuid().ToString()
                        : id;

        SpatialLocator locator = SpatialLocator.GetDefault();
        SpatialStationaryFrameOfReference stationary = locator.CreateStationaryFrameOfReferenceAtCurrentLocation();
        SpatialAnchor anchor = SpatialAnchor.TryCreateRelativeTo(stationary.CoordinateSystem);
        Pose          pose   = World.FromPerceptionAnchor(anchor);

        Pose newAnchor = pose.ToMatrix().Inverse.Transform(new Pose(at, Quat.Identity));

        anchor = SpatialAnchor.TryCreateRelativeTo(stationary.CoordinateSystem, newAnchor.position, newAnchor.orientation);
        pose   = World.FromPerceptionAnchor(anchor);

        if (anchor != null)
        {
            anchorPoses.Add(anchorID, pose);
        }

        return(anchorStore.TrySave(anchorID, anchor)
                        ? anchorID
                        : null);
    }
Example #2
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.
        }
Example #3
0
        public FingerTracking(SpatialStationaryFrameOfReference referenceFrame, HolographicSpace holographicSpace)
        {
            this.referenceFrame   = referenceFrame;
            this.holographicSpace = holographicSpace;

            interactionManager = SpatialInteractionManager.GetForCurrentView();
            interactionManager.SourceUpdated += this.sourceUpdate;
        }
Example #4
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.
        }
    private void SetHolographicSpace()
    {
        // from Holographic Face Tracking Example
        // Use the default SpatialLocator to track the motion of the device.
        m_locator = SpatialLocator.GetDefault();

        // 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.
        m_referenceFrame = m_locator.CreateStationaryFrameOfReferenceAtCurrentLocation();
    }
Example #6
0
 private void OnLocated(SpatialLocator loc, object args)
 {
     if (frame != null || loc.Locatability != SpatialLocatability.PositionalTrackingActive)
     {
         return;
     }
     frame  = loc.CreateStationaryFrameOfReferenceAtCurrentLocation();
     anchor = SpatialAnchor.TryCreateRelativeTo(frame.CoordinateSystem);
     root   = World.FromPerceptionAnchor(anchor).ToMatrix();
     UpdateBounds(center, radius);
 }
Example #7
0
        //TODO: handle Navigation/Rails (SpatialGestureSettings)

        public GesturesManager(StereoApplication app, SpatialStationaryFrameOfReference referenceFrame)
        {
            this.app            = app;
            this.referenceFrame = referenceFrame;

            tap.Tapped += Tap_Tapped;

            hold.HoldCanceled  += Hold_HoldCanceled;
            hold.HoldCompleted += Hold_HoldCompleted;
            hold.HoldStarted   += Hold_HoldStarted;

            manipulationTranslate.ManipulationCanceled  += ManipulationTranslate_ManipulationCanceled;
            manipulationTranslate.ManipulationCompleted += ManipulationTranslate_ManipulationCompleted;
            manipulationTranslate.ManipulationStarted   += ManipulationTranslate_ManipulationStarted;
            manipulationTranslate.ManipulationUpdated   += ManipulationTranslate_ManipulationUpdated;
        }
Example #8
0
        void OnHolographicDisplayIsAvailableChanged(Object o, Object args)
        {
            // Get the spatial locator for the default HolographicDisplay, if one is available.
            SpatialLocator spatialLocator = null;

            if (canGetDefaultHolographicDisplay)
            {
                HolographicDisplay defaultHolographicDisplay = HolographicDisplay.GetDefault();
                if (defaultHolographicDisplay != null)
                {
                    spatialLocator = defaultHolographicDisplay.SpatialLocator;
                }
            }
            else
            {
                spatialLocator = SpatialLocator.GetDefault();
            }

            if (this.spatialLocator != spatialLocator)
            {
                // If the spatial locator is disconnected or replaced, we should discard any state that was
                // based on it.
                if (this.spatialLocator != null)
                {
                    this.spatialLocator.LocatabilityChanged -= this.OnLocatabilityChanged;
                    this.spatialLocator = null;
                }

                this.stationaryReferenceFrame = null;

                if (spatialLocator != null)
                {
                    // Use the SpatialLocator from the default HolographicDisplay to track the motion of the device.
                    this.spatialLocator = spatialLocator;

                    // Respond to changes in the positional tracking state.
                    this.spatialLocator.LocatabilityChanged += this.OnLocatabilityChanged;

                    // The simplest way to render world-locked holograms is to create a stationary reference frame
                    // based on a SpatialLocator. 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.stationaryReferenceFrame = this.spatialLocator.CreateStationaryFrameOfReferenceAtCurrentLocation();
                }
            }
        }
Example #9
0
    //   int reconstructionID = 0;

    // initialization
    void Start()
    {
        locator = SpatialLocator.GetDefault();
        originFrameOfReference = locator.CreateStationaryFrameOfReferenceAtCurrentLocation();
        audioData         = GetComponent <AudioSource>();
        startHeadPosition = Camera.main.transform.position;
        newHeadPosition   = startHeadPosition;
        textMesh.text     = photoCount.ToString();

        Debug.Log("Airtap to start/stop capture");

        //CreateScene("Test");

        CreateFolder();

        gr              = new GestureRecognizer();
        gr.TappedEvent += Tap;
        gr.StartCapturingGestures();
    }
Example #10
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();
        }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SeeingSharpHolographicsSpacePainter"/> class.
        /// </summary>
        /// <param name="targetWindow">The target window into which to render.</param>
        public SeeingSharpHolographicsSpacePainter(CoreWindow targetWindow)
        {
            m_targetWindow = targetWindow;

            // Call generic initialization
            //  (choose device, create holographic space)
            InitializeHolographicSpace(targetWindow);

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

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

            // 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.
            m_holoSpace.CameraAdded += this.OnHoloSpace_CameraAdded;

            // 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.
            m_holoSpace.CameraRemoved += this.OnHoloSpace_CameraRemoved;

            // 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.
            m_referenceFrame = m_spatialLocator.CreateStationaryFrameOfReferenceAtCurrentLocation();
        }
Example #12
0
 public HoloLensCamera()
 {
     locator = SpatialLocator.GetDefault();
     originalFrameOfReference = locator.CreateStationaryFrameOfReferenceAtCurrentLocation();
 }
        /// <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();
        }
Example #14
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);
        }
 public void ResetReferenceFrame()
 {
     // Allow user to reset the referenceFrame's location
     m_referenceFrame = m_locator.CreateStationaryFrameOfReferenceAtCurrentLocation();
 }
 // Summary:
 //      Handler for manipulation started events. Obtains the stationary frame of reference for the gesture.
 private void OnManipulationStarted(object sender, SpatialManipulationStartedEventArgs e)
 {
     // Manipulation has started - obtain the frame of reference relative to when the gesture began
     stationaryFrameOfReference = spatialLocator.CreateStationaryFrameOfReferenceAtCurrentLocation();
 }