SetTransform导致Unity LeapMotion对象旋转太快

时间:2018-01-30 10:20:52

标签: unity3d virtual-reality quaternions leap-motion

这是基于我最近在这里提出的一个问题:

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

但是,在给出的唯一响应中建议的代码不起作用。我一直在使用'SetTransform'方法,虽然它允许我将手移动到我想要的位置,旋转是疯狂的。手持续旋转,尽管花费了四天的最佳时间,我找不到解决方案。

总之,我试图将它设置为固定的姿势(例如拳头),但让它随着实时手数据移动和旋转。我创建了一个方法(在上一个问题中详述),当SetTransform引起这种疯狂的旋转时,它会手动重新计算关节的位置以将手放在姿势中。但是,由于必须转换手以旋转它,我仍然最终疯狂旋转,所以我已经切换回SetTransform方法以方便。

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());
}

我真正想要的是一种方法,我可以将两个手对象传递进去(一个是当前的'实时'手,另一个是所需的姿势)并获得一个手对象,然后我可以渲染。

更新

这里要求的是我目前得到的以及我想要实现的目标的图像。

电流:

enter image description here

目标:

enter image description here

目标图像将显示固定姿势,在此示例中,该姿势是当前位置的拳头和实时手的旋转。这意味着我可以让我的手'打开',但在屏幕上,我会看到一个拳头四处移动。正如您从“当前”中看到的那样,SetTransform正在给我正确的姿势和位置,但旋转却很吓人。

1 个答案:

答案 0 :(得分:0)

这个问题一直在其他地方回答。 Unity3D Leap Motion - Put hand in static pose (Pose done just can't rotate)

基本上,我必须创建一个函数,将姿势手作为参数,然后使用Hands.GetHand(Chiralty)从实时数据中获取位置和旋转,然后将其用于“SetTransform”# 39;新手位置和旋转的构成

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;
    }