/// <summary> /// Save the initial saber positions relative to the VRControllers /// </summary> private void CalibrateSaberPositions() { calibrated = true; // Save current controller position this.savedLeftController = TrackedDeviceManager.GetDevicePose(this.leftController) ?? new Pose(); this.savedLeftController = this.AdjustForPlayerOrigin(this.savedLeftController); this.savedRightController = TrackedDeviceManager.GetDevicePose(this.rightController) ?? new Pose(); this.savedRightController = this.AdjustForPlayerOrigin(this.savedRightController); // Save current game saber positions this.savedLeftSaber.position = saberManager.leftSaber.transform.position; this.savedLeftSaber.rotation = saberManager.leftSaber.transform.rotation; this.savedRightSaber.position = saberManager.rightSaber.transform.position; this.savedRightSaber.rotation = saberManager.rightSaber.transform.rotation; }
/// <summary> /// Gets the position of the device but factors in the room rotation of Beat Saber into the return. /// It requires the <see cref="MainSettingsModelSO" /> which can be found by calling /// Resources.FindObjectsOfTypeAll<MainSettingsModelSO>().FirstOrDefault(); /// </summary> private Pose?GetBeatSaberDevicePosition(InputDevice device) { Pose?devicePose = TrackedDeviceManager.GetDevicePose(device); if (devicePose == null) { return(null); } var roomCenter = this.mainSettingsModel.roomCenter; var roomRotation = Quaternion.Euler(0, this.mainSettingsModel.roomRotation, 0); Pose newDevicePose = devicePose.Value; newDevicePose.position = roomRotation * devicePose.Value.position; newDevicePose.position += roomCenter; newDevicePose.rotation = roomRotation * devicePose.Value.rotation; return(newDevicePose); }
private void Update() { if (!this.showTrackers || this.trackerInstances == null || this.trackerInstances.Count == 0) { return; } foreach (var tracker in this.trackerInstances) { // Update all the tracker poses Pose trackerPose = TrackedDeviceManager.GetDevicePose(tracker.InputDevice) ?? new Pose(); trackerPose = this.AdjustForRoomRotation(trackerPose); tracker.Instance.transform.position = trackerPose.position; tracker.Instance.transform.rotation = trackerPose.rotation; } var selectedTrackerInstance = this.trackerInstances.Find(t => t.Serial == this.selectedTracker.Serial); if (this.selectedTracker == null || String.IsNullOrWhiteSpace(this.selectedTracker.Serial)) { // No selected tracker so disable the saber this.saberInstance.SetActive(false); return; } // Transform the Saber according to the Tracker Config Data Pose selectedTrackerPose = new Pose( selectedTrackerInstance.Instance.transform.position, selectedTrackerInstance.Instance.transform.rotation); Pose pose = Utilities.CalculatePoseFromTrackerData(this.selectedTracker, selectedTrackerPose); this.saberInstance.transform.position = pose.position; this.saberInstance.transform.rotation = pose.rotation; this.saberInstance.SetActive(true); }
/// <summary> /// Gets the pose for the given tracker config data or else it falls back to the /// right saber pose. This method accounts for Room Adjust and Noodle Extensions /// changing viewpoint functionality. /// </summary> public Pose GetRightSaberPose(TrackerConfigData configData) { Pose?trackerPose; if (!String.IsNullOrWhiteSpace(configData?.Serial) && (trackerPose = TrackedDeviceManager.instance.GetPoseFromSerial(configData.Serial)) != null) { // Return adjusted position from the tracker Pose adjustedPose = this.AdjustForPlayerOrigin(trackerPose.Value); return(Utilities.CalculatePoseFromTrackerData(configData, adjustedPose)); } else { if (!calibrated || !this.rightController.isValid) { return(new Pose()); } // Return adjusted position from the saber Pose controllerPose = TrackedDeviceManager.GetDevicePose(this.rightController) ?? new Pose(); Pose adjustedControllerPose = this.AdjustForPlayerOrigin(controllerPose); return(TrackedDeviceManager.GetTrackedObjectPose(this.savedRightSaber, this.savedRightController, adjustedControllerPose)); } }
//private void DrawBounds(Bounds b) //{ // var vectorArray = new Vector3[] // { // new Vector3(b.min.x, b.min.y, b.min.z), // new Vector3(b.max.x, b.min.y, b.min.z), // new Vector3(b.max.x, b.min.y, b.max.z), // new Vector3(b.min.x, b.min.y, b.max.z), // new Vector3(b.min.x, b.max.y, b.min.z), // new Vector3(b.max.x, b.max.y, b.min.z), // new Vector3(b.max.x, b.max.y, b.max.z), // new Vector3(b.min.x, b.max.y, b.max.z) // }; // this.lines.positionCount = 8; // this.lines.SetPositions(vectorArray); //} private void Update() { // If there is nothing to grab anywhere, do nothing if (!this.grabbableInstances.Any()) { return; } // Check for trigger clicks first as it's debounced and will override simply having the trigger down if (InputManager.instance.GetRightTriggerClicked()) { this.rightGrabbed = this.GrabInstance(InputManager.instance.RightController); return; } if (InputManager.instance.GetLeftTriggerClicked()) { this.leftGrabbed = this.GrabInstance(InputManager.instance.LeftController); return; } // If there is no grabbed instance or grabbed device then we are done if (this.leftGrabbed == null && this.rightGrabbed == null) { return; } // Check for trigger being held down on the device if (this.rightGrabbed != null) { if (InputManager.instance.GetRightTriggerDown()) { // Trigger held so track instance position with the device Pose?grabbedPose = TrackedDeviceManager.GetDevicePose(rightGrabbed.grabbedDevice); if (grabbedPose == null) { return; } this.rightGrabbed.grabbedInstance.Pose = TrackedDeviceManager.GetTrackedObjectPose(rightGrabbed.grabbedStartPose, rightGrabbed.grabbedDevicePose, grabbedPose.Value); this.rightGrabbed.grabbedInstance.Instance.transform.position = this.rightGrabbed.grabbedInstance.Pose.position; this.rightGrabbed.grabbedInstance.Instance.transform.rotation = this.rightGrabbed.grabbedInstance.Pose.rotation; this.rightGrabbed.grabbedInstance.ExpandedBounds = CalculateExpandedBounds(this.rightGrabbed.grabbedInstance.Instance); //DrawBounds(this.rightGrabbed.grabbedInstance.ExpandedBounds); } else { ReleaseInstance(ref this.rightGrabbed); } } if (this.leftGrabbed != null) { if (InputManager.instance.GetLeftTriggerDown()) { // Trigger held so track instance position with the device Pose?grabbedPose = TrackedDeviceManager.GetDevicePose(leftGrabbed.grabbedDevice); if (grabbedPose == null) { return; } this.leftGrabbed.grabbedInstance.Pose = TrackedDeviceManager.GetTrackedObjectPose(leftGrabbed.grabbedStartPose, leftGrabbed.grabbedDevicePose, grabbedPose.Value); this.leftGrabbed.grabbedInstance.Instance.transform.position = this.leftGrabbed.grabbedInstance.Pose.position; this.leftGrabbed.grabbedInstance.Instance.transform.rotation = this.leftGrabbed.grabbedInstance.Pose.rotation; this.leftGrabbed.grabbedInstance.ExpandedBounds = CalculateExpandedBounds(this.leftGrabbed.grabbedInstance.Instance); //DrawBounds(this.leftGrabbed.grabbedInstance.ExpandedBounds); } else { ReleaseInstance(ref this.leftGrabbed); } } }