我正在尝试为 MS Kinect 实施实时策略控制方案。到目前为止,我已经有了一个光标,可以通过移动你的左手(或右手,取决于你的惯用手)来移动它。我有一个基于 Open-NI 的 Kinect 控制器,它为玩家的运动设置骨架,并为我的应用程序提供手腕、肘部、肩部和身体中心坐标。为了将这些手腕坐标投影到屏幕上,我设置了一个 Rectangle,它位于玩家中心稍左/右的位置,只要手腕在矩形内移动,光标就会在屏幕上移动。我的问题是,XNA-Rectangle 的左上角作为原点,即 X 轴指向右,因为它“应该”,但 Y 轴指向下方,而 Kinect 的 Y 轴 -坐标系指向上方。这导致光标在屏幕上向上移动,当我向下移动手时,反之亦然。我无法用 Kinect 坐标系改变任何东西,所以是否可以“翻转”矩形的“坐标系”,使其 Y 轴也向上?
以下是相关代码:
(来自校准()-方法:)
List<Vector3> joints = UDPlistener.getInstance().ParseCalibCoordinates(data);
//0 = Right Wrist 1 = Right Elbow 2 = Right Shoulder
//3 = Left Wrist 4 = Left Elbow 5 = Left Shoulder
//6 = Center
height = 762;
width = 1024;
switch (hand)
{
case 0:
cursorSpace = new Rectangle((int)(joints[6].X * 2) - 200, (int)(joints[6].Y * 2) + height, width, height);
break;
case 3:
cursorSpace = new Rectangle((int)(joints[6].X * 2) - 1200, (int)(joints[6].Y * 2) + height, width, height);
break;
}
public Point Cursor(String data)
{
List<Vector3> joints = UDPlistener.getInstance().ParsePlayCoordinates(data);
//0 = Right Wrist 1 = Left Wrist 2 = Center
double mhx = 0; //main hand x-coordinate
double mhy = 0; // main hand y-coordinate
switch (hand)
{
case 0:
mhx = joints[hand].X;
mhy = joints[hand].Y;
break;
case 3:
mhx = joints[hand-2].X;
mhy = joints[hand-2].Y;
break;
}
int x;
int y;
if (Math.Abs(mhx - mhxOld) < 1.0 || Math.Abs(mhy - mhyOld) < 1.0)
//To remove jittering of the cursor
{
x = (int) mhxOld * 2;
y = (int) mhyOld * 2;
}
else
{
x = (int) mhx * 2;
mhxOld = mhx;
y = (int) mhy * 2;
mhyOld = mhy;
}
Point cursor = new Point(0,0);
if (cursorSpace.Contains(x,y))
{
cursor = new Point(x - cursorSpace.X, y - CursorSpace.Y);
lastCursorPos = cursor;
return cursor;
}
对不起,文字墙,我希望,我能说清楚。
提前致谢,
KK