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

Question about the Matrix convention (C#/XNA) #433

Open
demonixis opened this issue Mar 8, 2017 · 2 comments
Open

Question about the Matrix convention (C#/XNA) #433

demonixis opened this issue Mar 8, 2017 · 2 comments

Comments

@demonixis
Copy link

@demonixis demonixis commented Mar 8, 2017

Hi,
I'm trying to add OpenVR support in my game engine which uses MonoGame as Backend.
The implementation goes well but I've problems with the matrix convention.

XNA uses the same matrix convention as directX but I haven't find any docs about the matrix convention used in OpenVR.

This is how I convert an OpenVR matrix to XNA matrix

public static Matrix ToXNA(this HmdMatrix34_t mat)
{
	var m = new Matrix(
		mat.m0, mat.m4, mat.m8, 0.0f,
		mat.m1, mat.m5, mat.m9, 0.0f,
		mat.m2, mat.m6, mat.m10, 0.0f,
		mat.m3, mat.m7, mat.m11, 1.0f);

	return m;
}

public static Matrix ToXNA(this HmdMatrix44_t mat)
{
	var m = new Matrix(
		mat.m0, mat.m4, mat.m8, mat.m12,
		mat.m1, mat.m5, mat.m9, mat.m13,
		mat.m2, mat.m6, mat.m10, mat.m14,
		mat.m3, mat.m7, mat.m11, mat.m15);

	return m;
}

It's almost OK, but the tracking data is not good (some axes are reversed). This is my WIP implementation

Thank you for your help.

@MarcVador
Copy link

@MarcVador MarcVador commented Mar 9, 2017

OpenVR may be using Left handedness, that would explain your reversed axes.

@TheHans255
Copy link

@TheHans255 TheHans255 commented Mar 23, 2017

Matrices in OpenVR are in the same format as that used by OpenGL - column major, assuming right-handed coordinate system with +x to the right, +y up, and +z toward camera. XNA matrices are row major (which you get right) but have +z away from the camera (which you need to adjust for with a FlipZ transformation of some kind).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.