/// <summary> /// Moves the maul sabers based on a two controller scheme /// </summary> private void TransformTwoControllerMaul() { var config = Configuration.instance.ConfigurationData; float sep = 1.0f * config.MaulDistance / 100.0f; // Determine Hand positions Pose leftHand = BehaviorCatalog.instance.SaberDeviceManager.GetLeftSaberPose(config.LeftMaulTracker); Pose rightHand = BehaviorCatalog.instance.SaberDeviceManager.GetRightSaberPose(config.RightMaulTracker); // Determine final saber positions and rotations Vector3 middlePos = (rightHand.position + leftHand.position) * 0.5f; Vector3 forward = (rightHand.position - leftHand.position).normalized; Vector3 rightHandUp = rightHand.rotation * Vector3.up; Saber forwardSaber = config.ReverseMaulDirection ? this.saberManager.leftSaber : this.saberManager.rightSaber; Saber backwardSaber = config.ReverseMaulDirection ? this.saberManager.rightSaber : this.saberManager.leftSaber; forwardSaber.transform.position = middlePos + (forward * sep); backwardSaber.transform.position = middlePos + (-forward * sep); forwardSaber.transform.rotation = Quaternion.LookRotation(forward, rightHandUp); backwardSaber.transform.rotation = Quaternion.LookRotation(-forward, -rightHandUp); if (MultiplayerLocalActivePlayerGameplayManagerPatch.multiplayerSaberManager) { MultiplayerSyncStateManagerPatch.SetMultiplayerSaberPositionAndRotate(config.ReverseMaulDirection ? forwardSaber : backwardSaber, config.ReverseMaulDirection ? backwardSaber : forwardSaber); } }
/// <summary> /// Transform the spear based on two controllers /// </summary> private void TransformForTwoControllerSpear() { const float handleLength = 0.75f; const float handleLengthSquared = 0.5625f; var config = Configuration.instance.ConfigurationData; // Determine the forward hand if (Configuration.instance.ConfigurationData.UseTriggerToSwitchHands) { if (BehaviorCatalog.instance.InputManager.GetLeftTriggerClicked()) { this.useLeftHandForward = true; } if (BehaviorCatalog.instance.InputManager.GetRightTriggerClicked()) { this.useLeftHandForward = false; } } // Get positions and rotations of hands Pose leftPosition = BehaviorCatalog.instance.SaberDeviceManager.GetLeftSaberPose(config.LeftSpearTracker); Pose rightPosition = BehaviorCatalog.instance.SaberDeviceManager.GetRightSaberPose(config.RightSpearTracker); Pose forwardHand = this.useLeftHandForward ? leftPosition : rightPosition; Pose rearHand = this.useLeftHandForward ? rightPosition : leftPosition; Vector3 forward = (forwardHand.position - rearHand.position).normalized; Vector3 up = forwardHand.rotation * Vector3.one; // Determine final saber position Vector3 saberPosition; float handSeparationSquared = (forwardHand.position - rearHand.position).sqrMagnitude; if (handSeparationSquared > handleLengthSquared) { // Clamp the saber at the extent of the forward hand saberPosition = forwardHand.position; } else { // Allow the saber to be pushed forward by the rear hand saberPosition = rearHand.position + (forward * handleLength); } if (Configuration.instance.ConfigurationData.ReverseSpearDirection) { forward = -forward; } // Apply transforms to saber Saber saberToTransform = Configuration.instance.ConfigurationData.UseLeftSpear ? this.saberManager.leftSaber : this.saberManager.rightSaber; saberToTransform.transform.position = saberPosition; saberToTransform.transform.rotation = Quaternion.LookRotation(forward, up); if (MultiplayerLocalActivePlayerGameplayManagerPatch.multiplayerSaberManager) { MultiplayerSyncStateManagerPatch.SetMultiplayerSaberPositionAndRotate(Configuration.instance.ConfigurationData.UseLeftSpear ? saberToTransform : this.saberManager.rightSaber, Configuration.instance.ConfigurationData.UseLeftSpear ? this.saberManager.leftSaber : saberToTransform); } }
/// <summary> /// Moves the left saber to the given <see cref="Pose"/> /// </summary> public void SetLeftSaberPose(Pose pose) { if (this.saberManager == null) { return; } this.saberManager.leftSaber.transform.position = pose.position; this.saberManager.leftSaber.transform.rotation = pose.rotation; if (MultiplayerLocalActivePlayerGameplayManagerPatch.multiplayerSaberManager) { MultiplayerSyncStateManagerPatch.SetMultiplayerLeftSaberPose(pose); } }
/// <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 <TrackerConfigData, Pose> getBaseController; TrackerConfigData baseTrackerConfig; Saber baseSaber; Saber otherSaber; if (config.UseLeftController) { getBaseController = BehaviorCatalog.instance.SaberDeviceManager.GetLeftSaberPose; baseTrackerConfig = config.LeftMaulTracker; baseSaber = this.saberManager.leftSaber; otherSaber = this.saberManager.rightSaber; } else { getBaseController = BehaviorCatalog.instance.SaberDeviceManager.GetRightSaberPose; baseTrackerConfig = config.RightMaulTracker; baseSaber = this.saberManager.rightSaber; otherSaber = this.saberManager.leftSaber; } var rotateSaber = config.ReverseMaulDirection ? baseSaber : otherSaber; // Move the other saber to the base saber Pose basePose = getBaseController(baseTrackerConfig); baseSaber.transform.position = basePose.position; baseSaber.transform.rotation = basePose.rotation; otherSaber.transform.position = basePose.position; otherSaber.transform.rotation = basePose.rotation; // Rotate the 'opposite' saber 180 degrees around rotateSaber.transform.Rotate(0.0f, 180.0f, 180.0f); rotateSaber.transform.Translate(0.0f, 0.0f, sep * 2.0f, Space.Self); if (MultiplayerLocalActivePlayerGameplayManagerPatch.multiplayerSaberManager) { MultiplayerSyncStateManagerPatch.SetMultiplayerSaberPositionAndRotate(config.ReverseMaulDirection ? baseSaber : otherSaber, config.ReverseMaulDirection ? otherSaber : baseSaber); } }
/// <summary> /// Transform the right spear based on the controller or the tracker /// </summary> private void TransformForOneControllerSpearRight() { var config = Configuration.instance.ConfigurationData; if (config.UseLeftController && config.RemoveOtherSaber) { return; } Pose saberPose = BehaviorCatalog.instance.SaberDeviceManager.GetRightSaberPose(config.RightSpearTracker); this.saberManager.rightSaber.transform.position = saberPose.position; this.saberManager.rightSaber.transform.rotation = saberPose.rotation; if (config.ReverseSpearDirection) { this.saberManager.rightSaber.transform.Rotate(0.0f, 180.0f, 180.0f); } if (MultiplayerLocalActivePlayerGameplayManagerPatch.multiplayerSaberManager) { MultiplayerSyncStateManagerPatch.SetMultiplayerSaberPositionAndRotate(this.saberManager.leftSaber, this.saberManager.rightSaber); } }