aestheticinteractive / Hover-UI-Kit

Create beautiful user interfaces for immersive VR/AR experiences.
Other
789 stars 162 forks source link

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

Closed richyz closed 7 years ago

richyz commented 7 years ago

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 forGetRotation' and no extension method GetRotation' of typeUnityEngine.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 commented 7 years ago

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 commented 7 years ago

@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));
}
richyz commented 7 years ago

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