コード例 #1
0
 //Событие выполняемое каждый кадр
 void Update()
 {
     if (Menu.IsVR)
     {
         if (Input.GetKeyDown(KeyCode.Escape) || FibrumInput.GetJoystickButtonDown(FibrumInput.Button.Y))
         {
             OnClickYes();
         }
     }
 }
コード例 #2
0
 // Update is called once per frame
 void Update()
 {
     cc.SimpleMove(speed * vrCamera.vrCameraHeading.TransformDirection(Vector3.forward * FibrumInput.GetJoystickAxis(FibrumInput.Axis.Vertical1) + Vector3.right * FibrumInput.GetJoystickAxis(FibrumInput.Axis.Horizontal1)));
     if (FibrumInput.GetJoystickButtonDown(FibrumInput.Button.A))
     {
         GameObject bullet = Instantiate(bulletPrefab, vrCamera.vrCameraHeading.transform.position + vrCamera.vrCameraHeading.transform.TransformDirection(Vector3.forward * 0.5f - Vector3.up * 0.5f), vrCamera.vrCameraHeading.transform.rotation) as GameObject;
         bullet.GetComponent <Rigidbody>().AddRelativeForce(Vector3.forward * 20f, ForceMode.Impulse);
         Destroy(bullet, 10f);
     }
 }
コード例 #3
0
ファイル: VoiceControl.cs プロジェクト: Oniskiv/Magistracy
 //Событие выполняемое раз за кадр
 void LateUpdate()
 {
     if (FibrumInput.GetJoystickButtonDown(FibrumInput.Button.X))
     {
         if (!isListening)
         {
             isListening = true;
             speechManager.StartListening(3, "ru-Ru");
             imageVoice.color = Color.green;
         }
         else
         {
             isListening = false;
             speechManager.StopListening();
             imageVoice.color = Color.red;
         }
     }
 }
コード例 #4
0
    //Событие выполняемое раз за кадр
    void LateUpdate()
    {
        Matrix4x4 matrix = new Matrix4x4();

        //получение данных с гироскопа и вычисление углов отклонения
        float[] M = FibrumController.vrs._ao.CallStatic <float[]>("getHeadMatrix");

        matrix.SetColumn(0, new Vector4(M[0], M[4], -M[8], M[12]));
        matrix.SetColumn(1, new Vector4(M[1], M[5], -M[9], M[13]));
        matrix.SetColumn(2, new Vector4(-M[2], -M[6], M[10], M[14]));
        matrix.SetColumn(3, new Vector4(M[3], M[7], M[11], M[15]));

        Quaternion ee            = TransformFromMatrix(matrix);
        float      deltaRotation = ee.eulerAngles.y - oldRotationY;

        while (deltaRotation > 180f)
        {
            deltaRotation -= 360f;
        }
        while (deltaRotation < -180f)
        {
            deltaRotation += 360f;
        }
        gyroYaccel       = Mathf.Lerp(gyroYaccel, (deltaRotation - oldDeltaRotation) / Time.deltaTime, Time.deltaTime);
        oldDeltaRotation = deltaRotation;
        oldRotationY     = ee.eulerAngles.y;

        if (Mathf.Abs(gyroYaccel) > 0.2f)
        {
            gyroBiasPause = Time.realtimeSinceStartup + 1f;
        }
        if (Time.realtimeSinceStartup > gyroBiasPause)
        {
            meanDeltaGyroY = Mathf.Lerp(meanDeltaGyroY, deltaRotation / Time.deltaTime, Time.deltaTime * 10f);
            AddToGyroBiasArray(meanDeltaGyroY);
        }

        rotationY += deltaRotation - gyroBias * Time.deltaTime;

        //устранение дрифтов гироскопа
        while (rotationY > 180f)
        {
            rotationY -= 360f;
        }
        while (rotationY < -180f)
        {
            rotationY += 360f;
        }
        if (FibrumController.useCompassForAntiDrift)
        {
            float compassDeltaRotationY = rotationY - (Input.compass.magneticHeading - initCompassHeading);
            while (compassDeltaRotationY > 180f)
            {
                compassDeltaRotationY -= 360f;
            }
            while (compassDeltaRotationY < -180f)
            {
                compassDeltaRotationY += 360f;
            }
            if (Time.realtimeSinceStartup > gyroBiasPause - 0.7f)
            {
                rotationY -= compassDeltaRotationY * Time.deltaTime * 1.5f;
            }
            else
            {
                rotationY -= compassDeltaRotationY * Time.deltaTime * 0.2f;
            }
        }

        Quaternion qq = Quaternion.Euler(ee.eulerAngles.x, rotationY, ee.eulerAngles.z);

        try
        {
            //изменение цвета иконок на экране
            if (FibrumInput.GetJoystickButtonDown(FibrumInput.Button.B))
            {
                if (!isEnableMove)
                {
                    isEnableMove    = true;
                    startMoveX      = qq.eulerAngles.y;
                    startMoveY      = qq.eulerAngles.x;
                    imageMove.color = Color.green;
                }
                else
                {
                    Move(Directions.STOP);
                    isStopMove      = false;
                    prevStopMove    = true;
                    isEnableMove    = false;
                    imageMove.color = Color.red;
                }
            }

            if (FibrumInput.GetJoystickButtonDown(FibrumInput.Button.A))
            {
                isEnableMove = false;
                SceneManager.LoadScene(Constants.SCENE_MENU_VR);
            }
        } catch (Exception)
        { }

        Debug.Log("MMM");
        if (isEnableMove)             //если включен режим движения, то ...
        {
            moveX = qq.eulerAngles.y; //получение значения угла отклонения по оси X с гироскопа
            moveY = qq.eulerAngles.x; //получение значения угла отклонения по оси Y с гироскопа
            moveX = (360f - (startMoveX - moveX));
            moveY = (360f - (startMoveY - moveY));
            moveX = moveX > 360 ? moveX - 360 : moveX;
            moveY = moveY > 360 ? moveY - 360 : moveY;
            Debug.Log(moveX);
            if (moveX < MagicNumbers.MAGIC_ANGEL && moveX > (MagicNumbers.MAGIC_LIMIT + sensitivity))//поворот робота направо
            {
                if (currentMove != Directions.RIGHT)
                {
                    isStopMove = true;
                }
                currentMove  = Directions.RIGHT;
                prevStopMove = false;
            }
            else if (moveX > MagicNumbers.MAGIC_ANGEL && moveX < (MagicNumbers.MAGIC_FULL_ANGEL - MagicNumbers.MAGIC_LIMIT - sensitivity))//поворот робота налево
            {
                if (currentMove != Directions.LEFT)
                {
                    isStopMove = true;
                }
                currentMove  = Directions.LEFT;
                prevStopMove = false;
            }
            else if (moveY < MagicNumbers.MAGIC_ANGEL && moveY > (MagicNumbers.MAGIC_LIMIT + sensitivity))//движение робота назад
            {
                if (currentMove != Directions.BACK)
                {
                    isStopMove = true;
                }
                currentMove  = Directions.BACK;
                prevStopMove = false;
            }
            else if (moveY > MagicNumbers.MAGIC_ANGEL && moveY < (MagicNumbers.MAGIC_FULL_ANGEL - MagicNumbers.MAGIC_LIMIT - sensitivity))//движение робота вперед
            {
                if (currentMove != Directions.FORWARD)
                {
                    isStopMove = true;
                }
                currentMove  = Directions.FORWARD;
                prevStopMove = false;
            }
            else if ((moveX < (MagicNumbers.MAGIC_LIMIT + sensitivity) && moveX >= MagicNumbers.MAGIC_ZERO_F) || (moveX > (MagicNumbers.MAGIC_FULL_ANGEL - MagicNumbers.MAGIC_LIMIT + sensitivity) && moveX <= MagicNumbers.MAGIC_FULL_ANGEL))//остановка робота
            {
                currentMove = Directions.STOP;
                if (!prevStopMove)
                {
                    isStopMove = true;
                }
                prevStopMove = true;
            }

            if (isStopMove)//передача команды остановки движения роботу
            {
                Move(Directions.STOP);
                isStopMove   = false;
                prevStopMove = true;
            }
            else if (!prevStopMove)//передача команд движения роботу
            {
                Move(currentMove);
            }
        }

        if (isLogging)//логирование координат на экран, если оно включено в настройках
        {
            text1.text = "X: " + moveX + "\n" + "Y: " + moveY;
        }
    }