示例#1
0
 public void SetupJoystick()
 {
     if (FibrumInput.InitializeJoystickSetup())
     {
         FibrumInput.joystickSetupGO.StartSetup();
     }
 }
示例#2
0
 public void SetControl(FibrumInput.Button button,string description,Texture tex)
 {
     Init ();
     typeOfControl.Add(1);
     controlNumToSetup.Add((int)button);
     controlDescription.Add(description);
     if( tex!=null )	textures.Add (tex);
     else textures.Add (pressKeyTex);
 }
示例#3
0
 public void SetControl(FibrumInput.Axis axis,string description,Texture tex)
 {
     Init ();
     typeOfControl.Add(0);
     controlNumToSetup.Add((int)axis);
     controlDescription.Add(description);
     if( tex!=null )	textures.Add (tex);
     else textures.Add (moveJoysctickTex);
 }
示例#4
0
 //Событие выполняемое каждый кадр
 void Update()
 {
     if (Menu.IsVR)
     {
         if (Input.GetKeyDown(KeyCode.Escape) || FibrumInput.GetJoystickButtonDown(FibrumInput.Button.Y))
         {
             OnClickYes();
         }
     }
 }
示例#5
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);
     }
 }
示例#6
0
 public void SetupJoystickScripted()
 {
     if (FibrumInput.InitializeJoystickSetup())
     {
         FibrumInput.joystickSetupGO.ClearControls();
         FibrumInput.joystickSetupGO.SetTitle("Setup joystick input");
         FibrumInput.joystickSetupGO.SetControl(FibrumInput.Axis.Vertical1, true, "FORWARD\nChoose joystick axis to move forward", null);
         FibrumInput.joystickSetupGO.SetControl(FibrumInput.Axis.Horizontal1, false, "RIGHT\nChose joystick axis to move right", null);
         FibrumInput.joystickSetupGO.SetControl(FibrumInput.Button.A, "Chose button for fire", null);
         FibrumInput.joystickSetupGO.StartSetup();
     }
 }
示例#7
0
 //Событие выполняемое раз за кадр
 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;
         }
     }
 }
示例#8
0
 // Update is called once per frame
 void Update()
 {
     if (scanning)
     {
         if (typeOfControl[currentControl] == 0)
         {
             if (FibrumInput.ScanAndSetupAxis((FibrumInput.Axis)controlNumToSetup[currentControl]) != -1)
             {
                 checkMark.color = new Color(1f, 1f, 1f, 1f);
                 scanning        = false;
                 Invoke("NextControl", 1f);
             }
         }
         else if (typeOfControl[currentControl] == 1)
         {
             if (FibrumInput.ScanAndSetupButton((FibrumInput.Button)controlNumToSetup[currentControl]) != -1)
             {
                 checkMark.color = new Color(1f, 1f, 1f, 1f);
                 scanning        = false;
                 Invoke("NextControl", 1f);
             }
         }
         else if (typeOfControl[currentControl] == 2)
         {
             if (FibrumInput.ScanAndSetupAxisDir((FibrumInput.Axis)controlNumToSetup[currentControl], true) != -1)
             {
                 checkMark.color = new Color(1f, 1f, 1f, 1f);
                 scanning        = false;
                 Invoke("NextControl", 1f);
             }
         }
         else if (typeOfControl[currentControl] == 3)
         {
             if (FibrumInput.ScanAndSetupAxisDir((FibrumInput.Axis)controlNumToSetup[currentControl], false) != -1)
             {
                 checkMark.color = new Color(1f, 1f, 1f, 1f);
                 scanning        = false;
                 Invoke("NextControl", 1f);
             }
         }
     }
 }
示例#9
0
    //Инициализация начального состояния
    public void Init()
    {
        FibrumController.useAntiDrift           = useAntiDrift;
        FibrumController.useCompassForAntiDrift = useCompassForAntiDrift;

        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        Screen.orientation  = ScreenOrientation.LandscapeLeft;

        if (!SystemInfo.supportsGyroscope)
        {
            noGyroscope = true;
        }
        else
        {
            noGyroscope = false;
        }

        FibrumController.Init();

        gyroBiasArray = new float[128]; for (int k = 0; k < gyroBiasArray.Length; k++)
        {
            gyroBiasArray[k] = 0f;
        }

        InvokeRepeating("RecalculateGyroBias", 0.1f, 0.2f);

        FibrumInput.LoadJoystickPrefs();

        meanAcceleration = Input.acceleration;

        if (FibrumController.vrSetup == null)
        {
            GameObject _setup = GameObject.Instantiate((GameObject)Resources.Load("FibrumResources/VRSetup", typeof(GameObject))) as GameObject;
            FibrumController.vrSetup = _setup;
        }
    }
示例#10
0
    public void Init()
    {
        if (initialized)
        {
            return;
        }

        NewLensCorrection[] nlc = GetComponentsInChildren <NewLensCorrection>();
        cameras = new Camera[nlc.Length];
        for (int k = 0; k < cameras.Length; k++)
        {
            cameras[k] = nlc[k].gameObject.GetComponent <Camera>();
        }

        FibrumController.useAntiDrift           = useAntiDrift;
        FibrumController.useCompassForAntiDrift = useCompassForAntiDrift;

        FPStimeleft = FPSupdateInterval;

        /*if( blackFadeTex==null ) checkFPS=false;
         * if( checkFPS )
         * {
         *      blackScreen = 1f;
         *      needBlackScreen = 1f;
         *      Invoke ("CheckFPS",1.6f);
         * } */


        if (transform.Find("VRCamera"))
        {
            vrCameraLocal = transform.Find("VRCamera").transform;
        }
        else
        {
            vrCameraLocal = transform;
        }

        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        Screen.orientation  = ScreenOrientation.LandscapeLeft;

#if !UNITY_STANDALONE && !UNITY_EDITOR
        if (!SystemInfo.supportsGyroscope)
        {
            noGyroscope = true;
        }
        else
        {
            noGyroscope = false;
        }
#endif

        FibrumController.Init();

                #if UNITY_ANDROID && !UNITY_EDITOR
        gyroBiasArray = new float[128]; for (int k = 0; k < gyroBiasArray.Length; k++)
        {
            gyroBiasArray[k] = 0f;
        }

        if (noGyroscope)
        {
            transform.Find("VRCamera/WarningPlane").gameObject.SetActive(true);
            EnableCompass(true);
        }

        InvokeRepeating("RecalculateGyroBias", 0.1f, 0.2f);

        if (FibrumController.useCompassForAntiDrift)
        {
            EnableCompass(true);
        }
                #endif

                #if UNITY_IPHONE
        //transform.localRotation = Quaternion.Euler(90, 0 ,0);
                #elif (UNITY_WP8 || UNITY_WP_8_1) && !UNITY_EDITOR
        Input.gyro.enabled = true;
        //transform.localRotation = Quaternion.Euler(90, 0 ,0);
        c        = new WindowsPhoneVRController.Controller();
        rotation = Quaternion.identity;
                #endif

        FibrumController.vrCamera = this;

        bool     noDummyUI  = true;
        Camera[] allCameras = GetComponentsInChildren <Camera>();
        for (int k = 0; k < allCameras.Length; k++)
        {
            if (allCameras[k].rect.width <= 0.5f)
            {
                if (allCameras[k].gameObject.GetComponent <ChangeCameraEye>() == null)
                {
                    allCameras[k].gameObject.AddComponent <ChangeCameraEye>();
                }
            }
            else if (allCameras[k].clearFlags == CameraClearFlags.Color && allCameras[k].depth == -100)
            {
                noDummyUI = false;
            }
        }
        if (noDummyUI)
        {
            GameObject dummyGO = GameObject.Instantiate((GameObject)Resources.Load("FibrumResources/VR_UI_dummyCamera", typeof(GameObject))) as GameObject;
            dummyGO.transform.parent        = vrCameraLocal;
            dummyGO.transform.localPosition = Vector3.zero;
            dummyGO.transform.localRotation = Quaternion.identity;
        }


        if (!noGyroscope)
        {
            Invoke("SensorCalibration", 0.1f);
        }
        FibrumInput.LoadJoystickPrefs();

        meanAcceleration = Input.acceleration;

        if (FibrumController.vrSetup == null)
        {
            GameObject _setup = GameObject.Instantiate((GameObject)Resources.Load("FibrumResources/VRSetup", typeof(GameObject))) as GameObject;
            FibrumController.vrSetup = _setup;
        }

        useLensCorrection = useLensCorrection;

        initialized = true;
    }
示例#11
0
    void LateUpdate()
    {
        float zoomSpeed = FibrumInput.FibAxis(FibrumInput.FibJoystick.Vertical) * Time.deltaTime * 10;

        if (Input.GetAxis("Vertical") != 0)
        {
            zoomSpeed = Input.GetAxis("Vertical");
        }



        #if UNITY_EDITOR || UNITY_STANDALONE
        Vector3 euler = rotation.eulerAngles;
        //rotation = Quaternion.Euler(Mathf.Max (-89f,Mathf.Min (89f,Mathf.DeltaAngle(0,euler.x)+mouseSensitivity*(oldMousePosition.y-Input.mousePosition.y))),euler.y-mouseSensitivity*(oldMousePosition.x-Input.mousePosition.x),0f);
        rotation = Quaternion.Euler(Mathf.Max(-89f, Mathf.Min(89f, Mathf.DeltaAngle(0, euler.x) - mouseSensitivity * Input.GetAxis("Mouse Y"))), euler.y + mouseSensitivity * Input.GetAxis("Mouse X"), 0f);
        vrCameraLocal.localRotation = rotation;
        oldMousePosition            = Input.mousePosition;
#elif UNITY_ANDROID && !UNITY_EDITOR
        if (!noGyroscope)
        {
            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]));

            TransformFromMatrix(matrix, vrCameraLocal);
            float deltaRotation = vrCameraLocal.localRotation.eulerAngles.y - oldRotationY;

            if (FibrumInput.FibButton(FibrumInput.FibJoystick.ButDown))
            {
                deltaRotation = 0;
            }

            while (deltaRotation > 180f)
            {
                deltaRotation -= 360f;
            }
            while (deltaRotation < -180f)
            {
                deltaRotation += 360f;
            }
            gyroYaccel       = Mathf.Lerp(gyroYaccel, (deltaRotation - oldDeltaRotation) / Time.deltaTime, Time.deltaTime);
            oldDeltaRotation = deltaRotation;
            oldRotationY     = vrCameraLocal.localRotation.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;
                }
            }

            vrCameraLocal.localRotation = Quaternion.Euler(vrCameraLocal.localRotation.eulerAngles.x, rotationY, vrCameraLocal.localRotation.eulerAngles.z);
        }
        else
        {
            Vector3 gravity = Input.acceleration;
            float   fi      = Mathf.Rad2Deg * Mathf.Atan(-gravity.z / (Mathf.Sign(gravity.y) * Mathf.Sqrt(gravity.y * gravity.y + gravity.x * gravity.x * 0.01f)));
            float   teta    = Mathf.Rad2Deg * Mathf.Atan(-gravity.x / (Mathf.Sqrt(gravity.z * gravity.z + gravity.y * gravity.y)));
            rotation = Quaternion.Slerp(rotation, Quaternion.Euler(-fi, Input.compass.magneticHeading - initCompassHeading, teta), Time.deltaTime * 4.0f);
            vrCameraLocal.localRotation = rotation;
        }
#elif UNITY_IPHONE
        rot = ConvertRotation(Input.gyro.attitude);

        float y = vrCameraLocal.eulerAngles.y;

        vrCameraLocal.localRotation = Quaternion.Euler(90f, 0f, 0f) * rot;

        if (Controller.IsCameraLocked)
        {
            free = false;
            vrCameraLocal.eulerAngles = new Vector3(vrCameraLocal.eulerAngles.x, angle = y, vrCameraLocal.eulerAngles.z);
        }
        else
        {
            if (!free)
            {
                free  = true;
                angle = vrCameraLocal.eulerAngles.y - angle;
            }

            vrCameraLocal.eulerAngles = new Vector3(vrCameraLocal.eulerAngles.x, vrCameraLocal.eulerAngles.y - angle, vrCameraLocal.eulerAngles.z);
        }
#elif UNITY_WP8 || UNITY_WP_8_1
        //rot = ConvertRotation(Input.gyro.attitude);
        //vrCameraLocal.localRotation = rot;
        //print (vrCameraLocal.localRotation.eulerAngles);
        float vertical_angle_delta   = (float)c.AngularVelocityY * Time.deltaTime;
        float horisontal_angle_delta = (float)c.AngularVelocityX * Time.deltaTime;
        float z_angle_delta          = (float)c.AngularVelocityZ * Time.deltaTime;
        rotation = Quaternion.Euler(rotation.eulerAngles.x + vertical_angle_delta, rotation.eulerAngles.y - horisontal_angle_delta, rotation.eulerAngles.z + z_angle_delta);
        Vector3 gravity = Input.acceleration;
        float   fi      = Mathf.Rad2Deg * Mathf.Atan(-gravity.z / (Mathf.Sign(gravity.y) * Mathf.Sqrt(gravity.y * gravity.y + gravity.x * gravity.x * 0.01f)));
        float   teta    = Mathf.Rad2Deg * Mathf.Atan(-gravity.x / (Mathf.Sqrt(gravity.z * gravity.z + gravity.y * gravity.y)));
        rotation = Quaternion.Slerp(rotation, Quaternion.Euler(-fi, rotation.eulerAngles.y, teta), Time.deltaTime * 2f);
        //vrCameraLocal.localRotation = Quaternion.Euler(90f,0f,0f)*rotation;
        vrCameraLocal.localRotation = rotation;
        //vrCameraLocal.localRotation = Quaternion.Euler(-fi,0f,teta);
#endif

        meanAcceleration = Vector3.Lerp(meanAcceleration, Input.acceleration, Time.deltaTime * 2.0f);
        if (meanAcceleration.x > 0.25f && Mathf.Abs(meanAcceleration.y) < 0.1f && (meanAcceleration - Input.acceleration).magnitude < 0.5f)
        {
            FibrumController.isHandOriented = true;
        }
        else
        {
            FibrumController.isHandOriented = false;
        }

        ////////////////////////////////////////
        // MEASURE FPS
        ////////////////////////////////////////
        FPStimeleft -= Time.deltaTime;
        FPSaccum    += Time.timeScale / Time.deltaTime;
        ++FPSframes;
        if (FPStimeleft <= 0.0)
        {
            fps         = FPSaccum / FPSframes;
            FPStimeleft = FPSupdateInterval;
            FPSaccum    = 0.0F;
            FPSframes   = 0;
        }

        /*if( checkFPS )
         * {
         *      blackScreen = Mathf.Lerp(blackScreen,needBlackScreen,Time.deltaTime*5f);
         * } */
    }
示例#12
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;
        }
    }