public Vector3 GetPosition() { Vector3 positionMouse; Camera positionCamera = GameObject.Find("Main Camera").GetComponent <Camera> (); if (positionCamera == null) { throw new System.ArgumentException("Camera not found"); } if (!mouse) { Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); // Map gaze indicator Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); positionMouse = new Vector3((float)gp.X, (float)gp.Y, 0); positionMouse = Camera.main.ScreenToWorldPoint(positionMouse); if (Points.stateGame.saveData) { Points.stateGame.Save((float)gp.X, (float)gp.Y); } } else { positionMouse = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, positionCamera.nearClipPlane + 1f)); } return(positionMouse); }
public List <RaycastResult> Raycast2Canvas(GameObject canvas) { GraphicRaycaster graphic = canvas.GetComponent <GraphicRaycaster>(); PointerEventData point = new PointerEventData(null); Camera Camera = GameObject.Find("Main Camera").GetComponent <Camera> (); if (Camera == null) { throw new System.ArgumentException("Camera not found"); } if (!mouse) { Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); // Map gaze indicator Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); point.position = new Vector3((float)gp.X, (float)gp.Y, Camera.nearClipPlane + 1f); } else { point.position = Input.mousePosition; } List <RaycastResult> results = new List <RaycastResult>(); graphic.Raycast(point, results); EventSystem.current.RaycastAll(point, results); return(results); }
void Update() { Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); Vector3 planeCoord = Vector3.zero; if (null != gazeCoords) { // Map gaze indicator Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, _Camera.nearClipPlane + .1f); planeCoord = _Camera.ScreenToWorldPoint(screenPoint); _GazeIndicator.transform.position = planeCoord; } if (_ShowGazeIndicator && !_GazeIndicator.activeSelf) { _GazeIndicator.SetActive(true); } else if (!_ShowGazeIndicator && _GazeIndicator.activeSelf) { _GazeIndicator.SetActive(false); } }
private Vector3 GetGazeScreenPosition(Point2D gp) { if (null != gp) { Point2D sp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gp); return(new Vector3((float)sp.X, (float)sp.Y, 0f)); } else { return(Vector3.zero); } }
// Update is called once per frame void Update() { Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); GraphicRaycaster gr = this.GetComponent <GraphicRaycaster>(); //Current pointer position PointerEventData point = new PointerEventData(null); if (!Global.useMouse) { Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); point.position = new Vector3((float)gp.X, (float)gp.Y, CamaraPosition.nearClipPlane + 1f); } else { point.position = Input.mousePosition; } //result will contain all of the hit canvas List <RaycastResult> results = new List <RaycastResult> (); gr.Raycast(point, results); if (results.Count > 0) { if (results [0].gameObject.name == "Back") { backText.color = Color.green; if (delay > waitTimeButtons) { SceneManager.LoadScene("MainMenu"); } else { delay += Time.deltaTime; } } else { backText.color = Color.white; delay = 0; } } }
private void PositionWayPoint() { if (null != _CurrentHit) { // position based on Gazable target if not too close Vector3 targetVec = _CurrentHit.transform.position - transform.position; double distance = Math.Abs(targetVec.magnitude); if (distance > 40) { Vector3 newTarget = _CurrentHit.transform.position; // We adjust target vertically to force pitch float yDiff = _CurrentHit.transform.position.y - transform.position.y; newTarget.y += yDiff; _EyeTarget.transform.position = newTarget; SetTarget(_EyeTarget.transform); return; } } //position based on gaze if (m_TakenOff) { Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); Vector3 planeCoord = Vector3.zero; if (null != gazeCoords) { // Map gaze to Unity space Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, WAYPOINT_DISTANCE); planeCoord = _Camera.ScreenToWorldPoint(screenPoint); _EyeTarget.transform.position = planeCoord; SetTarget(_EyeTarget.transform); } } }
// Update is called once per frame void Update() { /* @TheEyeTribe Check for collision and position waypoint */ Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); Vector3 mouse; playerPos = transform.position; float radio = GetComponent <Renderer> ().bounds.extents.x; if (!Global.useMouse) { // Map gaze indicator Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); mouse = new Vector3((float)gp.X, (float)gp.Y, CamaraPosition.z); mouse = Camera.main.ScreenToWorldPoint(mouse); if (Global.saveData == true) { SaveMedicalData.instance.Save((float)gp.X, (float)gp.Y); } } else { mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition); } if (mouse.x - playerPos.x < -radio / 100) //Raton a la izquierda { transform.Translate(-1 * speed); } else if (mouse.x - playerPos.x > radio / 3) { transform.Translate(speed); } if (transform.position.x > WallPosition.rightWallX) { transform.position = new Vector3(WallPosition.rightWallX, transform.position.y, transform.position.z);; } if (transform.position.x < WallPosition.leftWallX) { transform.position = new Vector3(WallPosition.leftWallX, transform.position.y, transform.position.z); } }
private void Update() { /* @TheEyeTribe Check for collision and position waypoint */ Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); if (null != gazeCoords) { // Map gaze indicator Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, _Camera.nearClipPlane + .1f); // Handle collision detection Vector3 hitPoint; if (checkGazeCollision(screenPoint, out hitPoint)) { //do nothing } } else { // Use mouse position for hover effect as default Vector3 hitPoint; if (checkGazeCollision(Input.mousePosition, out hitPoint)) { //do nothing } } /* @TheEyeTribe Handling callback queue on main thread */ lock (_CallbackQueue) { //we handle queued callback in the update loop while (_CallbackQueue.Count > 0) { _CallbackQueue.Dequeue()(); } } }
void Update() { if (!GazeManager.Instance.IsCalibrating) { //Set eyes size based on distance _EyesDistance = GazeDataValidator.Instance.GetLastValidUserPosition().Z; _DepthMod = (1 - _EyesDistance) * .25f; Vector3 scaleVec = new Vector3((float)(_DepthMod), (float)(_DepthMod), (float)_EyeBaseScale.z); Eye left = GazeDataValidator.Instance.GetLastValidLeftEye(); Eye right = GazeDataValidator.Instance.GetLastValidRightEye(); double angle = -GazeDataValidator.Instance.GetLastValidEyesAngle(); if (null != left) { if (!_LeftEye.GetComponent <Renderer>().enabled) { _LeftEye.GetComponent <Renderer>().enabled = true; } //position GO based on screen coordinates Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(left.PupilCenterCoordinates); PositionGOFromScreenCoords(_LeftEye, gp); _LeftEye.transform.localScale = scaleVec; _LeftEye.transform.eulerAngles = new Vector3(_LeftEye.transform.eulerAngles.x, _LeftEye.transform.eulerAngles.y, (float)angle); } else { if (_LeftEye.GetComponent <Renderer>().enabled) { _LeftEye.GetComponent <Renderer>().enabled = false; } } if (null != right) { if (!_RightEye.GetComponent <Renderer>().enabled) { _RightEye.GetComponent <Renderer>().enabled = true; } //position GO based on screen coordinates Point2D gp = UnityGazeUtils.GetRelativeToScreenSpace(right.PupilCenterCoordinates); PositionGOFromScreenCoords(_RightEye, gp); _RightEye.transform.localScale = scaleVec; _RightEye.transform.eulerAngles = new Vector3(_RightEye.transform.eulerAngles.x, _RightEye.transform.eulerAngles.y, (float)angle); } else { if (_RightEye.GetComponent <Renderer>().enabled) { _RightEye.GetComponent <Renderer>().enabled = false; } } } else { _LeftEye.GetComponent <Renderer>().enabled = false; _RightEye.GetComponent <Renderer>().enabled = false; } if (GazeManager.Instance.IsCalibrated) { if (!_GazeIndicator.GetComponent <Renderer>().enabled) { _GazeIndicator.GetComponent <Renderer>().enabled = true; } Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); if (null != gazeCoords) { // Map gaze indicator Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, _Camera.nearClipPlane + .1f); Vector3 planeCoord = _Camera.ScreenToWorldPoint(screenPoint); _GazeIndicator.transform.position = planeCoord; } } else { if (_GazeIndicator.GetComponent <Renderer>().enabled) { _GazeIndicator.GetComponent <Renderer>().enabled = false; } } lock (_CallbackQueue) { //we handle queued callback in the update loop while (_CallbackQueue.Count > 0) { _CallbackQueue.Dequeue()(); } } //handle keypress if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } }
// Update is called once per frame void Update() { Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); GraphicRaycaster gr = this.GetComponent <GraphicRaycaster>(); //Current pointer position PointerEventData point = new PointerEventData(null); if (!Global.useMouse) { Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); point.position = new Vector3((float)gp.X, (float)gp.Y, CamaraPosition.nearClipPlane + 1f); } else { point.position = Input.mousePosition; } //result will contain all of the hit canvas List <RaycastResult> results = new List <RaycastResult> (); gr.Raycast(point, results); if (results.Count > 0) { for (int i = 0; i < results.Count; i++) { if (results [i].gameObject.name == "menu") { text.color = Color.blue; if (delay > waitTime) { try{ if (KeyboardManager.keyboardManager.getText() != "") { SavePoints.pointsInstance.Save(new PlayerPoints(KeyboardManager.keyboardManager.getText(), Global.points)); KeyboardManager.keyboardManager.setText(""); SceneManager.LoadScene("MainMenu"); } } catch (System.Exception e) { SceneManager.LoadScene("MainMenu"); } } else { delay += Time.deltaTime; } } else { text.color = Color.white; } if (results [i].gameObject.name == "keyboard") { if (delay > waitTime) { SceneManager.LoadScene("Keyboard"); } else { delay += Time.deltaTime; } } } } }
// Update is called once per frame void Update() { Point2D gazeCoords = GazeDataValidator.Instance.GetLastValidSmoothedGazeCoordinates(); GraphicRaycaster gr = this.GetComponent <GraphicRaycaster>(); //Current pointer position PointerEventData point = new PointerEventData(null); if (!Global.useMouse) { Point2D gp = UnityGazeUtils.GetGazeCoordsToUnityWindowCoords(gazeCoords); point.position = new Vector3((float)gp.X, (float)gp.Y, CamaraPosition.nearClipPlane + 1f); } else { point.position = Input.mousePosition; } //result will contain all of the hit canvas List <RaycastResult> results = new List <RaycastResult> (); gr.Raycast(point, results); if (results.Count > 0) { for (int i = 0; i < results.Count; i++) { if (results [i].gameObject.name == "Save") { results [i].gameObject.GetComponent <Image> ().color = Color.green; objectObserved.gameObject.GetComponent <Image> ().color = Color.green; if (delay > waitTime) { SceneManager.LoadScene("FinishGame"); } else { delay += Time.deltaTime; } } else { GameObject.Find("Save").gameObject.GetComponent <Image> ().color = bColor; } if (results [i].gameObject.name == "Delete") { results [i].gameObject.GetComponent <Image> ().color = Color.green; if (delay > waitTime) { try { text = text.Substring(0, text.Length - 1); nameText.text = text; delay = 0; } catch (System.Exception e) { text = ""; delay = 0; } } else { delay += Time.deltaTime; } } else { GameObject.Find("Delete").gameObject.GetComponent <Image> ().color = bColor; } if (results [i].gameObject.name == "Space") { results [i].gameObject.GetComponent <Image> ().color = Color.green; if (delay > waitTime) { text = text + " "; delay = 0; } else { delay += Time.deltaTime; } } else { GameObject.Find("Space").gameObject.GetComponent <Image> ().color = bColor; } if (results [i].gameObject.name == "letter") { objectObserved = results [i].gameObject; objectObserved.gameObject.GetComponent <Image> ().color = Color.green; if (delay > waitTime) { text += results [i].gameObject.GetComponentInChildren <Text> ().text; nameText.text = text; delay = 0; } else { delay += Time.deltaTime; } } else { if (objectObserved != null && results [i].gameObject != objectObserved) { objectObserved.GetComponent <Image> ().color = bColor; } } } } }