HoloLens with Xamarin UrhoSharp

HoloLens is a Mixed Reality headset, that combines a real world view, with virtual objects. When developing for HoloLens, most will use Unity3D with the HoloLens SDK. Unity is a commercial product, and not free for commercial use. However, another option is to use UrhoSharp, a Xamarin lead port, of the open source software Urho, to .NET.

Setup

Even if you don’t have a spare pile of cash lying around, to purchase a headset, there is a HoloLens emulator, that can easily get you started. If you need the emulator, check out Install The Tools, to install it and ensure you download all prerequisites.

After this, you can create your first HoloLens UrhoSharp project, by using the default template provided. Search online templates for HoloLens, and create a new project.

Select the HoloLens Emulator, and run the application.

After this, you will see the HoloLens emulator start, and you will see the Moon orbiting the Earth.

Device Portal

Before we delve into code, it’s worth noting of the Device Portal. Press the Open Device Portal button on the emulator.

You will now be presented with the portal, that has much useful information, and functions, such as logging.

HoloLens Application

In this simple example, you have the Moon and the Earth. Two spheres, with one rotating around the other. In my Introduction to UrhoSharp, and UrhoSharp 3D Moving Object, I go into details on creating a basic object.

The differences for a HoloLens application, is the inheritance from SteroApplication.

public class HelloWorldApplication : StereoApplication

As with any UrhoSharp app, you have a Scene, you need to create children on. Once this child is created you can add textures and actions. Please see my other UrhoSharp articles for more information on this.

// Create a node for the Earth
earthNode = Scene.CreateChild();

Also, HoloLens accepts gesture input, and there are events you can override. To simulate hand gestures within the HoloLens Emulator, please take a look at Using the HoloLens emulator.

public override void OnGestureManipulationStarted() => earthPosBeforeManipulations = earthNode.Position;
public override void OnGestureManipulationUpdated(Vector3 relativeHandPosition) =>
                                    earthNode.Position = relativeHandPosition + earthPosBeforeManipulations;
public override void OnGestureTapped() { }
public override void OnGestureDoubleTapped() { }

HoloLens of course does a lot more than just presenting virtual objects in your view. It will also accept Speech input, Hand Gesture Recognition, and can communicate with web based services. An example would be using Azure’s Cognitive Services to provide facial recognition.

Learn More

This was a very basic look at getting started with HoloLens with UrhoSharp. Please look at the HoloLens UrhoSharp Samples, that include a dancing Mutant, Crowd Navigation and interacting with Cognitive Services, to start delving deeper.

Microsoft MVP | Xamarin MVP | Xamarin Certified Developer |
Exrin MVVM Framework | Xamarin Forms Developer | Melbourne, Australia

Related Posts

Leave A Comment?