As part of a Hackathon at work, I decided to put my Hololens app development skills to use and create a full fledged holographic application. I feel that designing a game on any platform requires not only the knowledge of developing on that platform, but also stresses the application's UI, functionality, and overall user engagement. And what better game than the world famous tile matching puzzle Tetris!
I have decided to make this project completely open source and available on GitHub here
Here's a YouTube link with short video demo of the app. I'd love feedback and comments!
Moving Holograms with Gestures
It's been radio silence since my last post (I know) but work has kept me super busy!
I'm back with what I think was my biggest challenge in developing applications using Hololens - moving holograms using gestures. Granted, the new MRTK has a HandDraggable script (renamed DragAndDropHandler) located here, but I found this script a little complicated for simpler Hololens applications. The script relies on both the camera and hand position and very quickly seems to "lose" the hologram out in the weeds if the user either moves his or her hand or head fast enough.
For my requirements (creating HoloTetris), I needed a simpler script where the reliance is on the user's hand position which is monitored on every frame rate once the hologram is engaged, allowing for a smoother movement of holograms across the screen. I named this script ObjectControl which inherits IInputHandler and IFocusable
Some of the most useful scripts involve getting and setting the object's position - very useful when engaging and moving the object. Code is provided on GitHub here and some snippets and highlights are explained below
A couple of useful boolean values isDragging and isEnabled are to keep track of the current status of the object.
IInputHandler inherits the OnInputDown and OnInputUp functions which commence and end the object dragging action.
OnInputDown records the event as used (so that the dragging action doesn't get interrupted by another user action until completion). StartDragging is another function in MRTK which determines the source that initiated the dragging gesture (hand or controller). The MRTK version of StartDragging also looks for the camera position and the pivot position of the hand. I stripped this script down to simply record the object position at the start of dragging.
UpdateDragging is another function which is called during Update. Similar to StartDragging, UpdateDragging continues to monitor and update the position of the object based on the hand's current position. The object's new position is calculated by using the Vector3.Slerp function which spherically interpolates between the current object's and hand's position to move the object to the new position
Vector3 draggedPosition = HostTransform.position + (handDistance * DistanceScale);
Vector3 newPosition = Vector3.Slerp(HostTransform.position, draggedPosition, PositionLerpSpeed);
Finally, a few functions to gracefully handle exiting the dragging motion, once the user releases the drag gesture. This invokes the OnInputUp inherited funciton, where I release the event (eventData.Use()) before calling a StopDragging function to fix the final position of the hologram