/// <summary> /// Updates the controller. /// </summary> /// <param name="role">The role.</param> /// <param name="state">The state.</param> /// <param name="pose">The pose.</param> internal void Update(VRControllerRole role, ref VRControllerState_t state, ref VRPose pose) { IsConnected = true; Pose = pose; Role = role; // Trackpad Trackpad.X = state.rAxis0.x; Trackpad.Y = state.rAxis0.y; TrackpadTouch = state.GetButtonTouched(EVRButtonId.k_EButton_Axis0); TrackpadButton = state.GetButtonPressed(EVRButtonId.k_EButton_Axis0).ToButtonState(); // Trigger Trigger = state.rAxis1.x; TriggerButton = state.GetButtonPressed(EVRButtonId.k_EButton_Axis1).ToButtonState(); // Buttons ApplicationMenu = state.GetButtonPressed(EVRButtonId.k_EButton_ApplicationMenu).ToButtonState(); A = state.GetButtonPressed(EVRButtonId.k_EButton_A).ToButtonState(); Grip = state.GetButtonPressed(EVRButtonId.k_EButton_Grip).ToButtonState(); // DPad DPad.Up = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Up).ToButtonState(); DPad.Down = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Down).ToButtonState(); DPad.Left = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Left).ToButtonState(); DPad.Right = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Right).ToButtonState(); }
internal void Update(int id, VRControllerRole role, ref VRControllerState_t state, ref VRPose pose) { this.Update(id, pose); this.Role = role; // Axies this.Trackpad.X = state.rAxis0.x; this.Trackpad.Y = state.rAxis0.y; this.Trigger = state.rAxis1.x; // Buttons this.TrackpadButton = state.GetButtonPressed(EVRButtonId.k_EButton_SteamVR_Touchpad).ToButtonState(); this.TriggerButton = state.GetButtonPressed(EVRButtonId.k_EButton_SteamVR_Trigger).ToButtonState(); this.ApplicationMenu = state.GetButtonPressed(EVRButtonId.k_EButton_ApplicationMenu).ToButtonState(); this.A = state.GetButtonPressed(EVRButtonId.k_EButton_A).ToButtonState(); this.Grip = state.GetButtonPressed(EVRButtonId.k_EButton_Grip).ToButtonState(); this.TrackpadTouch = state.GetButtonTouched(EVRButtonId.k_EButton_SteamVR_Touchpad); // DPad this.DPad.Up = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Up).ToButtonState(); this.DPad.Right = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Right).ToButtonState(); this.DPad.Left = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Left).ToButtonState(); this.DPad.Down = state.GetButtonPressed(EVRButtonId.k_EButton_DPad_Down).ToButtonState(); }
//NOTE: Late update used bc. OpenVR is updated during Update() and this way we ensure, that we have latest data and we're not frame behind private void LateUpdate() { if (VRSystem.Instance == null || !VRSystem.Instance.IsConnected) { return; } VREye[] eyes = VRSystem.Instance.EyesProperties; VRPose pose = VRSystem.Instance.TrackerCameraPose; UpdateCamera(LeftEyeCamera, 0); UpdateCamera(RightEyeCamera, 1); var transform = TrackerAnchor.LocalTransform; transform.Translation = pose.Position; transform.Orientation = pose.Orientation; TrackerAnchor.LocalTransform = transform; foreach (VRController controller in vrControllers) { VRControllerRole role = controller.Role; int cIndex; if (role == VRControllerRole.LeftHand) { cIndex = VRSystem.Instance.LeftControllerIndex; } else if (role == VRControllerRole.RightHand) { cIndex = VRSystem.Instance.RightControllerIndex; } else { cIndex = controller.ControllerIndex; } VRControllerState[] states = VRSystem.Instance.Controllers; VRControllerState newState; if (cIndex >= 0 && states != null && cIndex < states.Length) { newState = states[cIndex]; } else { newState = new VRControllerState(); } controller.UpdateState(newState); } VRPose centerPose = eyes[2].Pose; transform = CenterEyeAnchor.LocalTransform; transform.Translation = centerPose.Position; transform.Orientation = centerPose.Orientation; CenterEyeAnchor.LocalTransform = transform; }
private EmptyActor ConfigureControllerAnchor(EmptyActor root, VRControllerRole role) { string name = role == VRControllerRole.LeftHand ? leftControllerAnchorName : role == VRControllerRole.RightHand ? rightControllerAnchorName : string.Empty; EmptyActor anchor = Actor.GetChild(name) as EmptyActor; if (anchor == null) { anchor = EmptyActor.New(); var script = New <VRController>(); script.Role = role; anchor.AddScript(script); root.AddChild(anchor); anchor.Name = name; } return(anchor); }
/// <summary> /// Creates the OVR controller position /// </summary> /// <param name="root">The root entity</param> /// <param name="role">The controller role</param> /// <returns>The controller anchor</returns> private Entity ConfigureControllerAnchor(Entity root, VRControllerRole role) { string name; switch (role) { case VRControllerRole.LeftHand: name = leftControllerAnchorName; break; case VRControllerRole.RightHand: name = rightControllerAnchorName; break; default: name = string.Empty; break; } Entity anchor = root.FindChild(name); if (anchor == null) { anchor = new Entity(name) .AddComponent(new Transform3D()) .AddComponent(new VRController() { Role = role }); root.AddChild(anchor); } else if (anchor.FindComponent <VRController>() == null) { anchor.AddComponent(new VRController() { Role = role }); } return(anchor); }