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

Error - OculusTouchCursor.cs - UnityEngine.Matrix4x4 does not contain 'GetRotation' method #57

Closed
richyz opened this issue Dec 31, 2016 · 3 comments
Assignees
Labels

Comments

@richyz
Copy link

richyz commented Dec 31, 2016

Hello, awesome software, wow very nice!!!

When I compile, I get this error:
Assets/Hover/InputModules/OculusTouch/Scripts/OculusTouchCursor.cs(120,36): error CS1061: Type UnityEngine.Matrix4x4' does not contain a definition for GetRotation' and no extension method GetRotation' of type UnityEngine.Matrix4x4' could be found. Are you missing an assembly reference?

From this function (error is shown in comments):
` /--------------------------------------------------------------------------------------------/
private void UpdateDataWithLocalOffsets(ICursorDataForInput pData,
HoverInputOculusTouch.ControlState pState) {
Matrix4x4 txMat = OriginTransform.localToWorldMatrix;
Matrix4x4 txRotMat = txMat*Matrix4x4.TRS(Vector3.zero, pState.LocalRot, Vector3.one);

	pData.SetWorldPosition(txMat.MultiplyPoint3x4(pState.LocalPos)+
		txRotMat.MultiplyVector(LocalPosition));
	// pData.SetWorldRotation(txRotMat.GetRotation()*Quaternion.Euler(LocalRotation));
	// Above line was throwing error, and below line compiles but I don't know the fix
	pData.SetWorldRotation(Quaternion.Euler(LocalRotation));
}

`

Also, I'd like to try and use different data in your Force Directed Graph example. Is this possible with this code? Any suggestion on how to do this?

Thanks for sharing this excellent software!
Rich

@zachkinstner
Copy link
Member

Hi @richyz, thanks for posting this bug. The GetRotation() referenced here is actually a Matrix4x4 extension method that is defined by code in the Steam VR asset package (in SteamVR_Utils.cs).

My mistake -- I have both Steam VR (for Vive) and Oculus packages installed in my local project, so I didn't see this compilation error.

As an immediate workaround, you could use the code from the Steam VR package:

public static Quaternion GetRotation(this Matrix4x4 matrix) {
	Quaternion q = new Quaternion();
	q.w = Mathf.Sqrt(Mathf.Max(0, 1 + matrix.m00 + matrix.m11 + matrix.m22)) / 2;
	q.x = Mathf.Sqrt(Mathf.Max(0, 1 + matrix.m00 - matrix.m11 - matrix.m22)) / 2;
	q.y = Mathf.Sqrt(Mathf.Max(0, 1 - matrix.m00 + matrix.m11 - matrix.m22)) / 2;
	q.z = Mathf.Sqrt(Mathf.Max(0, 1 - matrix.m00 - matrix.m11 + matrix.m22)) / 2;
	q.x = _copysign(q.x, matrix.m21 - matrix.m12);
	q.y = _copysign(q.y, matrix.m02 - matrix.m20);
	q.z = _copysign(q.z, matrix.m10 - matrix.m01);
	return q;
}

I'll look into a code fix that avoids this dependency.

zachkinstner added a commit that referenced this issue Jan 2, 2017
@zachkinstner
Copy link
Member

@richyz, the commit link above includes a proper fix for this issue. It turns out that the method's use of Matrix4x4 was unnecessary, making the GetRotation() extension method unnecessary, as well.

For now, please patch this updated method into your code. This change will be included in the next Hover UI Kit release.

private void UpdateDataWithLocalOffsets(ICursorDataForInput pData,
                                               HoverInputOculusTouch.ControlState pState) {
    pData.SetWorldPosition(
        OriginTransform.TransformPoint(pState.LocalPos)+pState.LocalRot*LocalPosition);
    pData.SetWorldRotation(
        OriginTransform.rotation*pState.LocalRot*Quaternion.Euler(LocalRotation));
}

@zachkinstner zachkinstner self-assigned this Jan 2, 2017
@richyz
Copy link
Author

richyz commented Jan 3, 2017

Hi Zach, that resolved the issue. I sent you an email, Thanks for the quick response and fix! -Rich

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

No branches or pull requests

2 participants