예제 #1
0
    private void Calibrate()
    {
        //If there are frames left, do calibration
        if (calibrationFrames > 0)
        {
            if (leapManager.GetPalmSmoothedVelocity() < 5f && leapManager.PalmNormalNear(Vector3.down, 0.75f))
            {
                calibrationFrames--;

                setHandColor(Color.Lerp(Color.green, Color.grey, Mathf.Round((Time.frameCount % 10f) / 10f)));

                //How many frames taken into account, in order to determine a smoothed vector
                int range = 25;

                //Add data
                calibratedDownFrame.Add(leapManager.GetPalmNormal());

                //Clean up
                if (calibratedDownFrame.Count >= range)
                {
                    calibratedDownFrame.RemoveAt(0);
                }

                calibratedDown = Vector3.zero;

                //Find velocity
                for (int i = 0; i < calibratedDownFrame.Count; i++)
                {
                    calibratedDown.x += calibratedDownFrame [i].x;
                    calibratedDown.y += calibratedDownFrame [i].y;
                    calibratedDown.z += calibratedDownFrame [i].z;
                }

                calibratedDown.x /= calibratedDownFrame.Count;
                calibratedDown.y /= calibratedDownFrame.Count;
                calibratedDown.z /= calibratedDownFrame.Count;

                //If this was the last frame, close calibration
                if (calibrationFrames <= 0)
                {
                    //Debug.Log ("Calibration done! Down-vector is " + calibratedDown.ToString ());
                    // tell tutorial manager that calibration is done, and only than move forward to menu
                    calibrationManagerNew.calibrationDone = true;
                    calibrationManager.calibrationDone    = true;
                    musicManager.PlayMusic();
                    setHandColor(Color.grey);
                }
            }

            //If hand is removed from position, reset calibration
            else
            {
                calibrationFrames = 60;
                setHandColor(Color.grey);
            }
        }
    }