internal MotionControllerState GetController(XRNode nodeType, bool preserveState = false) { if (nodeType == XRNode.LeftHand) { if (!preserveState) { LeftController = new MotionControllerState(); LeftController.IsLeftHand = true; } return(LeftController); } else { if (!preserveState) { RightController = new MotionControllerState(); RightController.IsRightHand = true; } return(RightController); } }
public MotionControllerState GetController(InteractionSourceState interaction, bool preserveState = false) { if (interaction.source.handedness == InteractionSourceHandedness.Left) { if (!preserveState) { LeftController = new MotionControllerState(); } return(LeftController); } else { Debug.Assert(interaction.source.handedness == InteractionSourceHandedness.Right, "Right hadnedness should be default/fallback"); if (!preserveState) { RightController = new MotionControllerState(); } return(RightController); } }
public static string GetTraceState(this MotionControllerState state, PoseSource filterInput, bool allChanges, out bool hasNonDefaultValue, out bool hasEvent) { StringBuilder sb = new StringBuilder(); hasNonDefaultValue = false; hasEvent = false; float vector3ThresholdForDifference = 0.2f; float floatThresholdForDifference = 0.02f; if (state.IsLeftHand) { sb.Append(leftPrefix); diffState = pastLeft; } else if (state.IsRightHand) { sb.Append(rightPrefix); diffState = pastRight; } if (state.SelectPressed) { hasEvent = true; sb.AppendFormat("Select Pressed ({0});", state.SelectValue); } if (state.TouchPadPressed || state.TouchPadTouched) { hasEvent = true; sb.AppendFormat("TouchPad {0} {1} ({2},{3});", state.TouchPadPressed ? "Pressed" : "", state.TouchPadTouched ? "Touched" : "", state.TouchPadXValue, state.TouchPadYValue); } if (state.ThumbstickPressed) { hasEvent = true; sb.AppendFormat("Thumbstick pressed({0},{1});", state.ThumbstickXValue, state.ThumbstickYValue); } if (state.MenuPressed) { hasEvent = true; sb.Append("Menu Pressed;"); } if (state.GraspPressed) { hasEvent = true; sb.Append("Grasp Pressed;"); } // Grip position if ((filterInput & PoseSource.Grip) != PoseSource.None) { if (allChanges || (IsDifferent(state.GripPosition, diffState.GripPosition, vector3ThresholdForDifference))) { hasNonDefaultValue = true; sb.AppendFormat("Pos:{0},Rot:{1}", state.GripPosition, state.GripRotation); } } // Pointer position if ((filterInput & PoseSource.Pointer) != PoseSource.None) { if (allChanges || (IsDifferent(state.PointerPosition, diffState.PointerPosition, vector3ThresholdForDifference))) { hasNonDefaultValue = true; sb.AppendFormat("PointPos:{0},PointRot:{1}", state.PointerPosition, state.PointerRotation); } } if (allChanges || (IsDifferent(state.ThumbstickXValue, diffState.ThumbstickXValue, floatThresholdForDifference) || IsDifferent(state.ThumbstickYValue, diffState.ThumbstickYValue, floatThresholdForDifference))) { hasNonDefaultValue = true; sb.AppendFormat("Thumb:{0},{1}", state.ThumbstickXValue, state.ThumbstickYValue); } string message = sb.ToString(); #if TRACING_VERBOSE if (hasNonDefaultValue || HasContent(message)) { Debug.Log(message); } #endif if (state.IsLeftHand) { pastLeft = state; } else if (state.IsRightHand) { pastRight = state; } return(message); }