/// <summary> /// This method checks if a relative movement was started by the user. /// If started, the relative quaternion start value is set and the gain function reseted. /// </summary> public void CheckStartOfRelativeMovement() { Vector3 angularVelocity; Quaternion rotation; if (HandManager.IsRayRelativeUp()) { foreach (GameObject part in partsVisualRay) { part.GetComponent <Renderer>().material = rayInactiveMaterial; } } if (HandManager.IsRayRelativeDown()) { if (HandManager.CurrentHand.TryGetRotation(out rotation)) { currentRelativeRotation = Quaternion.identity; lastRelativeRotation = rotation; startRelativeQuat = rotation; foreach (GameObject part in partsVisualRay) { part.GetComponent <Renderer>().material = rayActiveMaterial; } if (HandManager.CurrentHand.TryGetAngularVelocity(out angularVelocity)) { GainFunction.ResetFunction(angularVelocity); } else { GainFunction.ResetFunction(startRelativeQuat, Time.time); } } else { startRelativeQuat = Quaternion.identity; GainFunction.ResetFunction(startRelativeQuat, Time.time); Debug.LogError("No start rotation data avaiable."); return; } } if (HandManager.IsRayRelative() || HandManager.IsRayRelativeUp()) { if (HandManager.CurrentHand.TryGetAngularVelocity(out angularVelocity)) { GainFunction.Instance.UpdateFunction(Mathf.Rad2Deg * angularVelocity.magnitude); } else if (HandManager.CurrentHand.TryGetRotation(out rotation)) { GainFunction.Instance.UpdateFunction(rotation, Time.time); } else { Debug.LogError("No velocity and rotation data avaiable"); } } }
/// <summary> /// This is a listener that is called from the depth ray manager every time a ray is shot. /// It updates the state of the object and resets timer /// </summary> public void OnUpdatePointer(GameObject newFocusedObject) { if (currentFocusedObject == newFocusedObject) { return; } timeTargetInFocusAndButtonDown = -1f; if (newFocusedObject == null || TargetManager.IsAnyObjectAttached()) { currentFocusedObject = null; } else { //check if update should be happen // velocity under a threshold and click Vector3 angularVelocity = Vector3.zero; if (HandManager.IsRayRelative() && HandManager.CurrentHand.TryGetAngularVelocity(out angularVelocity) && angularVelocity.magnitude < 0.5f) { switch (newFocusedObject.tag) { case "Target": Target target = newFocusedObject.GetComponent <Target>(); target.StartTimeInFocus = Time.time; targetsInFoucsSinceLastClickDown.Add(target); timeTargetInFocusAndButtonDown = 0; currentFocusedObject = newFocusedObject; break; case "Obstacle": currentFocusedObject = newFocusedObject; break; case "UI": currentFocusedObject = newFocusedObject; break; default: currentFocusedObject = null; break; } } else { currentFocusedObject = null; } } //CheckLeftClick(); }
/// <summary> /// This method sets and updates the rays from the head into the scene. /// The gaze direction is changed when the relative movement is active. /// Then the direction is steered by the controller or myo armband. /// </summary> public virtual void OnPreRaycast() { Vector3 forward; Vector3 position; switch (VariablesManager.InputMode) { case InputMode.HeadMyoHybrid: case InputMode.HeadHybrid: if (head == null) { rays[0] = default(RayStep); } else if (HandManager.IsRayRelative() || HandManager.IsRayRelativeUp()) { Quaternion quat; if (HandManager.CurrentHand.TryGetRotation(out quat)) { SetRays(quat); } } else { SetRaysWithHeadAsOrigin(head.transform.forward); } break; /*case InputMode.RayHeadOrigin: * if (HandManager.RayHand.TryGetForward(out forward)) * { * SetRaysWithHeadAsOrigin(forward); * } * break;*/ case InputMode.RayControllerOrigin: if (HandManager.CurrentHand.TryGetForward(out forward) && HandManager.CurrentHand.TryGetPos(out position)) { SetRays(forward, position); } break; } }
/// <summary> /// This method checks if the current focused object was more than a certain time in focus. /// If this is the case, a right click is triggered and true is returned. /// </summary> private bool CheckRightClick() { if (!SceneHandler.UseRightClick || currentFocusedObject == null || TargetManager.IsAnyObjectAttached()) { return(false); } if (HandManager.IsRayRelative()) { //Change time between Myo and Controller float timeRightClick = VariablesManager.TimeRightClickController; if (VariablesManager.InputMode == InputMode.HeadMyoHybrid) { timeRightClick = VariablesManager.TimeRightClickMyo; } isClick = true; rightClickIndicator.transform.localScale = scaleRCIndicatorDefault; if (timeTargetInFocusAndButtonDown >= 0) { timeTargetInFocusAndButtonDown += Time.deltaTime; rightClickIndicator.transform.localScale = scaleRCIndicatorDefault + Mathf.Min(1f, timeTargetInFocusAndButtonDown / timeRightClick) * differenceRCIandDM; HandManager.CurrentHand.Vibrate(Thalmic.Myo.VibrationType.Short); if (timeTargetInFocusAndButtonDown > timeRightClick) { OnRightClick(currentFocusedObject); timeTargetInFocusAndButtonDown = -1; return(true); } } } else { isClick = false; rightClickIndicator.transform.localScale = scaleRCIndicatorDefault; } return(false); }