public void Update() { bool useMouseAsInput = true; Point2D userPos = gazeUtils.GetLastValidUserPosition(); if (null != userPos) { //mapping cam panning to 3:2 aspect ratio double tx = (userPos.X * 5) - 2.5f; double ty = (userPos.Y * 3) - 1.5f; //camera 'look at' origo cam.transform.LookAt(Vector3.zero); } if (!useMouseAsInput) { Point2D gazeCoords = gazeUtils.GetLastValidSmoothedGazeCoordinates(); if (null != gazeCoords) { //map gaze indicator Point2D gp = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gazeCoords); Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, cam.nearClipPlane + .1f); Vector3 planeCoord = cam.ScreenToWorldPoint(screenPoint); //gazeIndicator.transform.position = planeCoord; //handle collision detection checkGazeCollision(screenPoint); // eye tracker } } if (useMouseAsInput) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 PositionToMoveTo = ray.GetPoint(5); checkGazeCollision(PositionToMoveTo); // mouse //go.transform.position = PositionToMoveTo; } //handle keypress if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } else if (Input.GetKey(KeyCode.Space)) { Application.LoadLevel(0); } }
void Update() { Point2D userPos = gazeUtils.GetLastValidUserPosition(); if (null != userPos) { //mapping cam panning to 3:2 aspect ratio double tx = (userPos.X * 5) - 2.5f; double ty = (userPos.Y * 3) - 1.5f; //position camera X-Y plane and adjust distance eyesDistance = gazeUtils.GetLastValidUserDistance(); depthMod = 2 * eyesDistance; Vector3 newPos = new Vector3( (float)tx, (float)ty, (float)(baseDist + depthMod)); cam.transform.position = newPos; //camera 'look at' origo cam.transform.LookAt(Vector3.zero); //tilt cam according to eye angle double angle = gazeUtils.GetLastValidEyesAngle(); cam.transform.eulerAngles = new Vector3(cam.transform.eulerAngles.x, cam.transform.eulerAngles.y, cam.transform.eulerAngles.z + (float)angle); } Point2D gazeCoords = gazeUtils.GetLastValidSmoothedGazeCoordinates(); if (null != gazeCoords) { //map gaze indicator Point2D gp = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gazeCoords); Vector3 screenPoint = new Vector3((float)gp.X, (float)gp.Y, cam.nearClipPlane + .1f); Vector3 planeCoord = cam.ScreenToWorldPoint(screenPoint); gazeIndicator.transform.position = planeCoord; //handle collision detection checkGazeCollision(screenPoint); } //handle keypress if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } else if (Input.GetKey(KeyCode.Space)) { Application.LoadLevel(0); } }
public void UpdateGazeCamera() { Point2D gazeCoords = gazeUtils.GetLastValidSmoothedGazeCoordinates(); if (null != gazeCoords) { //map gaze indicator Point2D gp = UnityGazeUtils.getGazeCoordsToUnityWindowCoords(gazeCoords); screenPoint = new Vector3((float)gp.X, (float)gp.Y, cam.nearClipPlane + .1f); if (useGazeTracker) { Vector3 planeCoord = cam.ScreenToWorldPoint(screenPoint); gazeIndicator.transform.position = planeCoord; } //handle collision detection, just as an example //checkGazeCollision(screenPoint); } }