Unity Leap Motion - 手掌位置随VR中的头部旋转而变化

时间:2018-03-27 17:49:44

标签: unity3d rotation quaternions leap-motion

我正在尝试使用手掌位置来获取距离传感器原点(表面)的手距离,然后将其用于我编写的函数中,该函数比较一组边界内的位置(每个轴一个)来计算来自传感器的数据的权重,因为内置在飞跃API中的“置信度”变量非常糟糕。

问题在于,无论何时我转过头,轴似乎都会改变,这完全是我的范围。有没有办法可以中和旋转,使轴保持一致,即Z远离传感器,X左右,Y上下。如果我面向前方它完美地工作,因为轴是如此详细,但如果我看起来正确,它就消失了。 :(

我将不胜感激。

FYI - 传入的参数'position'是手掌位置。

 float CalculateSensorWeight(Vector position)
    {
        float HighestX = 1f, LowestX = -1f;
        float HighestY = 1.2f, LowestY = 0.6f;
        float HighestZ = 1f, LowestZ = 0.4f;

        HighestX *= transform.root.lossyScale.x;
        LowestX *= transform.root.lossyScale.x;
        HighestY *= transform.root.lossyScale.x;
        LowestY *= transform.root.lossyScale.x;
        HighestZ *= transform.root.lossyScale.x;
        LowestZ *= transform.root.lossyScale.x;

        Debug.Log(position);

        clampedX = (1f - (-1f)) / (HighestX - LowestX) * (position.ToVector3().x - HighestX) + 1f;
        clampedY = (1f - (-1f)) / (HighestY - LowestY) * (position.ToVector3().y - HighestY) + 1f;
        clampedZ = (1f - (-1f)) / (HighestZ - LowestZ) * (position.ToVector3().z - HighestZ) + 1f;

        totalClamp = clampedX + clampedY + clampedZ;

        //Debug.Log(clampedX + " , " + clampedY + " , " + clampedZ + " = " + totalClamp);

        float weight = (1f - 0f) / (3f - (-3f)) * (totalClamp - 3f) + 1f;
        weight = ((weight-0f)/(1f-0f))*(1f-(-1f))+(-1f);
        weight = 1f - Mathf.Abs(weight);

        //Debug.Log("Weight = " + weight);
        //Round the weight to 2 decimal places for asthetics and ease
        weight = Round(weight, 2);
        return weight;
    }

1 个答案:

答案 0 :(得分:0)

我通过使用transform.inversetransformpoint并相应地调整我的阈值来解决这个问题