AllFramesReady重复循环

时间:2012-07-08 16:43:23

标签: c# c#-4.0 loops kinect

我正在创建一个程序,您可以在其中执行一段时间的代表,因此它会增加一个代表数量。我希望每个代表之间有一个间隔(不是当前的问题)。我把它嵌套在AllFramesReadyEventArgs中。问题是,由于SDK在整个程序中使用AllFramesReadyEvent,因此它是一个无限循环。当我不想要它时,如何在不重复的情况下完成每个代表?提前谢谢。

if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
{
    int whereIsX = (int)Canvas.GetLeft(ellipse1);
    int whereToX = (int)Canvas.GetLeft(pspine);
    whatToMultiplyX = whereToX / whereIsX;

    int whereIsY = (int)Canvas.GetTop(ellipse1);
    int whereToY = (int)Canvas.GetTop(pspine);
    whatToMultiplyY = whereToY / whereIsY;

    Canvas.SetTop(ellipse1, Canvas.GetTop(ellipse1) * whatToMultiplyY);
    Canvas.SetLeft(ellipse1, Canvas.GetLeft(ellipse1) * whatToMultiplyX);

    for (int i = 0; i < Doctor_ShoulderX.Count; i++)
    {
        Canvas.SetTop(doctorHand, Doctor_HandY[i] * whatToMultiplyY);
        Canvas.SetTop(doctorElbow, Doctor_ElbowY[i] * whatToMultiplyY);
        Canvas.SetTop(doctor_Shoulder, Doctor_ShoulderY[i] * whatToMultiplyY);

        Canvas.SetLeft(doctorHand, Doctor_HandX[i] * whatToMultiplyX);
        Canvas.SetLeft(doctorElbow, Doctor_ElbowX[i] * whatToMultiplyX);
        Canvas.SetLeft(doctor_Shoulder, Doctor_ShoulderX[i] * whatToMultiplyX);                        

        handX = Canvas.GetLeft(handright);
        handY = Canvas.GetTop(handright);

        elbowX = Canvas.GetLeft(elbowright);
        elbowY = Canvas.GetTop(elbowright);

        shoulderX = Canvas.GetLeft(shoulderright);
        shoulderY = Canvas.GetTop(shoulderright);

        shoulder_x.Text = "Shoulder X: " + shoulderX.ToString();
        shoulder_y.Text = "Shoulder Y: " + shoulderY.ToString();

        elbow_x.Text = "Elbow X: " + elbowX.ToString();
        elbow_y.Text = "Elbow Y: " + elbowY.ToString();

        hand_x.Text = "Hand X: " + handX.ToString();
        hand_y.Text = "Hand Y: " + handY.ToString();

        Patient_HandX.Add(handX);
        Patient_HandY.Add(handY);

        Patient_ElbowX.Add(elbowX);
        Patient_ElbowY.Add(elbowY);

        Patient_ShoulderX.Add(shoulderX);
        Patient_ShoulderY.Add(shoulderY);
    }
}

1 个答案:

答案 0 :(得分:1)

我会使用答案导致更多的写作而不是评论可以处理:)

每帧都会调用aleframesready动作。所以如果在这里你有20个循环的限制

for (int i = 0; i < Doctor_ShoulderX.Count; i++)

每次都会从0到20调用它。 Imo你应该在类中创建一个静态布尔变量。代码从循环中输出后将其设置为false(如果在启动时它为true)。在调用循环之前,请检查变量是否设置为true。如果是,则调用循环,如果不是,则继续