Take a look at these docs, they were quite useful for me when I was getting started.
https://developer.leapmotion.com/documentation/unity/devguide/Project_Setup.html#setting-up-a-unity3d-project
Are you using Orion for VR? We have used three methods for rotating objects in this case.
Option 1: InteractionBehaviour on GameObject
If so, once you have set up the LeapMotion HeadMountedRig (prefab included in SDK, see example scenes), you can natively rotate objects using InteractionBehaviours.
- Add a sphere collider & rigidbody to an object.
- Set rigidbody to kinematic and interpolate
- Set the rigidbody properties to lock position, leave rotation unlocked.
- Add an InteractionBehaviour
The docs go into more detials:
https://developer.leapmotion.com/documentation/unity/unity/Unity_IE_Setup.html
The InteractionEngine will take care of the rotation of the object when you are pinching or grasping the object. Rotations are mostly done with the twist of the wrist.
See www.handwaver.org
and look for the HigherDimensions video. The yellow cube uses this method.
Option 2:
Setup an InteractionBehaviour on an object as above.
Add a Joint to the rigidboy, fixing it's axis.
Now, Unity's physics system will take care of the rotation based on slight changes in position of the object from it's InteractionBehavior. this allows for rotations from grasping the edges of the object.
See www.HandWaver.org
and look for the video of the Revolve Operator. The ships wheel uses this method.
Option 3:
Use fingerDirectionDetectors to detect a swipe detector.
- add a finger dierction detector to the scene
- choose which fingers are up or down, and a duration
When the finger direction detector is started, start an corroutine. The corrutine would track the position of a relevant part of the relevant hand, using a running average of changes in position to track velocity and a running average of changes in the cross product of the changes in position to track angular velocity.
Here's a snipet of a related bit of our code, though it is setup to detect 'slices' made with a sword held by leap hands and not a 'swipe' gesture (though they might be similar).
private IEnumerator normals(float waitTime)
{
while (true)
{
yield return new WaitForSeconds(waitTime);
//update arc while holding
// Debug.Log(Vector3.Magnitude(this.GetComponent<Rigidbody>().angularVelocity).ToString());
if (isSlicing && (Vector3.Magnitude(this.GetComponent<Rigidbody>().velocity) > 0.2f))
{
if (idx < N)
{
positionTrack[idx] = this.transform.position;
if (idx > 2)
{
sumNormal = sumNormal + Vector3.Cross((positionTrack[idx - 1] - positionTrack[idx]), (positionTrack[idx - 2] - positionTrack[idx - 1]));
}
}
sumPosition = sumPosition + positionTrack[idx];
if (idx > 2)
{
normal = sumNormal / (idx + 1);
}
else
{
normal = Vector3.up;
}
center = sumPosition / (idx + 1);
idx = idx + 1;
}
else if ((Vector3.Magnitude(this.GetComponent<Rigidbody>().velocity) < .1f) && (idx > 5))
{
endEarly();
}
}
}