C# API Reference

The C# API Reference provides details on all the classes which make up the Leap Motion API.

Note that any coordinates, directions, and transformations reported by these classes are expressed relative to the Leap Motion coordinate system, not your Unity game world. To convert position vectors to Unity coordinates, use the Vector class extension ToUnityScaled(). To convert direction vectors to Unity coordinates, use ToUnity(). These scripts are defined in a C# script included with our Unity core asset package, LeapUnityExtensions.

You can convert a transform expressed as a matrix from the Leap Motion API to a Unity Quaternion rotation with the Matrix class extension Rotation() and a Vector3 translation with Translation() (also defined in the script LeapUnityExtensions).

When you get Vectors from the Hand scripts, these vectors have already been transformed into Unity world space relative to the HandController object. In other words, if you rotate the controller object in the scene, the hand positions are also rotated. You can transform points from Leap Motion coordinates to Unity world coordinates in the same way using the Unity Transform.TransformPoint() function after calling ToUnityScaled():

Leap.Vector position = finger.TipPosition;
Vector3 unityPosition = position.ToUnityScaled(false);
Vector3 worldPosition = handController.transform.TransformPoint(unityPosition);

You can do the same for direction vectors with TransformDirection():

Leap.Vector direction = finger.Direction;
Vector3 unityDirection = direction.ToUnity(false)
Vector3 worldDirection = handController.transform.TransformDirection(unityDirection);

To convert a rotation relative to the controller object in the scene, multiply the the rotation by the rotation of the controller:

Quaternion leapRotation = arm.Basis.Rotation(false);
Quaternion finalRotation = controller.transform.rotation * leapRotation;