/// <summary> /// Transforms the <see cref="Transform"/> of a Unity game object based on the given <see cref="TrackerConfigData"/> /// given the current tracker's rotation and position. /// </summary> public static void TransformSaberFromTrackerData(Transform saberTransform, TrackerConfigData trackerConfigData, Pose tracker) { Pose pose = CalculatePoseFromTrackerData(trackerConfigData, tracker); saberTransform.position = pose.position; saberTransform.rotation = pose.rotation; }
/// <summary> /// Moves the maul sabers based on a one controller scheme /// </summary> private void TransformOneControllerMaul() { var config = Configuration.instance.ConfigurationData; float sep = 1.0f * config.MaulDistance / 100.0f; var baseSaber = config.UseLeftController ? saberManager.leftSaber : saberManager.rightSaber; var otherSaber = config.UseLeftController ? saberManager.rightSaber : saberManager.leftSaber; var rotateSaber = config.ReverseMaulDirection ? baseSaber : otherSaber; string trackerSerial = config.UseLeftController ? config.LeftMaulTracker?.Serial : config.RightMaulTracker?.Serial; TrackerConfigData trackerConfigData = config.UseLeftController ? config.LeftMaulTracker : config.RightMaulTracker; Pose?trackerPose; if (String.IsNullOrWhiteSpace(trackerSerial) || (trackerPose = TrackedDeviceManager.instance.GetPoseFromSerial(trackerSerial)) == null) { // Move saber using Beat Saber saber positions otherSaber.transform.localPosition = baseSaber.transform.localPosition; otherSaber.transform.localRotation = baseSaber.transform.localRotation; } else { // Move both sabers to tracker pose Utilities.TransformSaberFromTrackerData(baseSaber.transform, trackerConfigData, trackerPose.Value); Utilities.TransformSaberFromTrackerData(otherSaber.transform, trackerConfigData, trackerPose.Value); } rotateSaber.transform.Rotate(0.0f, 180.0f, 180.0f); rotateSaber.transform.Translate(0.0f, 0.0f, sep * 2.0f, Space.Self); }
protected override void DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { base.DidActivate(firstActivation, addedToHierarchy, screenSystemEnabling); if (this.trackerConfigData == null) { // Calls to this method should never pass in null AlternativePlay.Logger.Error($"TrackerSelectView.DidActivate() Error null tracker was given at {Environment.StackTrace}"); trackerConfigData = new TrackerConfigData(); } this.InitializeTrackerList(); BehaviorCatalog.instance.ShowTrackersBehavior.EnableShowTrackers(); }
public void ShowTrackerSelect(TrackerConfigData trackerConfigData) { this.IsBusy = true; this.SetTitle("Select Tracker"); this.trackerSelectView.SetSelectingTracker(trackerConfigData); this.trackerPoseView.SetSelectingTracker(trackerConfigData); this.ReplaceTopViewController(this.trackerSelectView); this.SetLeftScreenViewController(null, ViewController.AnimationType.In); this.SetRightScreenViewController(this.trackerPoseView, ViewController.AnimationType.In); this.IsBusy = false; }
/// <summary> /// Moves the maul sabers based on a one controller scheme /// </summary> private void TransformOneControllerMaul() { var config = Configuration.instance.ConfigurationData; float sep = 1.0f * config.MaulDistance / 100.0f; // Determine which is the held normally 'base' saber and which is the 'other' saber that must be moved Func <Pose> getBaseController; Saber baseSaber; Saber otherSaber; if (config.UseLeftController) { getBaseController = BehaviorCatalog.instance.ControllerManager.GetLeftSaberPose; baseSaber = saberManager.leftSaber; otherSaber = saberManager.rightSaber; } else { getBaseController = BehaviorCatalog.instance.ControllerManager.GetRightSaberPose; baseSaber = saberManager.rightSaber; otherSaber = saberManager.leftSaber; } var rotateSaber = config.ReverseMaulDirection ? baseSaber : otherSaber; // Move the other saber to the base saber string trackerSerial = config.UseLeftController ? config.LeftMaulTracker?.Serial : config.RightMaulTracker?.Serial; Pose? trackerPose; if (String.IsNullOrWhiteSpace(trackerSerial) || (trackerPose = TrackedDeviceManager.instance.GetPoseFromSerial(trackerSerial)) == null) { // Use controller positions Pose saberPose = getBaseController(); baseSaber.transform.position = saberPose.position; baseSaber.transform.rotation = saberPose.rotation; otherSaber.transform.position = saberPose.position; otherSaber.transform.rotation = saberPose.rotation; } else { // Move both sabers to tracker pose TrackerConfigData trackerConfigData = config.UseLeftController ? config.LeftMaulTracker : config.RightMaulTracker; Utilities.TransformSaberFromTrackerData(baseSaber.transform, trackerConfigData, trackerPose.Value); Utilities.TransformSaberFromTrackerData(otherSaber.transform, trackerConfigData, trackerPose.Value); } rotateSaber.transform.Rotate(0.0f, 180.0f, 180.0f); rotateSaber.transform.Translate(0.0f, 0.0f, sep * 2.0f, Space.Self); }
/// <summary> /// Checks to see if the tracker data used should cause score submissions to be disabled. /// If the position of the saber is anything other than (0, 0, 0) then score /// submission will be disabled. Rotation can be any value. /// </summary> public static void CheckAndDisableForTrackerTransforms(TrackerConfigData trackerConfigData) { if (String.IsNullOrWhiteSpace(trackerConfigData?.Serial)) { return; } if (trackerConfigData.Position != Vector3.zero) { // Disable scoring due to transforms AlternativePlay.Logger.Info($"Position: {trackerConfigData.Position}"); AlternativePlay.Logger.Info("Disabling score submission on tracker with non-default position"); BS_Utils.Gameplay.ScoreSubmission.DisableSubmission(AlternativePlay.assemblyName); } }
/// <summary> /// Calculates the <see cref="Pose"/> based on the given <see cref="TrackerConfigData"/> /// given the current tracker's rotation and position. /// </summary> public static Pose CalculatePoseFromTrackerData(TrackerConfigData trackerConfigData, Pose tracker) { Pose result = Pose.identity; // Calculate and apply rotation first Quaternion extraRotation = Quaternion.Euler(trackerConfigData.EulerAngles); Quaternion finalRotation = tracker.rotation * extraRotation; result.rotation = finalRotation; // Rotate position and add Vector3 rotatedPosition = tracker.rotation * trackerConfigData.Position; result.position = tracker.position + rotatedPosition; return(result); }
/// <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)); } }
public void SetSelectingTracker(TrackerConfigData trackerConfigData) { this.trackerConfigData = trackerConfigData; this.originalPosition = this.trackerConfigData.Position; this.originalEuler = this.trackerConfigData.EulerAngles; }
public void SetSelectingTracker(TrackerConfigData trackerConfigData) { this.trackerConfigData = trackerConfigData; this.originalTrackerData = TrackerConfigData.Clone(trackerConfigData); }
/// <summary> /// Sets the given serial of the tracker as the currently selected tracker. /// The tracker will be drawn with a saber. Send null or a non-existant /// serial to set nothing to be selected. /// </summary> /// <param name="serial">The serial of the tracker to set as selected</param> public void SetSelectedSerial(TrackerConfigData tracker) { this.selectedTracker = tracker; }
/// <summary> /// Gets the pose for the given tracker config data or else it falls back to the /// right controller and then moves the right saber /// </summary> public void SetRightSaber(TrackerConfigData trackerData) { Pose pose = this.GetRightSaberPose(trackerData); this.SetRightSaberPose(pose); }