02-27-2015 01:13 AM
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);
}
03-02-2015 03:29 AM
03-02-2015 07:34 AM
Matrix4f ovrOrientation = Matrix4f(Quatf(eyeRenderPose[eye].Orientation).Inverted());
03-02-2015 12:42 PM
"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.
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;