Leaving breadcrumbs

The solution to this example was inspired in part by the fairy tale Hansel and Gretelspecifically, the part where the main characters in the story leave a trail of breadcrumbs to keep track of their location as they are led deep into the forest to be left abandoned. We will implement a similar strategy here; as the user walks, we will drop nodes to keep track of their path, as illustrated in the following figure:

Let's begin our journey--start by updating referenceFrame from SpatialStationaryFrameOfReference to SpatialLocatorAttachedFrameOfReference. Open up the file AssistantItemFinderMain.cs and navigate down to where referenceFrame is declared and change its class from SpatialStationaryFrameOfReference to SpatialLocatorAttachedFrameOfReference, as follows:

    internal class AssistantItemFinderMain : IDisposable, IFrameGrabberDataSource
{
...
SpatialLocatorAttachedFrameOfReference referenceFrame;
...
}

Now, make the following changes to the SetHolographicSpace method:

public void SetHolographicSpace(HolographicSpace holographicSpace)
{
this.holographicSpace = holographicSpace;
locator = SpatialLocator.GetDefault();
locator.LocatabilityChanged += this.OnLocatabilityChanged;
holographicSpace.CameraAdded += this.OnCameraAdded;
holographicSpace.CameraRemoved += this.OnCameraRemoved;
referenceFrame=
locator.CreateAttachedFrameOfReferenceAtCurrentHeading();

}

As you may remember from the previous chapter, referenceFrame is used by the HoloLens to consider the position and the orientation of the holograms it is rendering. In the previous chapter, we used a stationary reference frame that is SpatialStationaryFrameOfReference--which, once created, was static (until recreated). All the holograms would be positioned relative to this specific position. In this chapter, we are using an attached reference frame that is SpatialLocatorAttachedFrameOfReference--where, as the name implies, this origin is the position of the HoloLens device that is updated as the device moves.

The position of SpatialLocatorAttachedFrameOfReference is updated to match the position of the HoloLens, but the orientation remains static. 

Changing the type of referenceFrame will introduce many compile time errors. Let's jump through the code, making the necessary changes to resolve these. 

First jump to the Update method and change the following statement:

SpatialCoordinateSystem currentCoordinateSystem = referenceFrame.CoordinateSystem;

This will make it look as follows:

SpatialCoordinateSystem referenceFrameCoordinateSystem = referenceFrame.GetStationaryCoordinateSystemAtTimestamp(prediction.Timestamp); 

Similarly, with the Render method, make the following changes from the following line:

cameraResources.UpdateViewProjectionBuffer(deviceResources, cameraPose, referenceFrame.CoordinateSystem);

Change the preceding line to the following code snippet:

SpatialCoordinateSystem referenceFrameCoordinateSystem = referenceFrame.GetStationaryCoordinateSystemAtTimestamp(prediction.Timestamp);

if(referenceFrameCoordinateSystem == null)
{
continue;
}

cameraResources.UpdateViewProjectionBuffer(deviceResources, cameraPose, referenceFrameCoordinateSystem);

With the reference frame now updated, it's time to create our breadcrumbs--as discussed in the previous chapter, the HoloLens works over large areas. Unlike VR that can use a single coordinate system, the HoloLens needs to spawn these across a physical space. This makes sense, given that the HoloLens uses the physical world for reference; that is, if the HoloLens travels too far from a recognizable point, then it will be unable to accurately consider its position. For this reason, the Windows.Perception.Spatial namespace includes something called SpatialAnchor. SpatialAnchor allows us to explicitly create reference points, and therefore, allows us to extend it beyond its initial area. When SpatialAnchor is created, relationships are created between itself and other coordinate systems, allowing us to transform between them--something you will become familiar with by the end of this chapter. You may be wondering--how is this related to our breadcrumbs?--our breadcrumbs will essentially be SpatialAnchor with some additional metadata. 

We will soon jump back in the editor and create these breadcrumbs (here on, referred to as nodes), but before we do, let's first discuss the logic behind creating them. 

Our requirement is to be able to rebuild the user's path back to an item. To avoid having to scan the physical space and perform some type of path finding algorithm over the physical space, we will simply build a dense mesh as the user traverses the environment. Each node will reference an associated SpatialAnchor along with a collection of edges that will connect nearby nodes the user travels to and from. When constructing a path for the user, we can assume that these edges provide us with a clear path. The following figure illustrates this concept:

 

As illustrated in the preceding figure, nodes are created when the user's distance is beyond a predefined distance from the current node that the user resides in. When this occurs, the application will search for a node in proximity, and create a new node only if one cannot be found. When the user traverses between nodes, an edge is created that will connect them and, thus, make a path available for us to use.

During this brief discussion, we have identified a set of entities we will need to create. The following is a list of each of them with a short explanation of their purpose: 

  • Node: This is the breadcrumb of our system--these will be dropped as the user walks around their environment
  • Edge: This object creates a connection between nodes
  • Entity: This is the visual representation of a node and is used when we, obviously, want to render a path

Let's begin by creating our Node and Edge classes and then implement the logic to manage this process in the AssistantItemFinderMain class. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.198.49