public void HandleInput(GameTime gameTime) { if (Re.State == RhythmEngine.RhythmEngineState.Playing) { LeftController.Update(gameTime); RightController.Update(gameTime); } KeyboardState Current = Host.KeyboardInput.Current; if (Host.Debugging) { // Rhythm engine if (Host.KeyboardInput.IsTap(Keys.OemOpenBrackets)) { Re.Stop(); } if (Host.KeyboardInput.IsTap(Keys.OemCloseBrackets)) { Re.Play(); } if (Host.KeyboardInput.IsTap(Keys.OemPipe)) { Re.Pause(); } if (Current.IsKeyDown(Keys.OemPlus)) { Re.Shift(playerShift); } if (Current.IsKeyDown(Keys.OemMinus)) { Re.Shift(-playerShift); } } }
public void SetFingerPos(Vector2 pos) { if (first) { first = false; lastPos = pos; initPos = pos; SetPos(pos); } else { //根据手指位置调整 var diff = pos - initPos; var dir = pos - lastPos; lastPos = pos; //手指在中心半径范围内 50半径 相反运动 var mag = diff.magnitude; var external = this.con.ExternalRadius * LeftController.GetRate(); //手指在圆环外面 跟随手指移动 if (mag > external) { //initPos += dir; var fingerDir = pos - initPos; var distOff = fingerDir.normalized * external; initPos = pos - distOff; SetPos(initPos); } } }
void Awake() { Instance = this; if (Screen.width > Screen.height) { size = Screen.height; } else { size = Screen.width; } joyStickTexture = gameObject.AddComponent <GUITexture>(); joyStickTexture.texture = joyStick; joyStickTexture.color = inactiveColor; var bo = new GameObject("LeftBack"); bo.transform.localScale = Vector3.zero; backObj = bo.gameObject.AddComponent <GUITexture>(); backObj.texture = background2D; backObj.color = inactiveColor; rb = gameObject.AddComponent <LeftBack>(); rb.con = this; rb.tex = backObj; rf = gameObject.AddComponent <LeftFinger>(); gameObject.transform.localPosition = Vector3.zero; gameObject.transform.localScale = Vector3.zero; rf.con = this; rf.tex = joyStickTexture; }
protected override void Update() { base.Update(); leftStick = FinchVR.LeftController.GetTouchAxes(); rightStick = FinchVR.RightController.GetTouchAxes(); bool rightUp = rightStick.x >= -epsSwipe && rightStick.x <= epsSwipe && rightStick.y >= (1 - epsSwipe); bool rightDown = rightStick.x >= -epsSwipe && rightStick.x <= epsSwipe && rightStick.y <= -(1 - epsSwipe); bool leftUp = leftStick.x >= -epsSwipe && leftStick.x <= epsSwipe && leftStick.y >= (1 - epsSwipe); bool leftDown = leftStick.x >= -epsSwipe && leftStick.x <= epsSwipe && leftStick.y <= -(1 - epsSwipe); currentTime += Time.deltaTime; if (rightUp || leftUp) { if ((timesCount <= 1 && currentTime >= firstIntervalChangingHeightSec) || (timesCount > 1 && currentTime >= intervalChangingHeightSec)) { StickUp.Invoke(); if (Vibration) { if (rightUp) { RightController.HapticPulse(VibrationTimeMs); } if (leftUp) { LeftController.HapticPulse(VibrationTimeMs); } } currentTime = 0; ++timesCount; } } else if (rightDown || leftDown) { if ((timesCount <= 1 && currentTime >= firstIntervalChangingHeightSec) || (timesCount > 1 && currentTime >= intervalChangingHeightSec)) { StickDown.Invoke(); if (Vibration && rightDown) { RightController.HapticPulse(VibrationTimeMs); } if (Vibration && leftDown) { LeftController.HapticPulse(VibrationTimeMs); } currentTime = 0; ++timesCount; } } if (!(rightUp || leftUp) && !(rightDown || leftDown)) { timesCount = 0; } }
private void Update() { if (_rightHandIndex == -1) { _rightHandIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost); } if (_leftHandIndex == -1) { _leftHandIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost); } if (Input.GetKeyDown(KeyCode.Space) || (_leftHandIndex != -1 && LeftController.GetHairTriggerDown())) { _spacebarDown = true; if (!_experimentCommenced) { _experimentCommenced = true; StartCoroutine(RunExperiment()); } } else { _spacebarDown = false; } if (_recordingData) { RecordPosesDataToBuffer(); } if (Input.GetKeyDown(KeyCode.G)) { UI.CalibrationLines.SetActive(!UI.CalibrationLines.activeInHierarchy); } if (Input.GetKeyDown(KeyCode.Backspace)) { StartCoroutine(EmergencyFlushBufferAndQuit()); } // If tracking the pole positions, update the virtual pole position and experimenter display every frame. if (!_poleTrackersAssigned) { return; } var rightPolePosition = _trackedDevices[_trackedDeviceRoles[DeviceRole.PoleRight]].transform.position; var leftPolePosition = _trackedDevices[_trackedDeviceRoles[DeviceRole.PoleLeft]].transform.position; _poleRight.transform.position = new Vector3(rightPolePosition.x, _poleHeightRight / 2f, rightPolePosition.z); _poleLeft.transform.position = new Vector3(leftPolePosition.x, _poleHeightRight / 2f, leftPolePosition.z); var apertureText = new StringBuilder(); apertureText.AppendFormat((Vector3.Distance(_poleLeft.transform.position, _poleRight.transform.position) - Parameters.VirtualPoleDiameter).ToString("F4")); apertureText.AppendFormat(" LeftX: {0:F4} RightX: {1:F4}", _poleLeft.transform.position.x, _poleRight.transform.position.x); UI.ApertureValue.text = apertureText.ToString(); }
private void Start() { instance = this; optionPanel = GameObject.Find("OptionsPane").GetComponent <OptionPanel>(); mapPanel = GameObject.Find("MapPane").GetComponent <MapPanel>(); infoPanel = GameObject.Find("InfoPane").GetComponent <InfoPanel>(); camera = GameObject.Find("OVRCameraRig"); }
private void Update() { if (UI.Core.instance.layoutSystem.activeScreen == UI.Screen.center) { InputDevice inputDevice = InputDeviceManager.instance.currentInputDevice; if (inputDevice.getDeviceType() == InputDeviceManager.InputDeviceType.Mouse) { // Let mouse handle zooming: if (!UI.Core.instance.pointerIsOverPlatformUIObject) { if (Input.GetAxis("Mouse ScrollWheel") != 0) { float inputScroll = Input.GetAxis("Mouse ScrollWheel"); float zoom = transform.localScale.x + inputScroll / (1 / zoomingSpeed); zoom = Mathf.Clamp(zoom, minZoom, maxZoom); transform.localScale = new Vector3(zoom, zoom, zoom); targetZoom = transform.localScale; } } } else if (inputDevice.getDeviceType() == InputDeviceManager.InputDeviceType.ViveController) { // Let left Vive controller handle zooming: LeftController lc = InputDeviceManager.instance.leftController; if (lc != null) { UnityEngine.EventSystems.PointerEventData.FramePressState triggerState = lc.triggerButtonState; if (triggerState == UnityEngine.EventSystems.PointerEventData.FramePressState.Pressed && zooming == false) { zooming = true; originalDist = (lc.transform.position - transform.position).magnitude; mOriginalZoom = transform.localScale; } else if (triggerState == UnityEngine.EventSystems.PointerEventData.FramePressState.Released && zooming == true) { zooming = false; } if (zooming) { float dist = (lc.transform.position - transform.position).magnitude; float distDiff = dist - originalDist; Vector3 newScale = mOriginalZoom + mOriginalZoom * distDiff; setTargetZoom(newScale); } } } } // Auto-Zoom to target, if given: transform.localScale = Vector3.SmoothDamp(transform.localScale, targetZoom, ref zoomVelocity, scaleTime); }
void Start() { player = GameObject.FindGameObjectWithTag("Player"); topController = player.transform.GetChild(1).GetComponent <TopController>(); rightController = player.transform.GetChild(0).GetComponent <RightController>(); leftController = player.transform.GetChild(3).GetComponent <LeftController>(); botController = player.transform.GetChild(2).GetComponent <BotController>(); editorHandler = GameObject.Find("EditorHandler").GetComponent <EditorHandler>(); }
private void Awake() { leftHand = this.FindComponent <ActionBasedControllerManager>("XR Origin/Camera Offset/LeftHand"); rightHand = this.FindComponent <ActionBasedControllerManager>("XR Origin/Camera Offset/RightHand"); _interactionManager = this.FindComponent <XRInteractionManager>("XR Interaction Manager"); locomotionSystem = this.FindGameObject("Locomotion System"); _mainCamera = this.FindComponent <Camera>("XR Origin/Camera Offset/Main Camera"); leftXRRayInteractor = LeftController.GetComponent <XRRayInteractor>(); rightXRRayInteractor = RightController.GetComponent <XRRayInteractor>(); }
private void Update() { if (UI.Core.instance.layoutSystem.activeScreen == UI.Screen.center) { InputDevice inputDevice = InputDeviceManager.instance.currentInputDevice; if (inputDevice.getDeviceType() == InputDeviceManager.InputDeviceType.Mouse) { // Let mouse handle rotation: if (Input.GetMouseButton(1) || Input.GetKey(KeyCode.M)) { float inputH = -Input.GetAxis("Mouse X"); float inputV = -Input.GetAxis("Mouse Y"); Vector3 upVector = Camera.main.transform.up; Vector3 rightVector = Camera.main.transform.right; transform.RotateAround(transform.position, upVector, inputH * rotationSpeedMouse); transform.RotateAround(transform.position, rightVector, -inputV * rotationSpeedMouse); targetRotation = transform.localRotation; // Make sure it doesn't auto-rotate back. } } else if (inputDevice.getDeviceType() == InputDeviceManager.InputDeviceType.ViveController) { // Let left Vive controller handle rotation: LeftController lc = InputDeviceManager.instance.leftController; if (lc != null) { UnityEngine.EventSystems.PointerEventData.FramePressState triggerState = lc.triggerButtonState; if (triggerState == UnityEngine.EventSystems.PointerEventData.FramePressState.Pressed) { rotating = true; previousVivePos = lc.transform.localPosition; } else if (triggerState == UnityEngine.EventSystems.PointerEventData.FramePressState.Released) { rotating = false; previousVivePos = new Vector3(0, 0, 0); } if (rotating) { Vector3 upVector = Camera.main.transform.up; Vector3 rightVector = Camera.main.transform.right; transform.RotateAround(transform.position, upVector, (previousVivePos.x - lc.transform.localPosition.x) * rotationSpeedVive); transform.RotateAround(transform.position, rightVector, -(previousVivePos.y - lc.transform.localPosition.y) * rotationSpeedVive); targetRotation = transform.localRotation; // Make sure it doesn't auto-rotate back. previousVivePos = lc.transform.localPosition; } } } } // Slowly rotate towards target, if any: //float step = Time.time; transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, (Time.time - rotationStartTime) / rotationTime); }
private void ChangeCanvasEventCamera(WVR_DeviceType _dt) { var _objects = GameObject.FindGameObjectsWithTag(CanvasTag); if (_objects == null) { #if UNITY_EDITOR Debug.Log("WaveVR_CombinedInputModule::ChangeCanvasEventCamera, objects with tag [" + CanvasTag + "] are not found."); #endif Log.e(LOG_TAG, "ChangeCanvasEventCamera, objects with tag [" + CanvasTag + "] are not found."); return; } Camera _event_camera = null; switch (_dt) { case WVR_DeviceType.WVR_DeviceType_Controller_Right: _event_camera = (Camera)RightController.GetComponent(typeof(Camera)); break; case WVR_DeviceType.WVR_DeviceType_Controller_Left: _event_camera = (Camera)LeftController.GetComponent(typeof(Camera)); break; default: _event_camera = (Camera)GazeCamera.GetComponent(typeof(Camera)); break; } if (_event_camera == null) { #if UNITY_EDITOR Debug.Log("WaveVR_CombinedInputModule::ChangeCanvasEventCamera, no event camera!"); #endif Log.e(LOG_TAG, "ChangeCanvasEventCamera, no event camera!"); return; } foreach (GameObject o in _objects) { Canvas _canvas = (Canvas)o.GetComponent(typeof(Canvas)); if (_canvas != null) { if (_dt != WVR_DeviceType.WVR_DeviceType_HMD) { Log.d(LOG_TAG, "Change " + _canvas.name + " canvas event camera to " + _dt); } _canvas.worldCamera = _event_camera; } } }
void Start() { if (gameObject.transform.parent.CompareTag("SokobanBlock")) { unpassableBlocksTags = unpassableSokobanBlocksTags; } block = transform.parent.gameObject; iceBlockController = block.GetComponent <IceBlockController>(); antiBlock = transform.parent.GetChild(2).GetComponent <BlockLeftController>(); player = GameObject.FindGameObjectWithTag("Player"); playerController = player.GetComponent <PlayerController>(); playerMovement = player.transform.GetChild(3).GetComponent <LeftController>(); collider = gameObject.GetComponent <BoxCollider2D>(); }
void Update() { if (RightController.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { if (!rightMenuActive) { rightMenuActive = true; } else { rightMenuActive = false; } if ((rightMenuActive && !userMenuActive && !locomotionMenuActive && !XRoomConsole) || (leftMenuActive && !userMenuActive && !locomotionMenuActive && !XRoomConsole)) { userMenu.SetActive(true); userMenuActive = true; } else if (!rightMenuActive && !leftMenuActive) { userMenu.SetActive(false); locomotionMenu.SetActive(false); levelMenu.SetActive(false); userMenuActive = false; } } if (LeftController.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { if (!leftMenuActive) { leftMenuActive = true; } else { leftMenuActive = false; } if ((rightMenuActive && !userMenuActive && !locomotionMenuActive && !XRoomConsole) || (leftMenuActive && !userMenuActive && !locomotionMenuActive && !XRoomConsole)) { userMenu.SetActive(true); userMenuActive = true; } else if (!rightMenuActive && !leftMenuActive) { userMenu.SetActive(false); locomotionMenu.SetActive(false); levelMenu.SetActive(false); userMenuActive = false; } } }
private void SetupReticleBeam_Left() { if (reticlePointer_left == null) { reticlePointer_left = LeftController.GetComponentInChildren <WaveVR_ControllerPointer> (); // Remove left reticle by default. if (reticlePointer_left != null) { reticlePointer_left.removePointer(); } } if (beam_left == null) { beam_left = LeftController.GetComponentInChildren <WaveVR_Beam> (); } }
void Start() { StartCoroutine(ReloadMovesCoroutine()); if (EditorHandler.isBackToCheckpoint) { IsBackToCheckpoint(); } editorHandler = GameObject.FindGameObjectWithTag("EditorHandler").GetComponent <EditorHandler>(); keyHolder = GameObject.FindGameObjectWithTag("keyList").transform; keyHolderAnimator = GameObject.FindGameObjectWithTag("keyInventory").GetComponent <Animator>(); sr = gameObject.GetComponent <SpriteRenderer>(); botController = gameObject.GetComponentInChildren <BotController>(); leftController = gameObject.GetComponentInChildren <LeftController>(); rightController = gameObject.GetComponentInChildren <RightController>(); topController = gameObject.GetComponentInChildren <TopController>(); }
void ReleaseDesignerOutlets() { if (SplitView != null) { SplitView.Dispose(); SplitView = null; } if (LeftController != null) { LeftController.Dispose(); LeftController = null; } if (RightController != null) { RightController.Dispose(); RightController = null; } }
// Update is called once per frame void Update() { // シーンコントローラが所得できてるかをチェック if (sceneController) { // ここでシーンの切り替える条件などを書いてください if (Input.GetKeyDown(KeyCode.Return)) { // sceneController.SceneChange( シーンの列挙子 )を呼び出すとシーンを変えることができます sceneController.SceneChange(SceneController.SceneState.GameMain); } if (LeftController) { // 左コントローラの操作 if (LeftController.GetGripDown()) { sceneController.SceneChange(SceneController.SceneState.GameMain); } if (LeftController.GetHairTriggerDown()) { sceneController.SceneChange(SceneController.SceneState.GameMain); } } if (RightController) { // 右コントローラの操作 if (RightController.GetGripDown()) { sceneController.SceneChange(SceneController.SceneState.GameMain); } if (RightController.GetHairTriggerDown()) { sceneController.SceneChange(SceneController.SceneState.GameMain); } } } else { // ここではシーンコントローラが所得できなかった場合の処理を書きます sceneController = GameObject.Find("[SceneManager]").GetComponent <SceneController>(); } }
private void PhysicRaycast_Left() { Camera _cam = (Camera)LeftController.GetComponent(typeof(Camera)); PhysicsRaycaster _raycaster = LeftController.GetComponent <PhysicsRaycaster> (); if (_cam == null || _raycaster == null) { Log.e(LOG_TAG, "PhysicRaycast_Left() no Camera or Physics Raycaster!"); return; } if (leftHandPointer == null) { leftHandPointer = new PointerEventData(eventSystem); } leftHandPointer.Reset(); leftHandPointer.position = new Vector2(0.5f * Screen.width, 0.5f * Screen.height); // center of screen List <RaycastResult> _results = new List <RaycastResult>(); if (_raycaster != null) { _raycaster.Raycast(leftHandPointer, _results); } RaycastResult _firstResult = FindFirstRaycast(_results); if (_firstResult.module != null) { #if UNITY_EDITOR //Debug.Log ("PhysicRaycast_Left(), camera: " + _firstResult.module.eventCamera + ", first result = " + _firstResult); #endif //Log.d (LOG_TAG, "PhysicRaycast_Left(), camera: " + _firstResult.module.eventCamera + ", first result = " + _firstResult); } leftHandPointer.pointerCurrentRaycast = _firstResult; if (_firstResult.gameObject != null) { leftHandPointer.position = _firstResult.screenPosition; } }
protected override void Update() { base.Update(); if (ButtonEventType == FinchButtonEventType.Right || ButtonEventType == FinchButtonEventType.Any) { detectPress(FinchChirality.Right); } if (ButtonEventType == FinchButtonEventType.Left || ButtonEventType == FinchButtonEventType.Any) { detectPress(FinchChirality.Left); } bool wasInvoked = false; if (ButtonEventType == FinchButtonEventType.BothAtOneTime) { if ((RightController.GetPress(button) && LeftController.GetPressDown(button)) || (LeftController.GetPress(button) && RightController.GetPressDown(button))) { if (FinchDownEvent != null) { FinchDownEvent.Invoke(); wasInvoked = true; } else if (FinchUpEvent != null) { FinchUpEvent.Invoke(); wasInvoked = true; } if (wasInvoked && Vibration) { RightController.HapticPulse(VibrationTimeMs); LeftController.HapticPulse(VibrationTimeMs); } } } }
protected override void Update() { ButtonEventType = FinchButtonEventType.Any; base.Update(); bool startedTouching = !bothTouching && ((LeftController.GetPress(Button) && RightController.GetPressDown(Button)) || (RightController.GetPress(Button) && LeftController.GetPressDown(Button))); bool eventCanBeInvoked = !alreadyInvoked && bothTouching; bool stoppedTouching = bothTouching && (LeftController.GetPressUp(Button) || RightController.GetPressUp(Button)); if (startedTouching) { bothTouching = true; stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); } else if (eventCanBeInvoked) { if (stopWatch.ElapsedMilliseconds >= longTapTimeMs) { stopWatch.Stop(); alreadyInvoked = true; LongTapBothTouchpads.Invoke(); if (Vibration) { RightController.HapticPulse(VibrationTimeMs); LeftController.HapticPulse(VibrationTimeMs); } } } else if (stoppedTouching) { bothTouching = false; alreadyInvoked = false; stopWatch.Stop(); } }
private void Update() { //Drawing laser and picking up object RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, 100)) { _hitPoint = hit.point; ShowLaser(hit); if ((LeftController.GetHairTriggerDown() || RightController.GetHairTriggerDown()) && !heldGameObject && hit.collider.gameObject.GetComponent <Rigidbody>()) { if (applicationController.currentCube == hit.collider.gameObject) { applicationController.LogCorrectObject(-1.0f); } else { applicationController.LogWrongObject(-1.0f); } GrabObject(hit.collider.gameObject); } else if ((LeftController.GetHairTriggerDown() || RightController.GetHairTriggerDown()) && !heldGameObject) { applicationController.LogMissedObject(-1.0f); } } //Releasing an object if ((LeftController.GetHairTriggerUp() || RightController.GetHairTriggerUp()) && heldGameObject) { applicationController.LogDroppedObject(); ReleaseObject(); } else if (heldGameObject && !GetComponent <FixedJoint>()) { FixedJoint joint = AddFixedJoint(); joint.connectedBody = heldGameObject.GetComponent <Rigidbody>(); } }
protected virtual void CreateControllers() { // コントローラマネージャの生成 VRLog.Info("SteamVR Controller Manager Create"); _ControllerManager = gameObject.AddComponent <SteamVR_ControllerManager>(); _ControllerManager.enabled = false; // コントローラの生成. VRLog.Info("Left Controller Create"); Left = LeftController.Create(); VRLog.Info("Right Controller Create"); Right = RightController.Create(); _ControllerManager.left = Left.gameObject; _ControllerManager.right = Right.gameObject; _ControllerManager.UpdateTargets(); _ControllerManager.enabled = true; Left.transform.SetParent(VR.Camera.Origin, true); Right.transform.SetParent(VR.Camera.Origin, true); return; }
protected virtual Controller CreateLeftController() { return(LeftController.Create()); }
private void Update() { if (UI.Core.instance.layoutSystem.activeScreen == UI.Screen.center) { InputDevice inputDevice = InputDeviceManager.instance.currentInputDevice; if (inputDevice.getDeviceType() == InputDeviceManager.InputDeviceType.Mouse) { // Let mouse handle rotation: if (Input.GetMouseButton(0) || Input.GetKey(KeyCode.M)) { float inputH = -Input.GetAxis("Mouse X"); float inputV = -Input.GetAxis("Mouse Y"); if (mouseRotationMode == RotationMode.MODE_FIXED_UP_AXIS) { // Fixed-Up-Axis Mode maps up-down movement to the model's tilt value. Also has a maximum tilt rotation of // +- 85 degrees leftRightAng = leftRightAng + inputH * rotationSpeedMouse; Quaternion leftRightQuat = Quaternion.AngleAxis(leftRightAng, new Vector3(0, 1, 0)); transform.rotation = leftRightQuat * Quaternion.AngleAxis(90f, new Vector3(1, 0, 0)); // Decide in which direction to rotate by checking if the Y-Vector is facing towards the camera: float dist1 = Vector3.Distance(transform.TransformPoint(new Vector3(0, 1, 0)), Camera.main.transform.position); float dist2 = Vector3.Distance(transform.TransformPoint(new Vector3(0, -1, 0)), Camera.main.transform.position); if (dist1 > dist2) { inputV = -inputV; } upDownAng = Mathf.Clamp(upDownAng + inputV * rotationSpeedMouse, -85, 85); Quaternion upDownQuat = Quaternion.AngleAxis(upDownAng, new Vector3(1, 0, 0)); transform.localRotation *= upDownQuat; } else { // Standard Mode maps Controller left-right movement to rotation around the global "up" vector // and up-down movement to a global axis from left to right, so it ignores the model's current orientation. Vector3 upVector = Camera.main.transform.up; Vector3 rightVector = Camera.main.transform.right; transform.RotateAround(transform.position, upVector, inputH * rotationSpeedMouse); transform.RotateAround(transform.position, rightVector, -inputV * rotationSpeedMouse); } targetRotation = transform.localRotation; // Make sure it doesn't auto-rotate back. } } else if (inputDevice.getDeviceType() == InputDeviceManager.InputDeviceType.ViveController) { // Let left Vive controller handle rotation: LeftController lc = InputDeviceManager.instance.leftController; if (lc != null) { UnityEngine.EventSystems.PointerEventData.FramePressState triggerState = lc.triggerButtonState; if (triggerState == UnityEngine.EventSystems.PointerEventData.FramePressState.Pressed) { rotating = true; previousVivePos = lc.transform.localPosition; } else if (triggerState == UnityEngine.EventSystems.PointerEventData.FramePressState.Released) { rotating = false; previousVivePos = new Vector3(0, 0, 0); } if (rotating) { float inputH = (previousVivePos.x - lc.transform.localPosition.x); float inputV = -(previousVivePos.y - lc.transform.localPosition.y); if (viveRotationMode == RotationMode.MODE_STANDARD) { // Standard Mode maps Controller left-right movement to rotation around the global "up" vector // and up-down movement to a global axis from left to right, so it ignores the model's current orientation. Vector3 upVector = Camera.main.transform.up; Vector3 rightVector = Camera.main.transform.right; transform.RotateAround(transform.position, upVector, inputH * rotationSpeedVive); transform.RotateAround(transform.position, rightVector, inputV * rotationSpeedVive); } else if (viveRotationMode == RotationMode.MODE_FIXED_UP_AXIS) { // Fixed-Up-Axis Mode maps up-down movement to the model's tilt value. Also has a maximum tilt rotation of // +- 85 degrees leftRightAng = leftRightAng + inputH * rotationSpeedVive; Quaternion leftRightQuat = Quaternion.AngleAxis(leftRightAng, new Vector3(0, 1, 0)); transform.rotation = leftRightQuat * Quaternion.AngleAxis(90f, new Vector3(1, 0, 0)); // Decide in which direction to rotate by checking if the Y-Vector is facing towards the camera: float dist1 = Vector3.Distance(transform.TransformPoint(new Vector3(0, 1, 0)), Camera.main.transform.position); float dist2 = Vector3.Distance(transform.TransformPoint(new Vector3(0, -1, 0)), Camera.main.transform.position); if (dist1 <= dist2) { inputV = -inputV; } upDownAng = Mathf.Clamp(upDownAng + inputV * rotationSpeedVive, -85, 85); Quaternion upDownQuat = Quaternion.AngleAxis(upDownAng, new Vector3(1, 0, 0)); transform.localRotation *= upDownQuat; } else if (viveRotationMode == RotationMode.MODE_MAP_ROTATION) { // previousControllerRotation * delta = lc.transform.rotation; Quaternion delta = lc.transform.rotation * Quaternion.Inverse(previousControllerRotation); float angle; Vector3 axis; delta.ToAngleAxis(out angle, out axis); angle *= manualRotationSpeed; Quaternion scaledDelta = Quaternion.AngleAxis(angle, axis); transform.rotation = scaledDelta * transform.rotation; } else if (viveRotationMode == RotationMode.MODE_STANDARD_PLUS_ROLL) { // Standard Mode maps Controller left-right movement to rotation around the global "up" vector // and up-down movement to a global axis from left to right, so it ignores the model's current orientation. Vector3 upVector = Camera.main.transform.up; Vector3 rightVector = Camera.main.transform.right; transform.RotateAround(transform.position, upVector, inputH * rotationSpeedVive); transform.RotateAround(transform.position, rightVector, inputV * rotationSpeedVive); // Additional Rotation (rolling): Quaternion delta = lc.transform.rotation * Quaternion.Inverse(previousControllerRotation); float inputRoll = delta.eulerAngles.z; while (inputRoll > 180) { inputRoll -= 360; } while (inputRoll < -180) { inputRoll += 360; } Vector3 forwardVector = Camera.main.transform.forward; transform.RotateAround(transform.position, forwardVector, inputRoll * rollSpeed); } targetRotation = transform.localRotation; // Make sure it doesn't auto-rotate back. previousVivePos = lc.transform.localPosition; } previousControllerRotation = lc.transform.rotation; } } } // Slowly rotate towards target, if any: //float step = Time.time; transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, (Time.time - rotationStartTime) / rotationTime); }
/// <summary> /// Shut down both controllers in this pair. Must be called when the controllers are no longer needed. /// </summary> public void Shutdown() { LeftController.Shutdown(); RightController.Shutdown(); }
public void registerLeftController(LeftController left) { leftController = left; left.setTouchpadDirectionIcons(iconLeftControllerLeft, iconLeftControllerRight, iconLeftControllerUp, iconLeftControllerDown); left.setTouchpadCentralIcon(iconLeftControllerCenter); }
private void calculate(FinchChirality chirality) { Vector2 axis; float currentTime; if (chirality == FinchChirality.Right) { axis = FinchVR.RightController.GetTouchAxes(); currentTimeRight += Time.deltaTime; currentTime = currentTimeRight; } else if (chirality == FinchChirality.Left) { axis = FinchVR.LeftController.GetTouchAxes(); currentTimeLeft += Time.deltaTime; currentTime = currentTimeLeft; } else { return; } //zero bool zero = axis.x <= epsZero && axis.x >= -epsZero && axis.y <= epsZero && axis.y >= -epsZero; //stick swipe to right-left bool swipeToRight = axis.x >= (1 - epsSwipe) && axis.y >= -epsSwipe && axis.y <= epsSwipe; bool swipeToLeft = axis.x <= -(1 - epsSwipe) && axis.y >= -epsSwipe && axis.y <= epsSwipe; //stick swipe to up-down bool swipeToUp = axis.x >= -epsSwipe && axis.x <= epsSwipe && axis.y >= (1 - epsSwipe); bool swipeToDown = axis.x >= -epsSwipe && axis.x <= epsSwipe && axis.y <= -(1 - epsSwipe); bool previousWasZero = chirality == FinchChirality.Right ? previousWasZeroRight : previousWasZeroLeft; if (zero) { if (chirality == FinchChirality.Right) { currentTimeRight = 0; previousWasZeroRight = true; } else { currentTimeLeft = 0; previousWasZeroLeft = true; } return; } if (currentTime >= timeToSwapSec) { currentTime = 0; if (chirality == FinchChirality.Right) { currentTimeRight = 0; previousWasZeroRight = previousWasZero = false; } else { currentTimeLeft = 0; previousWasZeroLeft = previousWasZero = false; } } if (previousWasZero) { bool invoked = false; if (swipeToRight) { SwipeRight.Invoke(); invoked = true; } if (swipeToLeft) { SwipeLeft.Invoke(); invoked = true; } if (swipeToUp) { SwipeUp.Invoke(); invoked = true; } if (swipeToDown) { SwipeDown.Invoke(); invoked = true; } if (invoked) { if (chirality == FinchChirality.Right) { previousWasZeroRight = false; currentTimeRight = 0; if (Vibration) { RightController.HapticPulse(VibrationTimeMs); } } else { previousWasZeroLeft = false; currentTimeLeft = 0; if (Vibration) { LeftController.HapticPulse(VibrationTimeMs); } } } } }
//EMPTY #region PUBLIC_METHODS #endregion PUBLIC_METHODS #region PRIVATE_METHODS /// <summary> /// Handle the Left Controller input and put them in the Events /// </summary> void CheckLeftControllerInput() { BoolVariable temp; #region TRIGGER temp = LeftVariablesDictionnary.Get("TriggerIsDown"); if (!temp.Value && LeftController.GetHairTriggerDown()) { temp.SetValue(true); _leftEvent = (GameEvent)LeftEventsDictionnary.Get("LeftTriggerDown"); _leftEvent.Raise(); } else if (temp.Value && LeftController.GetHairTriggerUp()) { temp.SetValue(false); _leftEvent = (GameEvent)LeftEventsDictionnary.Get("LeftTriggerUp"); _leftEvent.Raise(); } #endregion TRIGGER #region TOUCHPAD temp = LeftVariablesDictionnary.Get("ThumbIsDown"); LeftThumbOrientation.SetValue(LeftController.GetAxis()); if (LeftController.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { temp.SetValue(true); _leftEvent = (GameEvent)LeftEventsDictionnary.Get("LeftThumbDown"); _leftEvent.Raise(); } else if (temp.Value && LeftController.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { temp.SetValue(false); _leftEvent = (GameEvent)LeftEventsDictionnary.Get("LeftThumbUp"); _leftEvent.Raise(); } if (LeftController.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad)) { _leftEventBool = (GameEventBool)LeftEventsDictionnary.Get("LeftThumbTouching"); _leftEventBool.Raise(true); } else if (LeftController.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { _leftEventBool = (GameEventBool)LeftEventsDictionnary.Get("LeftThumbTouching"); _leftEventBool.Raise(false); } #endregion TOUCHPAD #region GRIP temp = LeftVariablesDictionnary.Get("GripIsDown"); if (!temp.Value && LeftController.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { temp.SetValue(true); _leftEvent = (GameEvent)LeftEventsDictionnary.Get("LeftGripDown"); _leftEvent.Raise(); } else if (temp.Value && LeftController.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) { temp.SetValue(false); _leftEvent = (GameEvent)LeftEventsDictionnary.Get("LeftGripUp"); _leftEvent.Raise(); } #endregion GRIP #region MENU temp = LeftVariablesDictionnary.Get("MenuIsDown"); if (!temp.Value && LeftController.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { temp.SetValue(true); _leftEvent = (GameEvent)LeftEventsDictionnary.Get("LeftMenuDown"); _leftEvent.Raise(); } else if (temp.Value && LeftController.GetPressUp(SteamVR_Controller.ButtonMask.ApplicationMenu)) { temp.SetValue(false); _leftEvent = (GameEvent)LeftEventsDictionnary.Get("LeftMenuUp"); _leftEvent.Raise(); } #endregion MENU }