cancel
Showing results for 
Search instead for 
Did you mean: 

Looking left actually looks Right vice versa OpenGL

EpicZa
Honored Guest
Im close, so close! But looking left actually looks right! I tried taking out the .inverted but that just means that look up/down are the wrong way round, I tried computing the up vector from the cross of the right and direction vectors, but same thing. I know its to do with my up vector I just can't figure out how to fix it!

Any help appreciated.

for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++)
{

ovrEyeType eye = hmd->EyeRenderOrder[eyeIndex];
eyeRenderPose[eye] = ovrHmd_GetHmdPosePerEye(hmd, eye);

//Get Projection and ModelView matrici from SDK..
Matrix4f ovrProjection = Matrix4f(ovrMatrix4f_Projection(eyeRenderDesc[eye].Fov, 0.01f, 100.0f, true));
glm::mat4 glmProjection = fromOvr(ovrProjection);

//Translate for specific eye..
Matrix4f ovrTranslatEyeViewOffSet = Matrix4f::Translation(eyeRenderDesc[eye].HmdToEyeViewOffset);
glm::mat4 glmTranslatEyeViewOffSet = fromOvr(ovrTranslatEyeViewOffSet);

Matrix4f ovrOrientation = Matrix4f(Quatf(eyeRenderPose[eye].Orientation).Inverted());
glm::mat4 glmOrientation = fromOvr(ovrOrientation);

Matrix4f ovrTranslatEyeRenderPos = Matrix4f::Translation(-Vector3f(eyeRenderPose[eye].Position));
glm::mat4 glmTranslatEyeRenderPos = fromOvr(ovrTranslatEyeRenderPos);

glm::vec3 AdjustedPosition = glm::vec3(glmTranslatEyeRenderPos[3]);

AdjustedPosition += glm::vec3(glmTranslatEyeRenderPos[3]);


//Not currently using
glm::vec3 CurrentRightDirection = glm::vec3(glmOrientation[0][0], glmOrientation[0][1], glmOrientation[0][2]);


glm::vec3 CurrentUpDirection = glm::vec3(glmOrientation[1][0], glmOrientation[1][1], glmOrientation[1][2]);


glm::vec3 CurrentViewingDirection = glm::vec3(glmOrientation[2][0], glmOrientation[2][1], glmOrientation[2][2]);

//Camera Matrix
glm::mat4 glmView = glm::lookAt(
AdjustedPosition,
AjdustedPosition + CurrentViewingDirection,
CurrentUpDirection
);

glm::mat4 MVP = glmProjection * glmTranslatEyeViewOffSet * glmView * glm::mat4(1.0f);

glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);

glBindVertexArray(VertexArrayCube);


glViewport(eyeRenderViewport[eye].Pos.x, eyeRenderViewport[eye].Pos.y, eyeRenderViewport[eye].Size.w, eyeRenderViewport[eye].Size.h);

glDrawArrays(GL_TRIANGLES, 0, 12 * 3);

}


EDIT: (Changed code to add translations of HMD) Then also noticed that the up/down translation of the oculus along the y axis are inverted too, so raising the oculus to the roof actually lowers the view in the scene.
3 REPLIES 3

EpicZa
Honored Guest
Bump, anyone point me in the right direction?

kojack
MVP
MVP
Matrix4f  ovrOrientation            = Matrix4f(Quatf(eyeRenderPose[eye].Orientation).Inverted());

Why are you inverting the orientation of each eye pose? That would make it look in the opposite direction.

EpicZa
Honored Guest
"kojack" wrote:
Matrix4f  ovrOrientation            = Matrix4f(Quatf(eyeRenderPose[eye].Orientation).Inverted());

Why are you inverting the orientation of each eye pose? That would make it look in the opposite direction.


Ok I was doing it to reduce my problems from two to one axis'. But you got me thinking and here is what i've done now:

			Matrix4f  ovrOrientation            = Matrix4f(Quatf(eyeRenderPose[eye].Orientation));// .Inverted();
glm::mat4 glmOrientation = fromOvr(ovrOrientation);

glm::mat4 invertOrientation = glm::mat4{ -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 };

glmOrientation = glmOrientation * invertOrientation;


Rotations all work perfectly, just have to sort out the translations.

Cheerss!