Наследование: UnrealBuildTool.ModuleRules
Пример #1
0
 public SteamVRController(string name, int index, InputTransform inputTransform) : base(name)
 {
     m_Index          = (uint)index;
     m_InputTransform = inputTransform;
     // Write the controller's properties
     XDevicePlugin.SetBool(handle, XDevicePlugin.kField_IsAbsRotation, true);
 }
Пример #2
0
    protected virtual void OnVRContextInited(VRContext context)
    {
        //
        if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0) & 0xF000) != 0x4000)
        {
            Destroy(this);
            Ximmerse.Log.w("TrackedHead", "TrackedHead only works in Outside-in!!!");
            return;
        }
        else
        {
            VRDevice vrDevice = context.vrDevice;
            if (vrDevice.outsideInMarkPose.position != Vector3.zero)
            {
                markTransform.localPosition = vrDevice.outsideInMarkPose.position;
            }
        }
        //
        if (eyeContainer == null)
        {
            eyeContainer = new GameObject("Rotate-Pivot").transform;
            eyeContainer.SetParent(transform);
            //
            eyeContainer.localPosition = Vector3.zero;
            eyeContainer.localRotation = Quaternion.identity;
            eyeContainer.localScale    = Vector3.one;
            //
            if (context.vrDevice != null && context.vrDevice.family != "Dummy")
            {
                markTransform.localPosition = markTransform.localPosition + context.vrDevice.neckToEye;
                eyeContainer.localPosition  = context.vrDevice.neckToEye;
#if UNITY_EDITOR
                // Editor features.
                if (m_Gizmos.Length > 0 && m_Gizmos[0] != null)
                {
                    m_Gizmos[0].transform.localPosition = m_Gizmos[0].transform.localPosition + context.vrDevice.neckToEye;
                }
#endif
            }
        }
        //
        for (int i = 0; i < 3; ++i)
        {
            Transform eye = context.GetAnchor(VRNode.LeftEye + i, null);
            if (eye != null)
            {
                eye.SetParent(eyeContainer, false);
            }
        }
        //
        switch (PlayerPrefsEx.GetInt("XimmerseDevice.type", 0))
        {
        // No head tracking.
        case 0x1010:
            source            = ControllerType.None;
            m_ControllerInput = null;
            break;
        }
    }
Пример #3
0
    private void Update()
    {
        XDevicePlugin.UpdateInputState(m_trackingCameraHandle);
        XDevicePlugin.UpdateInputState(m_leftControllerHandle);
        XDevicePlugin.UpdateInputState(m_rightControllerHandle);

        UpdateLeftController();
    }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 public SixenseController(SixenseControllerManager manager, string name, int index) : base(name)
 {
     this.manager        = manager;
     this.index          = index;
     this.inputTransform = this.manager.inputTransforms.Length == 1?this.manager.inputTransforms[0]:this.manager.inputTransforms[index];
     this.rawData        = new SixensePluginLite.sixenseControllerData();
     // Write the controller's properties
     XDevicePlugin.SetBool(handle, XDevicePlugin.kField_IsAbsRotation, true);
 }
Пример #5
0
        //
        public override int GetInputState(ref XDevicePlugin.ControllerState state)
        {
            if (m_Device.connected)
            {
                Vector2 v2;
                //
                v2 = m_Device.GetAxis(EVRButtonId.k_EButton_Axis1);
                state.axes[(int)ControllerAxis.PrimaryTrigger] = v2.x;
                v2 = m_Device.GetAxis(EVRButtonId.k_EButton_Axis0);
                state.axes[(int)ControllerAxis.PrimaryThumbX] = v2.x;
                state.axes[(int)ControllerAxis.PrimaryThumbY] = v2.y;
                //
                state.buttons = 0;
                if (m_Device.GetHairTrigger())
                {
                    state.buttons |= (uint)XimmerseButton.Trigger;
                }
                if (m_Device.GetPress(SteamVR_Controller.ButtonMask.Grip))
                {
                    state.buttons |= (uint)XimmerseButton.Grip;
                }

                if (m_Device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
                {
                    state.buttons |= (uint)XimmerseButton.Touch;
                }
                if (m_Device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
                {
                    state.buttons |= (uint)XimmerseButton.Click;
                }

                if (m_Device.GetPress(SteamVR_Controller.ButtonMask.ApplicationMenu))
                {
                    state.buttons |= (uint)XimmerseButton.App;
                }
                if (m_Device.GetPress(SteamVR_Controller.ButtonMask.System))
                {
                    state.buttons |= (uint)XimmerseButton.Home;
                }

                //
                TrackedDevicePose_t pose = m_UseOnNewPoses?m_Pose:m_Device.GetPose();
                XDevicePlugin.SetInt(handle, XDevicePlugin.kField_TrackingResultInt, (int)(pose.bPoseIsValid?TrackingResult.PoseTracked:TrackingResult.NotTracked));
                SteamVR_Utils.RigidTransform rt = new SteamVR_Utils.RigidTransform(pose.mDeviceToAbsoluteTracking);
                Vector3 v3 = rt.pos;
                state.position[0] = v3.x;
                state.position[1] = v3.y;
                state.position[2] = -v3.z;
                Quaternion q = rt.rot;
                state.rotation[0] = -q.x;
                state.rotation[1] = -q.y;
                state.rotation[2] = q.z;
                state.rotation[3] = q.w;
                //
            }
            return(0);
        }
Пример #6
0
 protected virtual void Awake()
 {
     m_FadeUiRoot = uiRoot.GetComponent <Ximmerse.UI.UIFade>();
     //
     XDevicePlugin.Init();
     for (int i = 0, imax = devices.Length; i < imax; ++i)
     {
         devices[i].Awake();
     }
 }
Пример #7
0
        public void setHMDRotation()
        {
            Quaternion qua = Quaternion.identity;

            if (main != null)
            {
                qua = (s_Main.vrDevice == null)?Quaternion.identity:s_Main.vrDevice.GetRotation();
            }
            //Debug.Log("setHMDRotation:"+qua);
            XDevicePlugin.setHMDRotation(qua);
        }
Пример #8
0
    public override void Launch(bool checkOthers)
    {
        //
        XDevicePlugin.Init();
        XDevicePlugin.SetInt(-1, XDevicePlugin.kField_CtxDeviceVersion, 0x3000);
        //
        base.Launch(checkOthers);
        // Create control points in runtime.
        Transform trackingSpace = VRContext.GetAnchor(VRNode.TrackingSpace);

        for (int i = 0; i < 3; ++i)
        {
            if (docks[i] != null)
            {
                GameObject go   = Instantiate(docks[i]);
                Transform  t    = docks[i].transform;
                Transform  newT = go.transform;
                //
                go.name = docks[i].name;

                newT.SetParent(trackingSpace);
                newT.localPosition = t.localPosition;
                newT.localRotation = t.localRotation;
                newT.localScale    = t.localScale;
                //
                docks[i] = go;
            }
        }
        // Initialize play area.
        m_PlayAreaRenderer = docks[2].GetComponentInChildren <PlayAreaRenderer>();
        if (m_PlayAreaRenderer != null)
        {
            m_PlayArea    = m_PlayAreaRenderer.transform;
            m_BoundaryPtr = NativeMethods.Boundary_Alloc(-1, 4, -2.0f, 2.0f);
            for (int i = 0, imax = m_PlayAreaRenderer.corners.Length; i < imax; ++i)
            {
                NativeMethods.Boundary_SetCorner(m_BoundaryPtr, i,
                                                 m_PlayAreaRenderer.corners[i].x, -m_PlayAreaRenderer.corners[i].z
                                                 );
            }
        }
        //
        Transform head = VRContext.GetAnchor(VRNode.Head);

        if (head != null)
        {
            TrackedHead trackedHead = head.GetComponent <TrackedHead>();
            if (trackedHead != null)
            {
                trackedHead.markTransform.localPosition =
                    head.InverseTransformPoint(anchor.position);
            }
        }
    }
Пример #9
0
 /// <summary>
 /// Center tracking to the current position and orientation of the HMD.
 /// </summary>
 public virtual void Recenter()
 {
     //
     if (XDevicePlugin.GetBool(m_Handle, XDevicePlugin.kField_IsAbsRotationBool, false))
     {
         return;
     }
     //
     if (useUnityVR)
     {
         UnityEngine.VR.InputTracking.Recenter();
     }
 }
Пример #10
0
 public void OnApplicationPause(bool isPause)
 {
     #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_IOS
     if (isPause)
     {
         XDevicePlugin.OnPause();
     }
     else
     {
         XDevicePlugin.OnResume();
     }
     #else
     XDevicePlugin.OnPauseUnity(isPause);
     #endif
 }
Пример #11
0
        public override bool InitAllControllers()
        {
#if GOOGLE_VR_SDK
            bool ret = base.InitAllControllers();
            if (ret)
            {
                controllers = new DaydreamController[1] {
                    new DaydreamController(this, "DaydreamController-0")
                };
            }
            return(ret);
#else
            XDevicePlugin.RemoveInputDeviceAt(XDevicePlugin.GetInputDeviceHandle("DaydreamController-0"));
            return(false);
#endif
        }
Пример #12
0
        /// <summary>
        ///
        /// </summary>
        public override bool InitAllControllers()
        {
            //
            if (m_IsInited)
            {
                return(false);
            }
            m_IsInited = true;
            //
            int ret;

            ret = XDevicePlugin.Init();
            if (ret != 0)
            {
                return(false);
            }
            ret = SixensePluginLite.sixenseInit();
            if (ret != 0)
            {
                return(false);
            }
            //
            if (maxControllers <= 0)
            {
                maxControllers = SixensePluginLite.sixenseGetMaxControllers();
            }
            if (controllers == null)
            {
                if (inputTransforms.Length == 0)
                {
                    inputTransforms = new InputTransform[1] {
                        null
                    };
                }
                controllers = new SixenseController[maxControllers];
                for (int i = 0; i < maxControllers; ++i)
                {
                    controllers[i] = new SixenseController(
                        this,
                        string.Format(controllerFormat, i), i
                        );
                }
            }
            //
            m_Result = 0;
            return(true);
        }
Пример #13
0
    public virtual void CheckBounds()
    {
        //
        if (m_TrackerHandle == -1 ||
            XDevicePlugin.GetInt(m_TrackerHandle, XDevicePlugin.kField_ConnectionStateInt, 0) != (int)DeviceConnectionState.Connected
            )
        {
            return;
        }
        //
        BoundaryTestResult hitInfo  = new BoundaryTestResult();
        Vector3            position = Vector3.zero;
        float minDistance           = float.MaxValue;
        int   intRet;

        for (int i = 0, imax = trackedNodes.Length; i < imax; ++i)
        {
            intRet = NativeMethods.XDeviceTestNode(m_TrackerHandle, trackedNodes[i], ref hitInfo);
            if (intRet >= 0)
            {
                if (intRet == 0)              // False => outside
                {
                    if (hitInfo.distance != float.MaxValue && hitInfo.distance > 0.0f)
                    {
                        hitInfo.distance *= -1;
                    }
                }
                if (hitInfo.distance < minDistance)
                {
                    minDistance = hitInfo.distance;
                }
            }
        }
        if (m_PlayArea != null)
        {
            float alpha = 1.0f - Mathf.Clamp01(minDistance / warningDistance);
            //
            m_PlayArea.groundAlpha = m_GroundAlpha;
            m_PlayArea.wallAlpha   = alpha * m_WallAlpha;
            m_PlayArea.planeAlpha  = alpha * m_PlaneAlpha;
        }
    }
Пример #14
0
        public override int GetInputState(ref XDevicePlugin.ControllerState state)
        {
            int ret = manager.impl.XInputGetState(dwUserIndex, ref xinputState);

            if (ret == 0)
            {
                state.handle = this.handle;
                ++state.timestamp;
                ResetStatePose(ref state);
                //
                if (manager.impl.XInputGetBatteryInformation != null)
                {
                    manager.impl.XInputGetBatteryInformation(dwUserIndex, 0, ref xinputBatteryInformation);
                    XDevicePlugin.SetInt(handle, XDevicePlugin.kField_BatteryLevel,
                                         (xinputBatteryInformation.BatteryType == XInputPlugin.XINPUT_BATTERY_TYPE.BATTERY_TYPE_DISCONNECTED ||
                                          xinputBatteryInformation.BatteryType == XInputPlugin.XINPUT_BATTERY_TYPE.BATTERY_TYPE_UNKNOWN)?
                                         -1:
                                         (int)(100f * (float)xinputBatteryInformation.BatteryLevel / (float)XInputPlugin.XINPUT_BATTERY_LEVEL.BATTERY_LEVEL_FULL)
                                         );
                }
                //
                if (inputTransform == null)
                {
                    state.buttons = (uint)xinputState.Gamepad.wButtons;
                }
                else
                {
                    state.buttons = inputTransform.TransformButtons((uint)xinputState.Gamepad.wButtons);
                }
                //
                state.axes[(int)ControllerRawAxis.LeftTrigger]  = Mathf.Lerp(0f, 1f, MathUtil.Normalize(0, 255, xinputState.Gamepad.bLeftTrigger));
                state.axes[(int)ControllerRawAxis.RightTrigger] = Mathf.Lerp(0f, 1f, MathUtil.Normalize(0, 255, xinputState.Gamepad.bRightTrigger));
                state.axes[(int)ControllerRawAxis.LeftThumbX]   = Mathf.Lerp(-1f, 1f, MathUtil.Normalize(-32767, 32767, xinputState.Gamepad.sThumbLX));
                state.axes[(int)ControllerRawAxis.LeftThumbY]   = Mathf.Lerp(-1f, 1f, MathUtil.Normalize(-32767, 32767, xinputState.Gamepad.sThumbLY));
                state.axes[(int)ControllerRawAxis.RightThumbX]  = Mathf.Lerp(-1f, 1f, MathUtil.Normalize(-32767, 32767, xinputState.Gamepad.sThumbRX));
                state.axes[(int)ControllerRawAxis.RightThumbY]  = Mathf.Lerp(-1f, 1f, MathUtil.Normalize(-32767, 32767, xinputState.Gamepad.sThumbRY));
            }
            return(ret);
        }
        /// <summary>
        /// Gets the touch-pad.
        /// Center point = 0.
        /// left top = -0.5,
        /// </summary>
        /// <returns><c>true</c>, if touch pad was gotten, <c>false</c> otherwise.</returns>
        /// <param name="touchPad">Touch pad.</param>
        public static bool GetTouchPad(out Vector2 touchPad, int controllerIndex = 0)
        {
            //NOT supported:
            if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer)
            {
                touchPad = Vector2.zero;
                return(false);
            }
            XDevicePlugin.ActParam_TouchpadState tpad_st = new XDevicePlugin.ActParam_TouchpadState();
            int tpad_act_rs = XDevicePlugin.DoAction(DevicerHandle.GetController(controllerIndex), XDevicePlugin.XActions.kXAct_Get_TouchPadState, ref tpad_st);

            if (tpad_act_rs >= 0 && tpad_st.pressed)
            {
                touchPad = new Vector2((tpad_st.x - 0.5f) / 0.5f, ((tpad_st.y - 0.5f) * -1) / 0.5f);
                return(true);
            }
            else
            {
                touchPad = Vector2.zero;
                return(false);
            }
        }
Пример #16
0
        public virtual void TransformState(ref XDevicePlugin.ControllerState state)
        {
            //
            state.buttons = GetButtons();
            //
            int i = 0;

            state.axes[i++] = Input.GetAxis(LeftTrigger.name);
            state.axes[i++] = Input.GetAxis(RightTrigger.name);
            state.axes[i++] = Input.GetAxis(LeftThumbstickX.name);
            state.axes[i++] = Input.GetAxis(LeftThumbstickY.name);
            state.axes[i++] = Input.GetAxis(RightThumbstickX.name);
            state.axes[i++] = Input.GetAxis(RightThumbstickY.name);
            //
            Vector3    pos = InputTracking.GetLocalPosition(node);
            Quaternion rot = InputTracking.GetLocalRotation(node);
            //
            TrackingResult trackingResult = TrackingResult.NotTracked;

            if (pos != Vector3.zero)
            {
                trackingResult |= TrackingResult.PositionTracked;
            }
            if (rot != Quaternion.identity)
            {
                trackingResult |= TrackingResult.RotationTracked;
            }
            XDevicePlugin.SetInt(state.handle, XDevicePlugin.kField_TrackingResult, (int)trackingResult);
            //
            i = 0;
            state.position[i] = pos[i]; ++i;
            state.position[i] = pos[i]; ++i;
            state.position[i] = -pos[i]; ++i;
            i = 0;
            state.rotation[i] = -rot[i]; ++i;
            state.rotation[i] = -rot[i]; ++i;
            state.rotation[i] = rot[i]; ++i;
            state.rotation[i] = rot[i]; ++i;
        }
Пример #17
0
        public void Update()
        {
            if (handle < 0)
            {
                return;
            }
            //
            XDevicePlugin.UpdateInputState(handle);
            //
            DeviceConnectionState s = (DeviceConnectionState)XDevicePlugin.
                                      GetInt(handle, XDevicePlugin.kField_ConnectionState, 0);

            if (connectionState != s)
            {
                connectionState = s;
                //
                for (int i = 0, imax = connectUI.Length; i < imax; ++i)
                {
                    if (connectUI[i] != null)
                    {
                        connectUI[i].SetActive(i == (int)s);
                    }
                }
            }
            //
            int b = XDevicePlugin.
                    GetInt(handle, XDevicePlugin.kField_BatteryLevel, 0);

            if (battImage != null)
            {
                //battImage.sprite=battSprites[(int)s];
            }
            if (battText != null)
            {
                battText.text = (b == -1)?"?":(b + "%");
            }
        }
Пример #18
0
        public Controller(ControllerIndex Index)
        {
            if (Index == ControllerIndex.Controller01)
            {
                ctrlHandle = DevicerHandle.Controller01;
                indexInt   = 0;
            }
            else
            {
                ctrlHandle = DevicerHandle.Controller02;
                indexInt   = 1;
            }

            m_state = (DeviceConnectionState)XDevicePlugin.GetInt(this.ctrlHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, (int)DeviceConnectionState.Disconnected);

            //Add LLAPI event listener:
            XDevicePlugin.RegisterObserver(ctrlHandle,
                                           XDevicePlugin.XControllerAttributes.kXCAttr_Int_ConnectionState,
                                           new XDevicePlugin.XDeviceConnectStateChangeDelegate(LLAPIConnectionStateChange),
                                           ctrlHandle);

            if (sAllButtons == null)
            {
                var controllerButtons = System.Enum.GetValues(typeof(ControllerButton));
                sAllButtons = new ControllerButton[controllerButtons.Length];
                for (int i = 0; i < controllerButtons.Length; i++)
                {
                    sAllButtons[i] = (ControllerButton)controllerButtons.GetValue(i);
                }
            }

            foreach (var button in sAllButtons)
            {
                buttonStates.Add(button, new ButtonState());
            }
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        public override bool DeinitAllControllers()
        {
            if (!m_IsInited)
            {
                return(false);
            }
            m_IsInited = false;
            //
            int ret;

            ret = SixensePluginLite.sixenseExit();
            if (ret != 0)
            {
                return(false);
            }
            ret = XDevicePlugin.Exit();
            if (ret != 0)
            {
                return(false);
            }
            //
            m_Result = 0;
            return(true);
        }
        /// <summary>
        /// Stops pairing.
        /// </summary>
        public static void StopPairing()
        {
            int ret = XDevicePlugin.DoAction(DevicerHandle.HmdHandle, XDevicePlugin.XActions.kXAct_StopPairingController);

            Debug.LogFormat("Stop pairing result : {0}", ret);
        }
 /// <summary>
 /// Disconnect the controller at the index.
 /// </summary>
 /// <param name="Index">Index.</param>
 public static void Disconnect(int Index)
 {
     XDevicePlugin.DoAction(DevicerHandle.HmdHandle, XDevicePlugin.XActions.kXAct_DisconnectControllerByIndex, Index);
 }
        public static void DisconnectAll()
        {
            int result = XDevicePlugin.DoAction(DevicerHandle.HmdHandle, XDevicePlugin.XActions.kXAct_DisconnectAllControllers);

            Debug.LogFormat("Disconnect result: {0}", result);
        }
        /// <summary>
        /// Connects all paired device.
        /// </summary>
        public static void ConnectAll()
        {
            int result = XDevicePlugin.DoAction(DevicerHandle.HmdHandle, XDevicePlugin.XActions.kXAct_ConnectAllPairedControllers);

            Debug.LogFormat("Connect-All result: {0}", result);
        }
        /// <summary>
        /// Gets paired device count.
        /// </summary>
        /// <param name="PairedNumber">Paired number.</param>
        public static int GetPairedDeviceCount()
        {
            int PairedNumber = XDevicePlugin.GetInt(DevicerHandle.HmdHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_PairedNumber, 0);

            return(PairedNumber);
        }
 /// <summary>
 /// Starts pairing.
 /// </summary>
 public static void StartPairing(XDevicePlugin.XControllerTypes controllerType)
 {
     XDevicePlugin.DoAction(DevicerHandle.HmdHandle, XDevicePlugin.XActions.kXAct_StartPairingController, (int)controllerType);
 }
 /// <summary>
 /// Gets the controller01 rotation.
 /// </summary>
 /// <returns>The controller01 rotation.</returns>
 public static Quaternion GetController01Rotation()
 {
     XDevicePlugin.ActParam_ControllerState state = new XDevicePlugin.ActParam_ControllerState();
     XDevicePlugin.DoAction(DevicerHandle.Controller01, XDevicePlugin.XActions.kXAct_GetControllerState, ref state);
     return(new Quaternion(state.rotation[0], state.rotation[1], state.rotation[2], state.rotation[3]));
 }
        /// <summary>
        /// Unpair the specified controllerIndex.
        /// </summary>
        /// <param name="controllerIndex">Controller index.</param>
        public static void Unpair(int controllerIndex)
        {
            var ret = XDevicePlugin.DoAction(DevicerHandle.HmdHandle, XDevicePlugin.XActions.kXAct_UnpairController, controllerIndex);

            Debug.LogFormat("Unpair controller: {0}, result: {1}", controllerIndex, ret);
        }
        /// <summary>
        /// Unpairs all.
        /// </summary>
        public static void UnpairAll()
        {
            int ret3 = XDevicePlugin.DoAction(DevicerHandle.HmdHandle, XDevicePlugin.XActions.kXAct_UnpairAllControllers);

            Debug.LogFormat("Unpair all controllers: {0}", ret3);
        }
Пример #29
0
 /// <summary>
 /// Initialize this device.
 /// </summary>
 public virtual void InitDevice(VRContext context)
 {
     m_Handle = XDevicePlugin.GetInputDeviceHandle("VRDevice");
 }
Пример #30
0
 public virtual void OnTrackerRecenter()
 {
     if (m_PlayArea != null)
     {
         Transform t   = m_PlayArea.transform;
         float     yaw = 180.0f + m_Transform.localRotation.eulerAngles.y;
         t.localRotation = Quaternion.Euler(0.0f, yaw, 0.0f);
         Vector3 newPos = m_Transform.localPosition - t.localRotation * new Vector3(0.0f, 0.0f, XDevicePlugin.GetFloat(m_TrackerHandle, XDevicePlugin.kField_TrackerDepth, 0f));
         newPos.y        = t.localPosition.y;
         t.localPosition = newPos;
     }
     UpdateModel();
 }