Home › Forums › Software Development › Get Eye-screen-coordinates and match it with a Unity game object › Reply To: Get Eye-screen-coordinates and match it with a Unity game object
02/05/2015 at 18:48 #2926
Participant
I use the code below but it moves just opposite on the X coordinate (it goes left when I look right and it goes right when I look left). Unfortunately, I cannot find the mistake here;
void Update()
{
var displaySize = _eyeXHost.DisplaySize;
var screenBounds = _eyeXHost.ScreenBounds;
var gazePoint = _gazePointDataComponent.LastGazePoint;
var gazePointOnDisplayX = gazePoint.Display.x;
var gazePointOnDisplayY = gazePoint.Display.y;
if (displaySize.IsValid &&
screenBounds.IsValid && screenBounds.Value.Width > 0 && screenBounds.Value.Height > 0 &&
gazePoint.IsValid)
{
var normalizedGazePoint = new Vector2(
(float)((gazePointOnDisplayX - screenBounds.Value.X) / screenBounds.Value.Width),
(float)((gazePointOnDisplayY - screenBounds.Value.Y) / screenBounds.Value.Height));
var gazePointOnDisplayPlaneMm = new Vector2(
(float)((0.5 - normalizedGazePoint.x) * displaySize.Value.Width),
(float)((0.5 - normalizedGazePoint.y) * displaySize.Value.Height));
_rendererComponent.transform.position = new Vector3(
gazePointOnDisplayPlaneMm.x * Scale,
gazePointOnDisplayPlaneMm.y * Scale,
0);
_rendererComponent.enabled = true;
}
else
{
_rendererComponent.enabled = false;
}
}
Could you help me please ?