////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public void UpdateData(HoverCursorDataProvider pCursorDataProv,
                               HoverInputOculusTouch.ControlState pState, OvrAvatar pAvatar)
        {
            ICursorDataForInput data = GetData(pCursorDataProv);

            if (data == null)
            {
                return;
            }

            data.SetUsedByInput(pState.IsValid);

            if (!pState.IsValid)
            {
                return;
            }

            if (!TryUpdateDataWithAvatarElement(data, pAvatar))
            {
                UpdateDataWithLocalOffsets(data, pState);
            }

            UpdateDataForTrigger(data, pState);
            UpdateDataForSize(data, pState);
        }
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateDataForSize(ICursorDataForInput pData,
                                       HoverInputOculusTouch.ControlState pState)
        {
            float prog = GetInputSourceProgress(CursorSizeInput, pState, 0.5f);

            pData.SetSize(Mathf.Lerp(MinSize, MaxSize, prog));
        }
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateDataForTrigger(ICursorDataForInput pData,
                                          HoverInputOculusTouch.ControlState pState)
        {
            float prog = GetInputSourceProgress(TriggerStrengthInput, pState, 0);

            pData.SetTriggerStrength(prog);
        }
Exemplo n.º 4
0
 /*--------------------------------------------------------------------------------------------*/
 private void UpdateDataWithLocalOffsets(ICursorDataForInput pData,
                                         HoverInputOculusTouch.ControlState pState)
 {
     pData.SetWorldPosition(
         OriginTransform.TransformPoint(pState.LocalPos) + pState.LocalRot * LocalPosition);
     pData.SetWorldRotation(
         OriginTransform.rotation * pState.LocalRot * Quaternion.Euler(LocalRotation));
 }
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateDataWithLocalOffsets(ICursorDataForInput pData,
                                                HoverInputOculusTouch.ControlState pState)
        {
            Matrix4x4 txMat    = OriginTransform.localToWorldMatrix;
            Matrix4x4 txRotMat = txMat * Matrix4x4.TRS(Vector3.zero, pState.LocalRot, Vector3.one);

            pData.SetWorldPosition(txMat.MultiplyPoint3x4(pState.LocalPos) +
                                   txRotMat.MultiplyVector(LocalPosition));
            pData.SetWorldRotation(txRotMat.GetRotation() * Quaternion.Euler(LocalRotation));
        }
        /*--------------------------------------------------------------------------------------------*/
        private float GetInputSourceProgress(InputSourceType pInputSourceType,
                                             HoverInputOculusTouch.ControlState pState, float pDefault)
        {
            switch (pInputSourceType)
            {
            case InputSourceType.IndexTrigger:
                return(Mathf.InverseLerp(0, IndexTriggerMax, pState.IndexTrigger));

            case InputSourceType.HandTrigger:
                return(Mathf.InverseLerp(0, HandTriggerMax, pState.HandTrigger));

            case InputSourceType.Button1Press:
                return(pState.Button1Press ? 1 : 0);

            case InputSourceType.Button2Press:
                return(pState.Button2Press ? 1 : 0);

            case InputSourceType.StartPress:
                return(pState.StartPress ? 1 : 0);

            case InputSourceType.ThumbstickPress:
                return(pState.ThumbstickPress ? 1 : 0);

            case InputSourceType.ThumbstickY:
                return(Mathf.InverseLerp(-ThumbstickMax, ThumbstickMax, pState.ThumbstickAxis.y));

            case InputSourceType.ThumbstickUp:
                return(Mathf.InverseLerp(0, ThumbstickMax, pState.ThumbstickAxis.y));

            case InputSourceType.ThumbstickDown:
                return(Mathf.InverseLerp(0, -ThumbstickMax, pState.ThumbstickAxis.y));

            case InputSourceType.ThumbstickX:
                return(Mathf.InverseLerp(-ThumbstickMax, ThumbstickMax, pState.ThumbstickAxis.x));

            case InputSourceType.ThumbstickLeft:
                return(Mathf.InverseLerp(0, -ThumbstickMax, pState.ThumbstickAxis.x));

            case InputSourceType.ThumbstickRight:
                return(Mathf.InverseLerp(0, ThumbstickMax, pState.ThumbstickAxis.x));
            }

            return(pDefault);
        }