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

Add static methods to convert matrices #6

Merged
merged 1 commit into from
Jun 1, 2021

Conversation

nesk
Copy link
Contributor

@nesk nesk commented May 26, 2021

I've added two methods to convert a HmdMatrix34_t to a Matrix4x4 and vice versa.

The purpose is to ease transformations, here's an example:

double radians = (Math.PI / 180) * 45; // 45 degrees to radians
var rotation = Matrix4x4.CreateRotationX(radians);
var translation = Matrix4x4.CreateTranslation(0, -0.3f, -0.9f);
var transform = Matrix4x4.Multiply(rotation, translation);

Overlay overlay = new("key", "name")
{
    Transform = OVRSharp.Math.Matrix.ConvertNet4x4ToOpenVr3x4(transform),
};

There's one drawback: I had to include the System.Numerics.Vectors package. Not sure why (I'm new to .NET) because I didn't have to do that on my own project, maybe it depends on the target framework and/or the output type?

If the included package is a no-go, feel free to close the PR. The code is not lost and I will still use it in my own project.

@tjhorner
Copy link
Member

Thanks!

There's one drawback: I had to include the System.Numerics.Vectors package. Not sure why (I'm new to .NET)

That's probably because System.Numerics.Vectors is not included in .NET Standard 2.0. Looks like the package provided on NuGet is compatible with Standard 2.0, so I'm fine with adding it.

OVRSharp/Math/Matrix.cs Outdated Show resolved Hide resolved
@nesk nesk force-pushed the matrix-helpers branch from 153e5dd to 35260a8 Compare May 29, 2021 23:33
@nesk nesk force-pushed the matrix-helpers branch from 35260a8 to 7689327 Compare May 29, 2021 23:35
@tjhorner tjhorner merged commit dc4e0c1 into OVRTools:master Jun 1, 2021
@nesk nesk deleted the matrix-helpers branch June 2, 2021 18:09
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 this pull request may close these issues.

2 participants