unity-game-enginevirtual-realityquaternionsleap-motion

SetTransform causes Unity LeapMotion object to spin too fast


This builds upon a question I recently asked here:

Unity3D Leap Motion - Put hand in static pose (SetTransform causes Hand to spin crazy)

However, the code suggested in the only response given does not work. I have been using the 'SetTransform' method and while it does allow me to move the hand to my desired position, the rotation is crazy. The hand continuously spins and despite spending the best part of four days on it, I can't find the solution.

In short all I am trying to do it set the hand to a fixed pose (a fist for example) but have it move and rotate with the live hand data. I created a method (detailed in previous question) that would manually recalculate the positions of the joints to put the hand in the pose as the SetTransform was causing this crazy rotation. However, I still ended up with crazy rotation from having to transform the hand to rotate it, so I have switched back to the SetTransform method for ease.

posedHand = PoseManager.LoadHandPose(mhd.LeftHand, int.Parse("2"), transform);
Hand h = new Hand();
if(posedHand != null)
{
    h.CopyFrom(posedHand);                               
    h.SetTransform(LiveData.LeftHand.PalmPosition.ToVector3(), LiveData.LeftHand.Rotation.ToQuaternion());
}

All I really want is a method that I can pass two hand objects into (one being the current 'live' hand, the other being the desired pose) and get a hand object returned which I can then render.

Update

As requested here are images of what I am currently getting and what I want to achieve.

Current:

enter image description here

Target:

enter image description here

The target image would display the fixed pose, which in this example is a fist at the current position and rotation of the live hand. Thus meaning I could have my hand 'open' but onscreen I would see a fist moving around. As you can see from the 'current' the SetTransform is giving me the correct pose and position but the rotation is freaking out.


Solution

  • This question has been answere elsewhere. Unity3D Leap Motion - Put hand in static pose (Pose done just can't rotate)

    Essentially, i had to create a function that took in the pose hand as a parameter which then used Hands.GetHand(Chiralty) to get the position and rotation from the live data which was then used to 'SetTransform' the posed hand to the new position and rotation

    public static Hand TransformHandToLivePosition(Chirality handType, Hand poseHand)
        {
            Hand sourceHand = Hands.Get(handType);
            Hand mimicHand = null;
    
            if (poseHand == null && sourceHand != null && sourceHand.Fingers.Count > 0)
            {
                //poseHand = PoseManager.LoadHandPose(sourceHand, 2, this.transform, true);
            }
    
            if (poseHand != null && sourceHand != null)
            {
                // Copy data from the tracked hand into the mimic hand.
                if (mimicHand == null) { mimicHand = new Hand(); }
    
                mimicHand.CopyFrom(poseHand); //copy the stored pose in the mimic hand
                mimicHand.Arm.CopyFrom(poseHand.Arm); // copy the stored pose's arm into the mimic hand
    
                // Use the rotation from the live data
                var handRotation = sourceHand.Rotation.ToQuaternion();
    
                // Transform the copied hand so that it's centered on the current hands position and matches it's rotation.
                mimicHand.SetTransform(sourceHand.PalmPosition.ToVector3(), handRotation);
            }
            return mimicHand;
        }