public override void ManipulationUpdate(Vector3 startGesturePosition, Vector3 currentGesturePosition, Vector3 startHeadOrigin, Vector3 startHeadRay, GestureInteractive.GestureManipulationState gestureState)
        {
            base.ManipulationUpdate(startGesturePosition, currentGesturePosition, startHeadOrigin, startHeadRay, gestureState);

            // get gesture data for gesturing along the horizontal axis
            GestureInteractiveData gestureData = GetGestureData(new Vector3(1, 0, 0), MaxGestureDistance, FlipDirecationOnCameraForward);

            for (int i = 0; i < mCycleList.Count; ++i)
            {
                CycleData data = mCycleList[i];
                // get the length of ICycle values to loop through
                float length    = data.Controller.GetLastIndex() + 1;
                float incrament = MaxGestureDistance / length;

                // get the delta of the current gesture
                int offset = Mathf.RoundToInt(gestureData.Distance / incrament);
                if (gestureState == GestureInteractive.GestureManipulationState.Start)
                {
                    // set the starting index so we can add the delta to it
                    data.Index = data.Controller.Index;

                    mCycleList[i] = data;
                }

                // update the ICycle component
                data.Controller.SetIndex(Mathf.Clamp(offset + data.Index, 0, data.Controller.GetLastIndex()));
            }
        }
Example #2
0
        /// <summary>
        /// Returns a data set about the current gesture information compared to a specific vector.
        /// For instance, to compare if the gesture is moving vertically or horizontally,
        /// create two instances of this data set and compare the distance for each.
        /// If the vertical percentage is greater than the horizontal percentage then the gesture is moving vertically.
        /// </summary>
        /// <param name="alignmentVector"></param>
        /// <param name="maxDistance"></param>
        /// <param name="flipDirecationOnCameraForward"></param>
        /// <returns></returns>
        public GestureInteractiveData GetGestureData(Vector3 alignmentVector, float maxDistance, bool flipDirecationOnCameraForward)
        {
            GestureInteractiveData data = new GestureInteractiveData(alignmentVector, maxDistance, flipDirecationOnCameraForward);

            data.Direction = DirectionVector;
            bool flipDirection = Vector3.Dot(Vector3.forward, StartHeadRay) < 0 && flipDirecationOnCameraForward;

            if (flipDirection)
            {
                data.Direction = -data.Direction;
            }
            data.Distance = Vector3.Dot(data.Direction, alignmentVector);

            data.Percentage = Mathf.Min(Mathf.Abs(data.Distance) / maxDistance, 1);

            return(data);
        }