If you have the latest version of the Interaction Engine, you should be able to take any reference to an InteractionBehaviour and call intObj.graspingController
, which will return null if there is no controller (hand or VR controller) grasping the object, or will return the grasping InteractionController object if there is one.
You can convert an InteractionController to an InteractionHand by calling controller.interactionHand
, which will be null if the controller is, in fact, a VR controller instead of a Leap hand. An InteractionHand contains a reference to the Leap hand that is driving it on any given frame -- you can access that with intHand.leapHand
. Again, this will be null if that hand is not currently tracked by the Leap Motion Controller
You can also get a set of InteractionHands that can be foreach
'd over directly from the interaction behaviour reference: foreach (var intHand in intObj.graspingHands) { }
An easy way to do this that generically supports hands and controllers might be:
InteractionBehaviour intObj; // fill this somehow
if (intObj.isGrasped) {
var graspingController = intObj.graspingController;
Vector3 controllerPos = graspingController.transform.position;
Quaternion controllRot = graspingController.transform.rotation;
// Use the position and rotation.
}