Sign in to follow this  

Simple Rotation Question...

Recommended Posts

tmason    326


Thanks to various members of the forum here I am 90% there. Thank you.

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? Thank you.


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);

Thank you for any help you can provide for this last piece.

Share this post

Link to post
Share on other sites
JohnnyCode    1046



DirectionOfWhereCameraIsFacing is calculated from mouse....



You have a constant 2d vector you subtract from volatile mouse 2d position- very likely. Just change the order of subtraction on the X component, it will inverse mouse horizontaly. Do not change the routine


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this