Example #1
0
 public void HapticPulse(FinchNodeType type, uint millisecond)
 {
     if (FinchCore.NodesState.GetState(type, FinchNodesStateType.Connected))
     {
         FinchCore.HapticPulse(type, millisecond);
     }
 }
        private void FillControllerState(PlayerState outState)
        {
            for (int index = 0; index < PlayerState.Bones.BoneCount; ++index)
            {
                FinchBone bone = PlayerState.Bones[index];
                switch (bone)
                {
                case FinchBone.LeftUpperArm:
                case FinchBone.LeftLowerArm:
                case FinchBone.LeftHand:
                case FinchBone.LeftHandCenter:
                case FinchBone.RightUpperArm:
                case FinchBone.RightLowerArm:
                case FinchBone.RightHand:
                case FinchBone.RightHandCenter:
                {
                    outState.Rotations[index]    = GetBoneRotation(bone);
                    outState.Positions[index]    = GetBoneCoordinate(bone);
                    outState.Available[index]    = true;
                    outState.BonesLengths[index] = FinchCore.GetBoneLength(bone);
                    break;
                }

                default:
                {
                    outState.Rotations[index]    = FinchCore.GetBoneRotation(bone);
                    outState.Positions[index]    = FinchCore.GetBoneCoordinate(bone);
                    outState.Available[index]    = FinchCore.IsBoneAvailable(bone);
                    outState.BonesLengths[index] = FinchCore.GetBoneLength(bone);
                    break;
                }
                }
            }
        }
        public override void Init(int id)
        {
            base.Init(id);

            if (FinchCore.Interop.FinchIsUpperArmReverted(FinchCore.Interop.FinchChirality.Left) == 1)
            {
                FinchCore.Interop.FinchRevertUpperArm(FinchCore.Interop.FinchChirality.Left);
            }

            if (FinchCore.Interop.FinchIsUpperArmReverted(FinchCore.Interop.FinchChirality.Right) == 1)
            {
                FinchCore.Interop.FinchRevertUpperArm(FinchCore.Interop.FinchChirality.Right);
            }

            FinchCore.Interop.FinchResetCalibration(FinchCore.Interop.FinchChirality.Left);
            FinchCore.Interop.FinchResetCalibration(FinchCore.Interop.FinchChirality.Right);

            bool rightDifferentNodes = FinchController.Right.IsConnected && FinchInput.IsConnected(FinchNodeType.LeftUpperArm);
            bool leftDifferentNodes  = FinchController.Left.IsConnected && FinchInput.IsConnected(FinchNodeType.RightUpperArm);

            if (FinchCore.NodesState.GetUpperArmCount() == 1 && (rightDifferentNodes || leftDifferentNodes))
            {
                FinchCore.SwapNodes(FinchNodeType.LeftUpperArm, FinchNodeType.RightUpperArm);
            }

            tremblePass    = FinchCore.NodesState.GetUpperArmCount() < 2;
            leftArmShaking = false;

            ResetValue();
            TryPassStepWithoutRedefine();
        }
        private bool TryCalibrate(FinchChirality chirality, bool swap)
        {
            FinchController mainController       = chirality == FinchChirality.Left ? FinchController.Left : FinchController.Right;
            FinchController additionalController = chirality == FinchChirality.Left ? FinchController.Right : FinchController.Left;

            bool leftCalibrate       = leftPressDown && FinchController.Left.GetPressTime(FinchControllerElement.HomeButton) > FinchCalibration.Settings.TimePressingToCallCalibration;
            bool rightCalibrate      = rightPressDown && FinchController.Right.GetPressTime(FinchControllerElement.HomeButton) > FinchCalibration.Settings.TimePressingToCallCalibration;
            bool mainCalibrate       = chirality == FinchChirality.Left ? leftCalibrate : rightCalibrate;
            bool additionalCalibrate = chirality == FinchChirality.Left ? rightCalibrate : leftCalibrate;

            if (mainCalibrate || additionalCalibrate && swap)
            {
                if (mainCalibrate)
                {
                    mainController.HapticPulse(FinchCalibration.Settings.HapticTime);
                    mainController.Calibrate();
                }
                else
                {
                    additionalController.HapticPulse(FinchCalibration.Settings.HapticTime);
                    additionalController.Calibrate();
                    FinchCore.SwapNodes(FinchNodeType.LeftHand, FinchNodeType.RightHand);
                    FinchCore.Interop.FinchSwapCalibrations(1, 0);
                }
            }

            return(mainCalibrate || additionalCalibrate && swap);
        }
        private Vector3 GetBoneCoordinate(FinchBone bone)
        {
            switch (bone)
            {
            case FinchBone.LeftUpperArm:
                return(FinchCore.GetBoneCoordinate(FinchBone.LeftUpperArm));

            case FinchBone.LeftLowerArm:
                return(elbowPositions[0]);

            case FinchBone.LeftHandCenter:
                return(wristPositions[0]);

            case FinchBone.LeftHand:
                return(GetHandPositionByControllerPosition(wristPositions[0], wristOrientations[0], Vector3.left, FinchCore.GetBoneLength(FinchBone.LeftHand)));

            case FinchBone.RightUpperArm:
                return(FinchCore.GetBoneCoordinate(FinchBone.RightUpperArm));

            case FinchBone.RightLowerArm:
                return(elbowPositions[1]);

            case FinchBone.RightHand:
                return(GetHandPositionByControllerPosition(wristPositions[1], wristOrientations[1], Vector3.right, FinchCore.GetBoneLength(FinchBone.RightHand)));

            case FinchBone.RightHandCenter:
                return(wristPositions[1]);

            default:
                return(Vector3.zero);
            }
        }
 private void BindsChirality(bool swapNodes)
 {
     if (swapNodes)
     {
         FinchCore.SwapNodes(FinchNodeType.LeftUpperArm, FinchNodeType.RightUpperArm);
     }
 }
        private void BindUpperArms()
        {
            FinchCore.BindsUpperArms();
            int controllerCount = FinchCore.NodesState.GetControllersCount();
            int upperArmsCount  = FinchCore.NodesState.GetUpperArmCount();

            PlayableSet.RememberNodes(controllerCount, controllerCount > upperArmsCount ? 0 : controllerCount);
        }
        private bool IsSwiped(Vector2 baseRotationVector)
        {
            bool correctLength = FinchCore.GetSwipe(Chirality).magnitude > 0.4f;
            bool correctTime   = FinchCore.GetSwipeTime(Chirality) < 0.5f;
            bool correctAngle  = Vector2.Angle(baseRotationVector, FinchCore.GetSwipe(Chirality).normalized) < 22.5f;

            return(correctLength && correctTime && correctAngle);
        }
Example #9
0
        public virtual void ReadState(PlayerState outState)
        {
            if (!string.IsNullOrEmpty(errorDetails))
            {
                outState.ErrorDetails = errorDetails;
                Debug.LogError(errorDetails);
                return;
            }

            FinchUpdateError err = FinchUpdateError.NotInitialized;

            if (FinchSettings.HeadUpdateType == FinchHeadUpdateType.RotationUpdate)
            {
                err = FinchCore.Update(FinchVR.MainCamera != null ? FinchVR.MainCamera.rotation.ToFinch() : Camera.main.transform.rotation.ToFinch());
            }
            else if (FinchSettings.HeadUpdateType == FinchHeadUpdateType.RotationAndPositionUpdate)
            {
                err = FinchCore.Update(FinchVR.MainCamera.rotation.ToFinch(), FinchVR.MainCamera.position.ToFinch());
            }
            else
            {
                err = FinchCore.Update();
            }

            if (err != FinchUpdateError.None)
            {
                outState.ErrorDetails = "Error update Dash controller data: " + err;
                Debug.LogError(outState.ErrorDetails);
            }

            for (int i = 0; i < (int)FinchChirality.Last; ++i)
            {
                outState.ElementsBeginEvents[i] = FinchCore.GetEvents((FinchChirality)i, FinchEventType.Begin);
                outState.ElementsState[i]       = FinchCore.GetEvents((FinchChirality)i, FinchEventType.Process);
                outState.ElementsEndEvents[i]   = FinchCore.GetEvents((FinchChirality)i, FinchEventType.End);
                outState.IsTouching[i]          = FinchCore.GetEvent((FinchChirality)i, FinchControllerElement.Touchpad, FinchEventType.Process);
                outState.TouchAxes[i]           = FinchCore.GetTouchpadAxes((FinchChirality)i);
                outState.IndexTrigger[i]        = FinchCore.GetIndexTrigger((FinchChirality)i);
            }

            for (int i = 0; i < (int)FinchNodeType.Last; ++i)
            {
                outState.Gyro[i]  = FinchCore.GetBoneLocalAngularVelocity(PlayerState.Bones[(FinchNodeType)i]);
                outState.Accel[i] = FinchCore.GetBoneLocalAcceleration(PlayerState.Bones[(FinchNodeType)i]);
            }

            outState.NodesState = FinchCore.NodesState;

            if (FinchCore.ControllerType == FinchControllerType.Hand)
            {
                UpdateLongPressDetection(FinchControllerElement.Touchpad, true, outState);
                UpdateCalibrationDelay(outState);
            }
            else
            {
                UpdateLongPressDetection(FinchControllerElement.ButtonZero, false, outState);
            }
        }
        private void CheckChirality(bool vibrate)
        {
            FinchChirality left  = FinchCore.GetCapacitySensor(FinchNodeType.LeftHand);
            FinchChirality right = FinchCore.GetCapacitySensor(FinchNodeType.RightHand);

            if (left == FinchChirality.Unknown && FinchController.Left.IsConnected && right == FinchChirality.Unknown && FinchController.Right.IsConnected)
            {
                Sprite.sprite = NoneHoldBoth;
                return;
            }

            if (left == FinchChirality.Unknown && FinchController.Left.IsConnected || right == FinchChirality.Unknown && FinchController.Right.IsConnected)
            {
                Sprite.sprite = NoneHoldOne;
                return;
            }

            if (left == FinchChirality.Both && FinchController.Left.IsConnected && right == FinchChirality.Both && FinchController.Right.IsConnected)
            {
                Sprite.sprite = BothHoldBoth;
                return;
            }

            if (left == FinchChirality.Both && FinchController.Left.IsConnected || right == FinchChirality.Both && FinchController.Right.IsConnected)
            {
                Sprite.sprite = BothHoldOne;
                return;
            }

            if (left == FinchChirality.Left && FinchController.Left.IsConnected && right == FinchChirality.Left && FinchController.Right.IsConnected)
            {
                Sprite.sprite = BothLeftHold;
                return;
            }

            if (left == FinchChirality.Right && FinchController.Left.IsConnected && right == FinchChirality.Right && FinchController.Right.IsConnected)
            {
                Sprite.sprite = BothRightHold;
                return;
            }

            if (FinchCore.NodesState.GetControllersCount() == 0)
            {
                Sprite.sprite = NoneHoldBoth;
                return;
            }

            if (vibrate)
            {
                FinchController.Left.HapticPulse(100);
                FinchController.Right.HapticPulse(100);
            }

            FinchCore.BindsControllers();
            PlayableSet.RememberNodes();
            NextStep();
        }
        private void TryCalibrate()
        {
            if (IsCalbrating)
            {
                return;
            }

            bool leftReady  = !FinchController.Left.IsConnected || leftReadyCalibrate && FinchController.Left.GetPressTime(FinchControllerElement.HomeButton) > Settings.TimePressingToCallCalibration;
            bool rightReady = !FinchController.Right.IsConnected || rightReadyCalibrate && FinchController.Right.GetPressTime(FinchControllerElement.HomeButton) > Settings.TimePressingToCallCalibration;

            if (Settings.AvailableMomentalCalibration)
            {
                if (FinchCore.Settings.ControllerType == FinchControllerType.Dash)
                {
                    if (leftReady)
                    {
                        FastCalibrate(FinchController.Left);
                        leftReadyCalibrate = false;
                    }

                    if (rightReady)
                    {
                        FastCalibrate(FinchController.Right);
                        rightReadyCalibrate = false;
                    }
                }
                else if (leftReady && rightReady)
                {
                    if (availableMomentalCalibration)
                    {
                        leftReadyCalibrate  = false;
                        rightReadyCalibrate = false;
                        FinchController.Left.HapticPulse(Settings.HapticTime);
                        FinchController.Right.HapticPulse(Settings.HapticTime);
                        FinchCore.Calibration(FinchChirality.Both);
                    }
                    else
                    {
                        leftReadyCalibrate  = false;
                        rightReadyCalibrate = false;

                        ResetCalibration();
                        Calibrate(Settings.Calibration);
                    }
                }
            }
            else if (FinchCore.NodesState.GetControllersCount() > 0 && leftReady && rightReady)
            {
                leftReadyCalibrate  = false;
                rightReadyCalibrate = false;

                ResetCalibration();
                Calibrate(Settings.Calibration);
            }
        }
Example #12
0
        public override void Init(int id)
        {
            base.Init(id);

            TutorialNotification.SetActive(true);
            WarningNotification.SetActive(false);

            FinchBodyRotationMode mode = FinchCore.NodesState.GetUpperArmCount() == 2 ? FinchBodyRotationMode.ShoulderRotation : FinchBodyRotationMode.HmdRotation;

            FinchCore.SetBodyRotationMode(mode);
        }
Example #13
0
        private void TryPassStep()
        {
            bool correctSet = FinchCore.NodesState.GetControllersCount() == 1 && FinchCore.NodesState.GetUpperArmCount() == 1;

            bool leftCapacityCorrect  = !FinchController.Left.IsConnected || FinchCore.GetCapacitySensor(FinchNodeType.LeftHand) == GetUpperArmChirality();
            bool rightCapacityCorrect = !FinchController.Right.IsConnected || FinchCore.GetCapacitySensor(FinchNodeType.RightHand) == GetUpperArmChirality();

            if (!correctSet || leftCapacityCorrect && rightCapacityCorrect)
            {
                NextStep();
            }
        }
Example #14
0
        private void Awake()
        {
            if (Settings.UpdateType != FinchUpdateType.HmdTransform)
            {
                UnityEngine.XR.InputTracking.disablePositionalTracking = true;
            }

            Application.targetFrameRate = 9000;

            FinchCore.Hmd    = Hmd ?? Camera.main.transform;
            FinchCore.Origin = Root;
            FinchCore.Init(Settings);
        }
Example #15
0
        public FinchProvider(FinchControllerType deviceType)
        {
            FinchInitError err = FinchCore.Init(deviceType);

            if (err != FinchInitError.None)
            {
                errorDetails = "Error creating/initializing Dash controller API: " + err;
                Debug.LogError(errorDetails);
                return;
            }
            FinchCore.LoadCalibrations();
            InitializeWatches();
            calibrationButtonState = new bool[(int)FinchChirality.Last];
        }
        private void TryCalibrate()
        {
            bool leftReady     = !FinchController.Left.IsConnected || leftReadyCalibrate && FinchController.Left.GetPressTime(FinchControllerElement.HomeButton) > Settings.TimeToCallModule;
            bool rightReady    = !FinchController.Right.IsConnected || rightReadyCalibrate && FinchController.Right.GetPressTime(FinchControllerElement.HomeButton) > Settings.TimeToCallModule;
            bool fastCalibrate = Settings.Calibration == CalibrationType.FastCalibration && PlayableSet.AllPlayableNodesConnected;
            bool useDash       = FinchCore.Settings.ControllerType == FinchControllerType.Dash;

            if (fastCalibrate && useDash)
            {
                if (leftReady)
                {
                    FastCalibrate(FinchController.Left);
                    leftReadyCalibrate = false;
                }

                if (rightReady)
                {
                    FastCalibrate(FinchController.Right);
                    rightReadyCalibrate = false;
                }
            }
            else if (FinchCore.NodesState.GetControllersCount() > 0 && leftReady && rightReady && !IsCalbrating)
            {
                leftReadyCalibrate  = false;
                rightReadyCalibrate = false;

                ResetCalibration();

                bool leftCapacityCorrect  = !FinchController.Left.IsConnected || FinchCore.GetCapacitySensor(FinchNodeType.LeftHand) == FinchChirality.Left;
                bool rightCapacityCorrect = !FinchController.Right.IsConnected || FinchCore.GetCapacitySensor(FinchNodeType.RightHand) == FinchChirality.Right;
                bool angleCorrect         = NodeAngleChecker.IsCorrectAngle;
                bool momentalCalibration  = leftCapacityCorrect && rightCapacityCorrect && angleCorrect && !useDash;

                if (fastCalibrate && momentalCalibration)
                {
                    FinchController.Left.HapticPulse(Settings.HapticTime);
                    FinchController.Right.HapticPulse(Settings.HapticTime);
                    FinchCore.Calibration(FinchChirality.Both);
                }
                else
                {
                    if (!(PlayableSet.AllPlayableNodesConnected))
                    {
                        PlayableSet.ResetSaveComlect();
                    }

                    Calibrate(PlayableSet.AllPlayableNodesConnected ? Settings.Calibration : CalibrationType.FullCalibration);
                }
            }
        }
            private void TrembleAcceleration()
            {
                Vector3 upperArmAccel = FinchCore.GetNodeLinearAcceleration(node);
                float   acceleration  = (upperArmAccel - Vector3.up * g).sqrMagnitude;

                if (Mathf.Abs(acceleration - lastAcceleration) > accelerationBorder)
                {
                    if ((acceleration - lastAcceleration > 0) != directionUp)
                    {
                        directionUp = !directionUp;
                        TrembleCount++;
                    }

                    lastAcceleration = acceleration;
                }
            }
Example #18
0
        public FinchControllerModel GetControllerModel(FinchNodeType nodeType)
        {
            string modelName = FinchCore.GetNodeModelNumber(nodeType);

            switch (modelName)
            {
            case "Dash":
                return(FinchControllerModel.Dash);

            case "Shift":
                return(FinchControllerModel.Shift);

            case "Dash M4":
                return(FinchControllerModel.DashM4);

            default:
                return(FinchControllerModel.Unknown);
            }
        }
            private void ArmDirection()
            {
                Vector3 origin = (node == FinchNodeType.RightUpperArm) ? Vector3.right : Vector3.left;
                float   y      = (FinchCore.GetNodeRotation(node, false) * origin).y;

                if (Mathf.Abs(y) < angleBorder)
                {
                    return;
                }

                if (y > 0)
                {
                    sideAboveZero += y;
                }
                else
                {
                    sideBelowZero -= y;
                }
            }
        private void TryBindChiralityManually()
        {
            bool pressLeft  = FinchInput.GetPressDown(FinchNodeType.LeftUpperArm, FinchControllerElement.HomeButton);
            bool pressRight = FinchInput.GetPressDown(FinchNodeType.RightUpperArm, FinchControllerElement.HomeButton);

            if (pressLeft || pressRight)
            {
                if (pressLeft)
                {
                    FinchCore.SwapNodes(FinchNodeType.LeftUpperArm, FinchNodeType.RightUpperArm);
                }

                if (!tremblePass)
                {
                    ResetValue();
                    tremblePass = true;
                }
            }
        }
        private void ResetCalibration()
        {
            bool wasLeftReverted  = FinchCore.Interop.FinchIsUpperArmReverted(FinchCore.Interop.FinchChirality.Left) == 1;
            bool wasRightReverted = FinchCore.Interop.FinchIsUpperArmReverted(FinchCore.Interop.FinchChirality.Right) == 1;

            FinchCore.ResetCalibration(FinchChirality.Both);

            if (wasLeftReverted)
            {
                FinchCore.Interop.FinchRevertUpperArm(FinchCore.Interop.FinchChirality.Left);
            }

            if (wasRightReverted)
            {
                FinchCore.Interop.FinchRevertUpperArm(FinchCore.Interop.FinchChirality.Right);
            }

            FinchCore.Update();
            NodeAngleChecker.Update();
        }
Example #22
0
        public override void ReadState(PlayerState outState)
        {
            base.ReadState(outState);

            for (int i = 0; i < PlayerState.Bones.BoneCount; ++i)
            {
                FinchBone bone = PlayerState.Bones[i];
                outState.Rotations[i]    = FinchCore.GetBoneRotation(bone);
                outState.Positions[i]    = FinchCore.GetBoneCoordinate(bone);
                outState.Available[i]    = FinchCore.IsBoneAvailable(bone);
                outState.BonesLengths[i] = FinchCore.GetBoneLength(bone);
            }

            outState.Positions[PlayerState.Bones[FinchBone.Head]] = outState.Positions[PlayerState.Bones[FinchBone.Neck]]
                                                                    + outState.Rotations[PlayerState.Bones[FinchBone.Hips]] * Vector3.up * outState.BonesLengths[PlayerState.Bones[FinchBone.Neck]];

            outState.Positions[PlayerState.Bones[FinchBone.RightEye]] = outState.Positions[PlayerState.Bones[FinchBone.Head]]
                                                                        + outState.Rotations[PlayerState.Bones[FinchBone.Head]] * Vector3.up * outState.BonesLengths[PlayerState.Bones[FinchBone.Head]]
                                                                        + outState.Rotations[PlayerState.Bones[FinchBone.Head]] * Vector3.forward * eyeForwardShift;
        }
Example #23
0
        protected static void UpdateLongPressDetection(FinchControllerElement element, bool handsDevice, PlayerState outState)
        {
            for (FinchChirality i = 0; i < FinchChirality.Last; ++i)
            {
                if (handsDevice)
                {
                    calibrationButtonState[(int)i] = false;
                }
                else
                {
                    outState.CalibrationButtonPressed[(int)i] = false;
                }

                if (FinchCore.GetEvent(i, element, FinchEventType.Begin))
                {
                    calibrationLongPressStopWatch[(int)i].Start();
                }

                if (FinchCore.GetEvent(i, element, FinchEventType.End))
                {
                    calibrationLongPressStopWatch[(int)i].Reset();
                }

                if (calibrationLongPressStopWatch[(int)i].ElapsedMilliseconds >= LongPressTimeMs)
                {
                    if (handsDevice)
                    {
                        calibrationButtonState[(int)i] = true;
                    }
                    else
                    {
                        outState.CalibrationButtonPressed[(int)i] = true;
                        calibrationLongPressStopWatch[(int)i].Reset();
                    }
                }
            }
        }
Example #24
0
 public void Recenter(FinchChirality chirality, FinchRecenterMode recenterMode)
 {
     FinchCore.Recenter(chirality, recenterMode);
 }
Example #25
0
 public virtual void Exit()
 {
     FinchCore.Exit();
 }
Example #26
0
 public void SetBoneLength(FinchBone bone, float length)
 {
     FinchCore.SetBoneLength(bone, length);
 }
Example #27
0
 public void ChangeDevice(FinchControllerType deviceType)
 {
     FinchCore.Init(deviceType);
 }
Example #28
0
 public void StartChiralityRedefine()
 {
     FinchCore.ChiralityRedefine(true);
 }
Example #29
0
 public void Calibrate(FinchChirality chirality, FinchRecenterMode recenterMode)
 {
     FinchCore.OnePoseAxisCalibration(chirality, recenterMode);
     Recenter(chirality, recenterMode);
     FinchCore.SaveCalibrations();
 }
Example #30
0
 public float GetBatteryCharge(FinchNodeType nodeType)
 {
     return(FinchCore.GetNodeCharge(nodeType));
 }