My First “Real” Magic Leap Project: Part 6
We wrap up this series by building a head-locked user interface showing the mode and score.
This article is part of a multi-part series starting with My First “Real” Magic Leap Project: Part 1.
The completed application for this article is available for download from the part6 branch of the bounce repository.
Head Locked Content (Hard)
In a similar vein as how we placed the ball on the table using the user’s head pose (camera position and orientation), we will similarly position the user-interface elements (current mode and score).
note: The approach here is loosely inspired by the Magic Leap article, Interacting with Head Locked Content Unity® Edition.
It is important to note that Magic Leap does not support rendering the UI Canvas relative to the screen as you see from the warning.
Rather we render it into World Space.
For the optimal distance in front of the user to place the UI Canvas, I guessed 2.5 meters based on articles on vehicle heads up displays.
Through trial and error (using the simulator and a cube), I concluded the the maximum visible size of an object at 2.5 meter is 2.3 by 1.7 meters. Illustrates the field-of-view (FOV) limitations that many have commented on.
As for the pixel resolution of the UI Canvas, I did some Internet research and concluded the maximum resolution of the Magic Leap hardware was 720p (or 1280 by 720 pixels).
Through computation and trial and error, the resolution that we are going to use is 945 by 720 pixels with scale of 0.0029.
With this in mind, we create the UI canvas with the following settings:
and with the following script.
Assets / Table / WorldHeadLockCanvas.cs
With this configuration, the UI Canvas immediately tracks the head pose (camera position and rotation).
Head Locked Content (Soft)
Borrowing heavily from the Magic Leap article, we update the script to have the UI Canvas smoothly follow the head pose.
Assets / Table / WorldHeadLockCanvas.cs
Observations:
- The use of Slerp (instead of MoveTowards or Lerp) has the position and rotation ease in and out (less jarring)
- The head movement illustrated is unrealistic; using simulator has its limitations
Mode
Updating a text game object with the current mode is straightforward.
Assets / Table / ModeUI.cs
Score
Similarly, we can wire a new global score into a text game object. We can then increment the score on collisions on the ball.
Assets / Table / Ball.cs
Observations:
- One interesting problem is that, presumably, because the mesh consists of lots of triangles, seemingly simple collisions with a block result in a large number of reported collisions
Wrap Up
While we did not end up with a mind-blowing cool application, we did bump into and solve a number of practical problems with writing Magic Leap applications in Unity.
Hope you found this helpful.