Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XR Plugin reports wrong eye positions #86

Open
Shii2 opened this issue Mar 22, 2021 · 2 comments · May be fixed by #105
Open

XR Plugin reports wrong eye positions #86

Shii2 opened this issue Mar 22, 2021 · 2 comments · May be fixed by #105

Comments

@Shii2
Copy link

Shii2 commented Mar 22, 2021

Left and Right eye position Y an Z coordinates always equals to Center eye Y and Z coordinates.
Here is a video demonstrating the problem: https://www.youtube.com/watch?v=9Bp0c7_XvuY
Reproduced problem in both Unity 2019.4.22f1 and Unity 2020.3.0f1, using SteamVR 1.16.10, OpenVR Unity XR plugin v1.1.4 and Oculus Rift CV1 headset.
This is the only bug preventing us from migrating our project from Legacy VR and Unity 2019.4.22f1 to XR Plugin and Unity 2020.3
Here is the code that used in above video to report eye positions:

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR;

public class EyePosTest : MonoBehaviour
{
	public Text leftEyePosValue;
	public Text rightEyePosValue;
	public Text centerEyePosValue;
	public Text headPosValue;

	void Update()
	{
		Vector3 leftEyePosition;
		Vector3 rightEyePosition;
		Vector3 centerEyePosition;
		Vector3 headPosition;
		TryGetEyeFeature(out leftEyePosition, XRNode.LeftEye);
		TryGetEyeFeature(out rightEyePosition, XRNode.RightEye);
		TryGetEyeFeature(out centerEyePosition, XRNode.CenterEye);
		TryGetEyeFeature(out headPosition, XRNode.Head);
		leftEyePosValue.text = leftEyePosition.ToString("F4");
		rightEyePosValue.text = rightEyePosition.ToString("F4");
		centerEyePosValue.text = centerEyePosition.ToString("F4");
		headPosValue.text = headPosition.ToString("F4");
	}

	private bool TryGetEyeFeature(out Vector3 position, XRNode eye)
	{
		InputFeatureUsage<Vector3> inputFeatureUsage = CommonUsages.devicePosition;
		if (eye == XRNode.LeftEye)
			inputFeatureUsage = CommonUsages.leftEyePosition;
		else if (eye == XRNode.RightEye)
			inputFeatureUsage = CommonUsages.rightEyePosition;
		else if (eye == XRNode.CenterEye)
			inputFeatureUsage = CommonUsages.centerEyePosition;
		else if (eye == XRNode.Head)
			inputFeatureUsage = CommonUsages.devicePosition;

		InputDevice device = InputDevices.GetDeviceAtXRNode(XRNode.Head);
		if (device.isValid)
		{
			if (device.TryGetFeatureValue(inputFeatureUsage, out position))
				return true;
		}
		// This is the fail case
		position = Vector3.zero;
		return false;
	}
}
@leekentvr
Copy link

leekentvr commented Mar 22, 2021

image

Another visualisation of the bug, with headset looking straight on, and looking to the right. The left eye (green) and right eye (red) are also flipped over.
The do not rotate around the centre point as would be expected.

@Shii2
Copy link
Author

Shii2 commented Sep 29, 2021

Analyzed unity-xr-plugin source code and found a fix!
Issue was found in file

xrTrackingTransformRef *= reinterpret_cast< XRMatrix4x4 & >( *postTransform );
at line 477 and this happens because wrong matrix multiplication order is used.
To fix the issue replace this line with:
xrTrackingTransformRef = reinterpret_cast< XRMatrix4x4 & >( *postTransform ) * xrTrackingTransformRef;

Shii2 added a commit to Shii2/unity-xr-plugin that referenced this issue Sep 29, 2021
@Shii2 Shii2 linked a pull request Sep 29, 2021 that will close this issue
zite added a commit that referenced this issue Mar 23, 2023
- Updated to SteamVR SDK 1.23.7
- Fix for unnecessary preinit #80
- Fix for incorrect reporting of eye position #86
- Fix for broken depth textures in some situations #110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants