示例#1
0
        public void ReadState(ControllerState outState)
        {
            var nativeControllerState = new NativeControllerState();

            ReadControllerState(out nativeControllerState);

            outState.connectionState = nativeControllerState.connectionState;
            outState.orientation     = new Quaternion(
                -nativeControllerState.orientation.y,
                -nativeControllerState.orientation.z,
                nativeControllerState.orientation.w,
                nativeControllerState.orientation.x);

            outState.gyro             = new Vector3(-nativeControllerState.gyro.x, -nativeControllerState.gyro.y, nativeControllerState.gyro.z);
            outState.accel            = new Vector3(nativeControllerState.accel.x, nativeControllerState.accel.y, -nativeControllerState.accel.z);
            outState.touchPos         = nativeControllerState.touchPos;
            outState.isTouching       = nativeControllerState.isTouching;
            outState.touchDown        = nativeControllerState.isTouching && !prevTouchState;
            outState.touchUp          = !nativeControllerState.isTouching && prevTouchState;
            outState.appButtonState   = nativeControllerState.appButtonState;
            outState.appButtonDown    = nativeControllerState.appButtonState && !prevAppButtonState;
            outState.appButtonUp      = !nativeControllerState.appButtonState && prevAppButtonState;
            outState.clickButtonState = nativeControllerState.clickButtonState;
            outState.clickButtonDown  = nativeControllerState.clickButtonState && !prevClickButtonState;
            outState.clickButtonUp    = !nativeControllerState.clickButtonState && prevClickButtonState;

            prevTouchState       = nativeControllerState.isTouching;
            prevAppButtonState   = nativeControllerState.appButtonState;
            prevClickButtonState = nativeControllerState.clickButtonState;
        }
示例#2
0
        /// <summary>
        /// Convert the native controller state.
        /// </summary>
        /// <param name="nativeState">State of the native.</param>
        private static void ConvertState(ref NativeControllerState nativeState)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            switch (nativeState.ConnectionState)
            {
            case 0:
                controllerState.ConnectionState = ConnectionState.Disconnected;
                break;

            case 1:
                controllerState.ConnectionState = ConnectionState.Connected;
                break;

            case 2:
                controllerState.ConnectionState = ConnectionState.Connecting;
                break;

            default:
                controllerState.ConnectionState = ConnectionState.Disconnected;
                break;
            }

            controllerState.IsTouching    = nativeState.IsTouching == 0x01;
            controllerState.TouchDown     = nativeState.TouchDown == 0x01;
            controllerState.TouchUp       = nativeState.TouchUp == 0x01;
            controllerState.TouchPosition = new Vector2(nativeState.TouchPos.X, nativeState.TouchPos.Y);
            controllerState.Orientation   = new Quaternion(nativeState.Orientation.X, nativeState.Orientation.Y, nativeState.Orientation.Z, nativeState.Orientation.W);

            if (useOCArmModel)
            {
                // use oculus' arm model
                controllerState.Position = new Vector3(nativeState.Position.X, nativeState.Position.Y, nativeState.Position.Z);
            }
            else
            {
                // use our arm model
                controllerState.Position = ArmModel.Instance.WristPosition;
            }

            controllerState.ClickButtonState        = nativeState.ClickButtonState == 0x01;
            controllerState.ClickButtonDown         = nativeState.ClickButtonDown == 0x01;
            controllerState.ClickButtonUp           = nativeState.ClickButtonUp == 0x01;
            controllerState.AppButtonState          = nativeState.AppButtonState == 0x01;
            controllerState.AppButtonDown           = nativeState.AppButtonDown == 0x01;
            controllerState.AppButtonUp             = nativeState.AppButtonUp == 0x01;
            controllerState.MenuButtonState         = nativeState.MenuButtonState == 0x01;
            controllerState.MenuButtonDown          = nativeState.MenuButtonDown == 0x01;
            controllerState.MenuButtonUp            = nativeState.MenuButtonUp == 0x01;
            controllerState.Recentered              = nativeState.Recentered == 0x01;
            controllerState.BatteryPercentRemaining = (int)nativeState.BatteryPercentRemaining;
#endif
        }
示例#3
0
        /// <summary>
        /// Updates the controller.
        /// </summary>
        private void UpdateStates()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            ReadHMDState(ref this.hmdState);
            NativeControllerState nativeControllerState = new NativeControllerState();
            ReadControllerStateForUnity(ref nativeControllerState);
            ConvertState(ref nativeControllerState);

            if (!useOCArmModel && ArmModel.Instance != null)
            {
                ArmModel.Instance.OnControllerUpdate();
            }
#endif
        }
示例#4
0
        public void ReadState(ControllerState outState)
        {
            var nativeControllerState = new NativeControllerState();

            ReadControllerState(out nativeControllerState);

            outState.connectionState = nativeControllerState.connectionState;
            outState.orientation     = new Quaternion(
                -nativeControllerState.orientation.y,
                -nativeControllerState.orientation.z,
                nativeControllerState.orientation.w,
                nativeControllerState.orientation.x);

            outState.gyro = new Vector3(
                -nativeControllerState.gyro.x, -nativeControllerState.gyro.y, nativeControllerState.gyro.z);
            outState.accel = new Vector3(
                nativeControllerState.accel.x, nativeControllerState.accel.y, -nativeControllerState.accel.z);
            outState.touchPos     = nativeControllerState.touchPos;
            outState.batteryLevel = (GvrControllerBatteryLevel)nativeControllerState.batteryLevel;
            outState.isCharging   = nativeControllerState.isCharging;
            outState.recentered   = nativeControllerState.isRecentered;

            outState.buttonsState = 0;
            if (nativeControllerState.appButtonState)
            {
                outState.buttonsState |= GvrControllerButton.App;
            }

            if (nativeControllerState.clickButtonState)
            {
                outState.buttonsState |= GvrControllerButton.TouchPadButton;
            }

            if (nativeControllerState.homeButtonState)
            {
                outState.buttonsState |= GvrControllerButton.System;
            }

            if (nativeControllerState.isTouching)
            {
                outState.buttonsState |= GvrControllerButton.TouchPadTouch;
            }

            outState.SetButtonsUpDownFromPrevious(prevButtonsState);
            prevButtonsState = outState.buttonsState;
        }
示例#5
0
    /// <summary>
    /// Converts the state.
    /// </summary>
    /// <param name="nativeState">State of the native.</param>
    /// <returns>the controller state</returns>
    private static MIControllerState ConvertState(NativeControllerState nativeState)
    {
        MIControllerState state = new MIControllerState();

#if UNITY_ANDROID && !UNITY_EDITOR
        switch (nativeState.ConnectionState)
        {
        case 0:
            state.ConnectionState = MIConnectionState.Disconnected;
            break;

        case 1:
            state.ConnectionState = MIConnectionState.Connected;
            break;

        case 2:
            state.ConnectionState = MIConnectionState.Connecting;
            break;

        default:
            state.ConnectionState = MIConnectionState.Disconnected;
            break;
        }

        state.IsTouching    = nativeState.IsTouching == 0x01;
        state.TouchDown     = nativeState.TouchDown == 0x01;
        state.TouchUp       = nativeState.TouchUp == 0x01;
        state.TouchPosition = new Vector2(nativeState.TouchPos.X, nativeState.TouchPos.Y);
        state.Orientation   = new Quaternion(nativeState.Orientation.X, nativeState.Orientation.Y, nativeState.Orientation.Z, nativeState.Orientation.W);

        const int ClickButtonIndex = 0;
        state.ClickButtonState = nativeState.ButtonState[ClickButtonIndex] == 0x01;
        state.ClickButtonDown  = nativeState.ButtonDown[ClickButtonIndex] == 0x01;
        state.ClickButtonUp    = nativeState.ButtonUp[ClickButtonIndex] == 0x01;

        const int AppButtonIndex = 1;
        state.AppButtonState = nativeState.ButtonState[AppButtonIndex] == 0x01;
        state.AppButtonDown  = nativeState.ButtonDown[AppButtonIndex] == 0x01;
        state.AppButtonUp    = nativeState.ButtonUp[AppButtonIndex] == 0x01;
        state.Recentered     = nativeState.Recentered == 0x01;
#endif
        return(state);
    }
示例#6
0
 private static extern void ReadControllerState(out NativeControllerState nativeControllerState);
示例#7
0
 private static extern void ReadControllerState(out NativeControllerState nativeControllerState, int controller_id);
示例#8
0
 private static extern void ReadControllerStateForUnity(ref NativeControllerState state);