public void Update()
        {
            if (controller == null)
            {
                return;
            }

            bool gestureActive  = controller.GestureActive();
            bool gestureStarted = gestureActive && !gestureActivePreviousFlag;
            bool gestureEnded   = !gestureActive && gestureActivePreviousFlag;

            if (gestureActive)
            {
                PopulateQueue();
            }

            if (gestureEnded)
            {
                List <GTransform> transforms = new List <GTransform>(dataQueue);
                metaData   = GestureMetaData.GetGestureMetaData(transforms);
                transforms = viewNormalizer.Normalize(transforms);

                CheckGestures(transforms);
            }

            else if (gestureStarted)
            {
                dataQueue.Clear();
                SetLineRendererPositions(dataQueue);
                OnGestureStartCallback();
            }

            gestureActivePreviousFlag = gestureActive;
        }
        /// <summary>
        /// Static helper method to convert a list of transforms into a partially complete GestureMetaData object
        /// </summary>
        /// <param name="transforms">The list of raw GTransform data</param>
        /// <returns>Returns a `GestureMetaData` instance with fields populated</returns>
        public static GestureMetaData GetGestureMetaData(List <GTransform> transforms)
        {
            Vector3 min      = transforms[0].position;
            Vector3 max      = transforms[0].position;
            Vector3 centroid = new Vector3(0, 0, 0);
            float   speed    = 0.0f;
            int     count    = transforms.Count;

            for (int i = 0; i < count; i++)
            {
                Vector3 pos = transforms[i].position;
                min       = new Vector3(Math.Min(pos.x, min.x), Math.Min(pos.y, min.y), Math.Min(pos.z, min.z));
                max       = new Vector3(Math.Max(pos.x, max.x), Math.Max(pos.y, max.y), Math.Max(pos.z, max.z));
                centroid += pos;

                speed += transforms[i].velocity.magnitude;
            }
            GestureMetaData ret = new GestureMetaData();

            ret.scale        = max - min;
            ret.centroid     = centroid / count;
            ret.pointCount   = count;
            ret.time         = transforms[count - 1].time - transforms[0].time;
            ret.averageSpeed = speed / count;

            return(ret);
        }
 void OnGestureFailedCallback(GestureMetaData metaData)
 {
     gestureFailedCallback.Invoke(metaData);
 }
 void OnGestureCompletedCallback(GestureMetaData metaData)
 {
     gestureObservedCallback.Invoke(metaData);
 }
Beispiel #5
0
 public void FireEvent(GestureMetaData metaData)
 {
     completeEvent.Invoke(metaData);
 }