public Pose GetRightSaberPose() { if (!calibrated || !this.rightController.isValid) { return(new Pose()); } Pose?rightControllerPose = this.GetBeatSaberDevicePosition(this.rightController); if (rightControllerPose == null) { return(new Pose()); } return(TrackedDeviceManager.GetTrackedObjectPose(this.savedRightSaber, this.savedRightController.Value, rightControllerPose.Value)); }
/// <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); } } }