Head Rotation in Opposite Direction with GLM and Oculus Rift SDK
Posted
by
user3434662
on Stack Overflow
See other posts from Stack Overflow
or by user3434662
Published on 2014-05-27T23:45:00Z
Indexed on
2014/05/28
15:27 UTC
Read the original article
Hit count: 287
I am 90% there in getting orientation to work.
I am just trying to resolve one last bit and I hope someone can point me to any easy errors I am making but not seeing.
My code works except when a person looks left the camera actually rotates right. Vice versa with looking right, camera rotates left.
Any idea what I am doing wrong here?
I retrieve the orientation from the Oculus Rift like so:
OVR::Quatf OculusRiftOrientation = PredictedPose.Orientation;
glm::vec3 CurrentEulerAngles;
glm::quat CurrentOrientation;
OculusRiftOrientation.GetEulerAngles<OVR::Axis_X, OVR::Axis_Y, OVR::Axis_Z,
OVR::Rotate_CW, OVR::Handed_R>
(&CurrentEulerAngles.x, &CurrentEulerAngles.y, &CurrentEulerAngles.z);
CurrentOrientation = glm::quat(CurrentEulerAngles);
And here is how I calculate the LookAt:
/*
DirectionOfWhereCameraIsFacing is calculated from mouse and standing position so that you are not constantly rotating after you move your head.
*/
glm::vec3 DirectionOfWhereCameraIsFacing;
glm::vec3 RiftDirectionOfWhereCameraIsFacing;
glm::vec3 RiftCenterOfWhatIsBeingLookedAt;
glm::vec3 PositionOfEyesOfPerson;
glm::vec3 CenterOfWhatIsBeingLookedAt;
glm::vec3 CameraPositionDelta;
RiftDirectionOfWhereCameraIsFacing = DirectionOfWhereCameraIsFacing;
RiftDirectionOfWhereCameraIsFacing = glm::rotate(CurrentOrientation, DirectionOfWhereCameraIsFacing);
PositionOfEyesOfPerson += CameraPositionDelta;
CenterOfWhatIsBeingLookedAt = PositionOfEyesOfPerson + DirectionOfWhereCameraIsFacing * 1.0f;
RiftCenterOfWhatIsBeingLookedAt = PositionOfEyesOfPerson + RiftDirectionOfWhereCameraIsFacing * 1.0f;
RiftView = glm::lookAt(PositionOfEyesOfPerson, RiftCenterOfWhatIsBeingLookedAt, DirectionOfUpForPerson);
© Stack Overflow or respective owner