Magic Leap (Unity on a Mac) by Example: Part 4

John Tucker
Coinmonks
2 min readJul 1, 2018

--

Exploring the Raycast Magic Leap API.

This article is part of the series starting with Magic Leap (Unity on a Mac) by Example: Part 1.

We explore a simple yet powerful technique of interacting with the physical world; raycasting.

The full examples in this series are available to download.

Raycast

As in previous articles, this example is a simplified version of Magic Leap’s more complicated example (one of multiple files) on the topic of raycasting.

This application draws a cube at a position calculated by starting with the position (0.0f, 0.5f, 0.0f); center of the room 1/2 a meter off the floor. It moves in the direction (-1.0f, 0.0f, 0,0f); towards the wall with the picture on it. It returns the position where it hits the first physical thing in the room (the back of the couch) and draws a cube.

Assets/src/raycast/Raycast.cs

Observations:

  • Much like the previous example, we use MLWorldRays.start and MLWorldRays.stop in the Awake and OnDestroy methods; including disabling the script if MLWorldRays.start fails.
  • It is not obvious to me why we would want / need to create a RaycastHit object to pass around data when we already have the key data in a more primitive form, e.g., Vector3 point.
  • It is not entirely clear how raycasting can work if the entire path from starting to collision point are not in view of the Magic Leap headset.

Conclusion

Through simple examples, we have explored four of the six core Magic Leap APIs: control, hand tracking (aka gesture), planes, and raycast.

The remaining two image tracking and meshing were more difficult to work with; thus were not included in this series.

We wrap up this series with a more complete example of using the APIs in Magic Leap (Unity on a Mac) by Example: Part 5.

--

--

John Tucker
Coinmonks

Broad infrastructure, development, and soft-skill background