C# 统一的kinect光标

C# 统一的kinect光标,c#,cursor,unity3d,kinect,C#,Cursor,Unity3d,Kinect,我希望能够让一个诅咒者使用Kinect在unity中工作。重要的是,我使用kinect sdk作为unity的插件,而不是使用openni,我成功地让它工作了一半,但它并没有真正完善。目前,我让它沿x轴工作,但它没有覆盖整个屏幕。更理想的做法是将光标从屏幕中心开始,然后相应地移动。当更多地向屏幕右侧移动时,它只移动了一半。我宁愿不硬编码在一个浮点数,而是根据屏幕计算。在统一中有一个功能,你们可以扩展到世界 void Update () { if (sw.pollSkeleton())

我希望能够让一个诅咒者使用Kinect在unity中工作。重要的是,我使用kinect sdk作为unity的插件,而不是使用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();
}
}
void更新(){
if(sw.pollskettle())
{
距离.x=sw.bonePos[0,2].x-sw.bonePos[0,7].x;//bonpos 0,2是脊椎0,7是左手
//脊柱位置通常在(0.1,1.2,0.3)左右
/*
Log(“距离为”+distance.x);
*/
/*
*(-0.2,1.4,0.7)在左侧将头翻转过来//基本上通过此修剪
*(-0.3,1.0,0.6)靠近肩部的手高度合理(-0.4,1.0,0.7)肩部意味着任何1.0区域
*(-0.2,0.6,0.7)手下部躯干水平游标应处于活动状态
* (-)
*(-0.1,0.7,0.3)侧面的手不应记录游标(-0.1,0.5,0.3)0.0-0.1
* 
*/
/*
*(0.3,1.3,0.8)左手在右侧头部上方
*(0.2,1.0,0.8)手向上举,另一侧右肩(0.4,1.0,0.7)再向右
*(0.3,0.9,0.7)手放低,然后应放低,但指向右侧
*(0.3,0.7,0.6)腰部以下右下角的手
*(0.2,0.7,0.5)手靠近腹股沟和脊柱
*/
//如果左手的x轴小于脊椎的x轴
//
if(sw.bonePos[0,7].x=sw.bonePos[0,2].x)
{
差值=-0.8f*距离.x;
Log(“右手交接”);
}
Debug.Log(“Dist:+distance.x+”,Diff:+difference);
Debug.Log(“脊椎位于:“+sw.bonePos[0,2]+”,左手位于:“+sw.bonePos[0,7]+”光标位置“+transform.position”);
}
}
void OnGUI(){
//左顶宽高
矩形r=新矩形(屏幕宽度*(差值+0.3f),0.5f*屏幕高度,100100);
/*屏幕宽度480*0.1973117,0.5f*1280100100
* 
* 
*/
标签(r,光标);
//GUI.DrawTexture();
}
}

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

上面帖子中的代码创建了一个框,该框由玩家身体周围的以下点限定:

  • 路肩=屏幕顶部
  • Hips=屏幕底部
  • 左肩=屏幕上最左侧
为了获得屏幕最右边的位置,我计算了左肩和右肩之间的距离,并将其添加到右肩位置

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


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

万一有人遇到这个问题,我就在这个网站上找到了一个可以使用的解决方案

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

differnetx=translate(distance.x,.6f,0,0,1);
differencey=translate(distance.y,.5f,0,0,1);
这将创建一个从手的最远伸展到脊椎的矩形,并将其映射到屏幕。当手穿过身体时,kinect有时会感到困惑,因此我认为最好不要穿过脊椎进行所有导航(p>:)谢谢@evillocletmonkey的帮助和这么酷的名字
differnetx=translate(distance.x,.6f,0,0,1);
differencey=translate(distance.y,.5f,0,0,1);