/// <summary> /// Starts scaling the object with the given input source. /// </summary> public void StartScaling(IInputSource inputSource, uint inputSourceId) { if (isScaling) { return; } if (inputSource == null || !inputSource.SupportsInputInfo(inputSourceId, SupportedInputInfo.Position)) { Debug.Log("The provided input source does not support the required positional info."); return; } currentInputSource = inputSource; currentInputSourceId = inputSourceId; // Add self as a modal input handler, to get all inputs during the manipulation. InputManager.Instance.PushModalInputHandler(gameObject); currentInputSource.TryGetPosition(currentInputSourceId, out prevHandPosition); grabPoint = prevHandPosition; scaleUpVector = Vector3.Normalize(grabPoint - TargetGameObject.transform.position); isScaling = true; StartedScaling.RaiseEvent(); }
public void StartScaling() { if (!IsScalingEnabled) { return; } if (isScaling) { return; } InputManager.Instance.PushModalInputHandler(gameObject); isScaling = true; Vector3 inputPosition = Vector3.zero; #if UNITY_2017_2_OR_NEWER InteractionSourceInfo sourceKind; currentInputSource.TryGetSourceKind(currentInputSourceId, out sourceKind); switch (sourceKind) { case InteractionSourceInfo.Hand: currentInputSource.TryGetGripPosition(currentInputSourceId, out inputPosition); break; case InteractionSourceInfo.Controller: currentInputSource.TryGetPointerPosition(currentInputSourceId, out inputPosition); break; } #else currentInputSource.TryGetPointerPosition(currentInputSourceId, out inputPosition); #endif startPosition = inputPosition; startScale = transform.localScale.x; StartedScaling.RaiseEvent(); }
public void StartScaling() { if (!IsDraggingAndScalingEnabled) { return; } if (isScaling) { return; } //extract the only input source isScaling = true; IInputSource inputSource0 = currentInputSources.Values.ToArray()[0]; uint inputSourceId0 = handsPositions.Keys.ToArray()[0]; IInputSource inputSource1 = currentInputSources.Values.ToArray()[1]; uint inputSourceId1 = handsPositions.Keys.ToArray()[1]; Vector3 handPosition0; Vector3 handPosition1; { Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; Vector3 handPosition; inputSource0.TryGetPosition(inputSourceId0, out handPosition); handPosition0 = handPosition; /* * * Vector3 pivotPosition = GetHandPivotPosition(); * handRefDistance = Vector3.Magnitude(handPosition - pivotPosition); * objRefDistance = Vector3.Magnitude(gazeHitPosition - pivotPosition); * * Vector3 objForward = HostTransform.forward; * Vector3 objUp = HostTransform.up; * * // Store where the object was grabbed from * handPosition0 = mainCamera.transform.InverseTransformDirection(HostTransform.position - gazeHitPosition); */ } { Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; Vector3 handPosition; inputSource1.TryGetPosition(inputSourceId1, out handPosition); handPosition1 = handPosition; /* * Vector3 pivotPosition = GetHandPivotPosition(); * handRefDistance = Vector3.Magnitude(handPosition - pivotPosition); * objRefDistance = Vector3.Magnitude(gazeHitPosition - pivotPosition); * * Vector3 objForward = HostTransform.forward; * Vector3 objUp = HostTransform.up; * * // Store where the object was grabbed from * handPosition1 = mainCamera.transform.InverseTransformDirection(HostTransform.position - gazeHitPosition); */ } handRefDistance = Vector3.Distance(handPosition0, handPosition1); handsPositions[inputSourceId0] = handPosition0; handsPositions[inputSourceId1] = handPosition1; StartedScaling.RaiseEvent(); }