【问题标题】:A kinect cursor in unity一个统一的 kinect 光标
【发布时间】:2013-03-21 12:02:31
【问题描述】:

我希望能够使用 Kinect 让光标统一工作。我通过使用 kinect sdk 作为统一插件而不使用 openni 来做到这一点,我设法让它工作了一半,但它并没有真正完善。目前我让它沿着 x 轴工作,但它没有覆盖整个屏幕。将光标从屏幕中心开始并相应地移动会更理想。当更多地向屏幕右侧移动时,它只会移动到一半。我宁愿不硬编码浮点数,而是根据屏幕计算。在统一中,有一个可以扩展到世界的功能

void Update () {


    if (sw.pollSkeleton())
    {
        distance.x=sw.bonePos[0,2].x - sw.bonePos[0,7].x;//bonpos 0,2 is the spine 0,7 is the left hand

        //spine position will usually be around (0.1,1.2,0.3)
        /*
        Debug.Log("the distance is"+distance.x);

        */
        /*
         * (-0.2,1.4,0.7) hand over head on left side// essentially by this trime
         * (-0.3,1.0,0.6) hand near shoulders resonably high (-0.4,1.0,0.7) shoulders meaning anything 1.0 region
         * (-0.2,0.6,0.7) hand lower torso level curser should then be alive
         * (-)
         * (-0.1,0.7,0.3)hand at the side shouldnt record curser (-0.1,0.5,0.3) 0.0 -0.1
         * 
         */

        /*
         * (0.3,1.3,0.8)left hand over head on right side
         * (0.2,1.0,0.8) hand higher up on the other side right shoulder (0.4,1.0,0.7) further right
         * (0.3,0.9,0.7) hand lower then shoullder but pointing towards the right
         * (0.3,0.7,0.6) hand lower right below waist
         * (0.2,0.7,0.5) hand close to groin and spine
         */



        //if the left hands x axis is less than that of the spine
        //
        if(sw.bonePos[0,7].x<sw.bonePos[0,2].x)
        {
            //distance being 0.2053766 * -0.5f
             difference = -0.5f*distance.x;
            //difference being -0.1026883
            Debug.Log("hand is over by the left");

        }
        if(sw.bonePos[0,7].x>=sw.bonePos[0,2].x)
        {
             difference = -0.8f*distance.x;
            Debug.Log("hand is over by the right");

        }

        Debug.Log("Dist: " + distance.x + ", Diff: " + difference);


        Debug.Log("The spine is positioned at :" +sw.bonePos[0,2]+"The left hand is at :" +sw.bonePos[0,7]+" the position of the cursor"+transform.position);
    }


}

void OnGUI() {
    //left top width height
    Rect r = new Rect(Screen.width * (difference + 0.3f),0.5f*Screen.height,100,100);
    /*screen.width 480 * 0.1973117,0.5f*1280,100,100
     * 
     * 
     */
    GUI.Label(r,cursor);
    //GUI.DrawTexture();
}
}

【问题讨论】:

    标签: c# cursor unity3d kinect


    【解决方案1】:

    我没有处理过 Unity,所以很遗憾我不能直接谈论 Unity 的代码——但我之前已经发布过 Kinect SDK 的代码。在我对这个问题的回答中,我包含了在播放器周围创建一个边界框来表示屏幕的源代码:

    how to use skeletal joint to act as cursor using bounds (No gestures)

    以上帖子中的代码创建了一个以玩家身体周围的以下点为边界的框:

    • 肩膀 = 屏幕顶部
    • 臀部 = 屏幕底部
    • 左肩 = 屏幕最左侧

    为了获得最右边的屏幕位置,我取左右肩之间的距离并将其添加到右肩位置。

    这提供了一个舒适的区域,允许玩家在屏幕上移动光标。它还可以轻松扩展到不同大小的不同玩家,并且无论玩家站在 Kinect 的 FOV 中的哪个位置都可以正常工作。

    这个概念应该适应 Unity 代码。

    【讨论】:

    • :) 谢谢@EvilClosetMonkey 的帮助和这么酷的名字
    【解决方案2】:

    万一有人遇到这个问题,我找到了一个可以玩的工作,我在这个网站上找到了 Mapping a range of values to another

    float translate(float value, float leftMin, float leftMax, float rightMin,float rightMax)
    {
        float leftSpan = leftMax - leftMin;
        float rightSpan= rightMax - rightMin;
    
        float valueScaled = (float)(value-leftMin)/(float)(leftSpan);
        return rightMin+(valueScaled * rightSpan);
    }
    

    在我的更新方法中我会这样做

    differnetx=translate(distance.x,.6f,0,0,1);
    differencey=translate(distance.y,.5f,0,0,1);
    

    这会从手的最远部分到脊椎创建一个矩形,并将其映射到屏幕。当手穿过身体时,kinect 有时会感到困惑,所以我认为最好不要进行所有导航而不是穿过脊柱

    【讨论】:

      猜你喜欢
      • 2016-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多