Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
tmason101's avatar
tmason101
Honored Guest
11 years ago

View Matricies Off for Eye, Simple Fix?

Hello,

I have a simple cube I am rendering using OpenGL,GLM, Qt (5.3), and the DK1.

Simply put, the left eye is off but the right eye renders fine.

I hope the image and code below makes sense; essentially the left eye's rotation/position is all over the place while the right eye renders correctly.

What am I doing wrong?

Thank you for your time:


void QTOculusRiftWindow::drawOculusRift() {

ovrFrameTiming Current_Frame = ovrHmd_BeginFrame(Main_HMD, Main_HMD_FrameIndex);

static ovrPosef Main_HMD_eyeRenderPose[2];
static ovrMatrix4f OculusRiftProjection[2];
static ovrMatrix4f OculusRiftView[2];
static OVR::Vector3f Main_HMD_HeadPos(0.0f, 1.6f, -5.0f);
static ovrTrackingState HmdState;

ovrVector3f hmdToEyeViewOffset[2] = { Main_EyeRenderDesc[0].HmdToEyeViewOffset, Main_EyeRenderDesc[1].HmdToEyeViewOffset };
ovrHmd_GetEyePoses(Main_HMD, Main_HMD_FrameIndex, hmdToEyeViewOffset, Main_HMD_eyeRenderPose, &HmdState);

Main_HMD_HeadPos.y = ovrHmd_GetFloat(Main_HMD, OVR_KEY_EYE_HEIGHT, Main_HMD_HeadPos.y);

glBindFramebuffer(GL_FRAMEBUFFER, OculusRiftFrameBufferID);

glUseProgram(MainOpenGLShaderProgramID);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

for (auto & C : Cubes) {

if (RotateCubes) {

C.RotateMe(RotationSpeed * RotateDirection);

}

}

for (GLint CurrentEyeIndex = 0; CurrentEyeIndex < ovrEye_Count; ++CurrentEyeIndex)
{

ovrEyeType CurrentEye = Main_HMD->EyeRenderOrder[CurrentEyeIndex];

glViewport(
Main_EyeTexture[CurrentEyeIndex].Texture.Header.RenderViewport.Pos.x,
Main_EyeTexture[CurrentEyeIndex].Texture.Header.RenderViewport.Pos.y,
Main_EyeTexture[CurrentEyeIndex].Texture.Header.RenderViewport.Size.w,
Main_EyeTexture[CurrentEyeIndex].Texture.Header.RenderViewport.Size.h
);

OculusRiftProjection[CurrentEyeIndex] = ovrMatrix4f_Projection(Main_EyeRenderDesc[CurrentEyeIndex].Fov,
1.0f, 1000.0f, true);

for (int o = 0; o < 4; o++) {
for (int i = 0; i < 4; i++) {
ProjectionMatrix[o][i] = OculusRiftProjection[CurrentEyeIndex].M[o][i];
}
}

ProjectionMatrix = glm::transpose(ProjectionMatrix);

CenterPositionMatrix = glm::translate(glm::mat4(1.0f),
-glm::vec3(Main_HMD_eyeRenderPose[CurrentEyeIndex].Position.x,
Main_HMD_eyeRenderPose[CurrentEyeIndex].Position.y,
Main_HMD_eyeRenderPose[CurrentEyeIndex].Position.z));

EyeOrientationMatrix = glm::toMat4(glm::quat(
Main_HMD_eyeRenderPose[CurrentEyeIndex].Orientation.w,
-Main_HMD_eyeRenderPose[CurrentEyeIndex].Orientation.x,
-Main_HMD_eyeRenderPose[CurrentEyeIndex].Orientation.y,
-Main_HMD_eyeRenderPose[CurrentEyeIndex].Orientation.z
));

EyePositionMatrix = glm::translate(glm::mat4(1.0f),
glm::vec3(
Main_EyeRenderDesc[CurrentEyeIndex].HmdToEyeViewOffset.x,
Main_EyeRenderDesc[CurrentEyeIndex].HmdToEyeViewOffset.y,
Main_EyeRenderDesc[CurrentEyeIndex].HmdToEyeViewOffset.z
));

ViewMatrix = EyePositionMatrix * EyeOrientationMatrix * CenterPositionMatrix;

for (auto & C : Cubes) {

C.DrawMe();

}

}

ovrHmd_EndFrame(Main_HMD, Main_HMD_eyeRenderPose, &Main_EyeTexture[0].Texture);

Main_HMD_FrameIndex += 1;

}


1 Reply

  • When you call ovrHmd_GetEyePoses and pass in the eye offsets, it automatically applies those offsets to the poses you get back. By creating an additional eye position matrix you're basically applying the offsets twice.

    Also, based on the image it looks like you may be misapplying the pose matrix. Remember that when you're applying it to the modelview matrix, you want the inverse of the head pose. I'm not sure your negations are actually going to accomplish that the way you expect, but I could be wrong.

    If you look here you'll find a bunch of convenience methods to convert from the OVR types directly to the corresponding GLM types, including one that takes as input an ovrPosef and returns a glm::mat4. Take the inverse of that any you can apply it to the modelview stack.