//create new gaze casting children at the user's eyes private void setupGazeCasters() { Transform leftCamera = GameObject.Find("FrontCameraStereo.Left").transform; Transform rightCamera = GameObject.Find("FrontCameraStereo.Right").transform; leftAlteredEye = new GameObject("leftAlteredEye").AddComponent <EyeGazeRayCaster>(); rightAlteredEye = new GameObject("rightAlteredEye").AddComponent <EyeGazeRayCaster>(); leftUnalteredEye = new GameObject("leftUnalteredEye").AddComponent <EyeGazeRayCaster>(); rightUnalteredEye = new GameObject("rightUalteredEye").AddComponent <EyeGazeRayCaster>(); leftAlteredEye.setLineMaterial(lineMaterial); rightAlteredEye.setLineMaterial(lineMaterial); leftUnalteredEye.setLineMaterial(lineMaterial); rightUnalteredEye.setLineMaterial(lineMaterial); leftAlteredEye.transform.SetParent(this.transform, false); rightAlteredEye.transform.SetParent(this.transform, false); leftUnalteredEye.transform.SetParent(this.transform, false); rightUnalteredEye.transform.SetParent(this.transform, false); leftAlteredEye.transform.localPosition = leftCamera.localPosition; leftUnalteredEye.transform.localPosition = leftCamera.localPosition; rightAlteredEye.transform.localPosition = rightCamera.localPosition; rightUnalteredEye.transform.localPosition = rightCamera.localPosition; }
//moves the altered gaze ray casters to both look at the correct point //also returns the RaycastHit of the object we are looking at private RaycastHit generatedAlteredGaze(EyeGazeRayCaster dominantEye, EyeGazeRayCaster subserviantEye) { RaycastHit dominantRaycastHit; //if we hit something if (dominantEye.rayCast(dominantEye.transform.forward, out dominantRaycastHit)) { Quaternion previousRotatoin = subserviantEye.transform.localRotation; //set the subserviant eye to look at that point subserviantEye.transform.LookAt(dominantRaycastHit.point); RaycastHit rayCastHit; //if we hit anything if (subserviantEye.rayCast(subserviantEye.transform.forward, out rayCastHit)) { //check to see if ray castr towards selected point gives the same point (round a bout) if (Vector3.SqrMagnitude(rayCastHit.point - dominantRaycastHit.point) > 0.0000001f) { //and reset the eye if that isn't the case subserviantEye.transform.localRotation = previousRotatoin; } } } return(dominantRaycastHit); }
//calculate the disparagy between the altered and unaltered gaze, and return the rotation needed for that to work private Vector3 calculateDisparagy(EyeGazeRayCaster alteredRay, EyeGazeRayCaster unalteredRay) { return(alteredRay.transform.localEulerAngles - unalteredRay.transform.localEulerAngles); }