Forum Discussion
tmason101
11 years agoHonored Guest
Just to update the thread, thanks to the help from vrdaveb up/down and left/right head movement is fine with the following code:
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);
Related Content
- 19 days ago
- 4 years ago
- 14 days ago
- 4 months ago