示例#1
0
        public virtual Frame GetFixedFrame()
        {
            //Aproximate the correct timestamp given the current fixed time
            float correctedTimestamp = (Time.fixedTime + smoothedFixedUpdateOffset_.value) * S_TO_NS;

            //Search the leap history for a frame with a timestamp closest to the corrected timestamp
            Frame closestFrame = leap_controller_.Frame();

            for (int searchHistoryIndex = 0; searchHistoryIndex < 60; searchHistoryIndex++)
            {
                leapMat = UnityMatrixExtension.GetLeapMatrix(this.transform);
                Frame historyFrame = leap_controller_.GetTransformedFrame(leapMat, searchHistoryIndex);

                //If we reach an invalid frame, terminate the search
                if (historyFrame.Id < 0)
                {
                    Debug.Log("historyFrame.Id is less than 0");
                    break;
                }

                if (Mathf.Abs(historyFrame.Timestamp - correctedTimestamp) < Mathf.Abs(closestFrame.Timestamp - correctedTimestamp))
                {
                    closestFrame = historyFrame;
                }
                else
                {
                    //Since frames are always reported in order, we can terminate the search once we stop finding a closer frame
                    break;
                }
            }
            return(closestFrame);
        }
示例#2
0
 // Update is called once per frame
 void Update()
 {
     leapMat      = UnityMatrixExtension.GetLeapMatrix(this.transform);
     CurrentFrame = leap_controller_.GetTransformedFrame(leapMat, 0);
     //perFrameFixedUpdateOffset_ contains the maximum offset of this Update cycle
     smoothedFixedUpdateOffset_.Update(PerFrameFixedUpdateOffset, Time.deltaTime);
     //float now = leap_controller_.Now();
     //Debug.Log("leap_controller_.Now():" + leap_controller_.Now() + " - CurrentFrame.Timestamp:" + CurrentFrame.Timestamp + " = " + (leap_controller_.Now() - CurrentFrame.Timestamp));
     //Debug.Log("provider.Update().CurrentFrame.Id: " + CurrentFrame.Id);
 }