Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Correcting Orientation from external source (Oculus Rift)

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109

    Correcting Orientation from external source (Oculus Rift)

    Hello,

    So I have a weird issue with orientation when I am pulling orientation data from an external device, in this case the Oculus Rift.

    Essentially I can get the correct position without an issue but my orientation is screwed up such that either looking up means I am looking down in the OpenGL environment OR looking left means I am looking right in the environment.

    Obviously I would like it such that I am looking in the right direction at all times.

    So, here is my code example:

    Code auto:0:
    glm::mat4 BulletOrientationMatrix = glm::mat4(1.0f);
     
    ovrMatrix4f OculusRiftOrientation = OVR::Matrix4f(Current_HeadPose[EyeToCalculate].Orientation).Inverted();
     
    for (int o = 0; o < 4; o++) {
    	for (int i = 0; i < 4; i++) {
    		BulletOrientationMatrix[o][i] = OculusRiftOrientation.M[o][i];
    	}
    }
     
    AdjustedPitch += HorizontalAngle;
     
    HorizontalAngle = 0;
     
    BulletOrientationMatrix = glm::transpose(BulletOrientationMatrix);
     
    BulletOrientationMatrix = glm::rotate(BulletOrientationMatrix, AdjustedPitch, glm::vec3(0.0f, 1.0f, 0.0f));
    As you can see, I copy over the orientation data from the Rift's SDK and then do corrections on it.

    I am sure I am doing it in the wrong order or something; but I tried the code above with/without the inversion and vice versa with the "glm::transpose" call.

    Is there something that maybe someone else sees in the code above that I am doing wrong?

    Thank you for your time.
    Last edited by tmason; 09-10-2014 at 08:50 AM. Reason: grammar

  2. #2
    Junior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109
    OK, so an update on this;

    I have corrected most head movement with the following code but a minor issue remains; will ask below.

    Code auto:0:
    OculusToGLMMatrix = glm::mat4(1.0f);
     
    ovrMatrix4f OculusRiftOrientation = OVR::Matrix4f(Current_HeadPose[EyeToCalculate].Orientation);
     
    for (int o = 0; o < 4; o++) {
    	for (int i = 0; i < 4; i++) {
    		OculusToGLMMatrix[o][i] = OculusRiftOrientation.M[o][i];
    	}
    }
     
    /*
     
    The AdjustedPitch stays a certain value such that when the person moves their mouse the resultant rotation inside the
    3D environment is added/subtracted from the Adjusted pitch.
     
    In this way the person can rotate using the mouse and the Oculus Rift device freely.
     
    */
     
    AdjustedPitch += HorizontalAngle;
     
    HorizontalAngle *= CurrentMouseMovementSpeed * (*deltaTime);
     
    OculusToGLMMatrix = glm::transpose(OculusToGLMMatrix);
     
    /*
     
    Change the "handedness" of the rotation using the following Rotation Fix matrix.
     
    */
     
    GLfloat* RotationFixArray = new GLfloat[16] { 1.0f, 0.0f, 0.0f, 0.0f,
    		0.0f, 1.0f, 0.0f, 0.0f,
    		0.0f, 0.0f, -1.0f, 0.0f,
    		0.0f, 0.0f, 0.0f, 1.0f };
     
    glm::mat4 RotationFixOrientation = glm::make_mat4(RotationFixArray);
     
    OculusToGLMMatrix *= RotationFixOrientation;
     
    OculusToGLMMatrix = glm::rotate(OculusToGLMMatrix, AdjustedPitch, glm::vec3(0.0f, 1.0f, 0.0f));
     
    CurrentRightDirection = glm::vec3(OculusToGLMMatrix[0][0], OculusToGLMMatrix[1][0], OculusToGLMMatrix[2][0]);
     
    CurrentUpDirection = glm::vec3(OculusToGLMMatrix[0][1], OculusToGLMMatrix[1][1], OculusToGLMMatrix[2][1]);
     
    CurrentViewingDirection = glm::vec3(OculusToGLMMatrix[0][2], OculusToGLMMatrix[1][2], OculusToGLMMatrix[2][2]);
     
    /*
     
    View adjusted position is from prior calculations based on the position of the eyes and the position of the device relative to the computer.
     
    */
     
    CurrentCameraMatrix = glm::lookAt(ViewAdjustedPosition, ViewAdjustedPosition + CurrentViewingDirection, CurrentUpDirection);

    With the above code up/down and left/right 100% works.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109
    The problem with the above code is that head tilting is not working.

    The Oculus Rift tracks not just head movement but head tilting.

    Currently with the above code when you TILT your head left you tilt right and vice versa.

    Is there anything I can do to fix that based on what you see above?

    Thank you.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109
    The issue has been corrected via reworking the order in which I multiply the matrices...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •