Question:
For research purposes, I'm trying to lock the global camera yaw in VR -- though, the "how" is more of a 3D math question and has little to do with VR. The user is in control of the orientation of the headset, but I want to take control of the global yaw. To illustrate the movement the user is allowed:
What I've tried:
I've a number approaches, but so far each one has ended up distorting the camera's orientation in some way. My most recent attempt sets the euler y component of both global last/current head rotations to any arbitrary, but same, value so delta yaw between them is always 0. But, the result is weird looping behavior in the same global area -- irrespective of where yaw first locked -- while rotating my head in a straight line.
Edit: It appears as the global yaw approaches 180, it flips. With global pitch=0, this happens instantly at 180, but with non-zero values of pitch it starts earlier and the flip happens over time. Here is a clip that illustrates this behavior.
Implementation of this approach (in pseudo-code, as I'm not using a well-known development platform/API):
var lastWorldOrientation = getHMDOrientation();//This method returns world space orientation
var displayedOrientation = lastWorldOrientation;
void Update() {
var nowWorldOrientation = getHMDOrientation();
var delta;
if (lockedYaw) { //null if not locked, else float with value yaw locked to
var tempLast = lastWorldOrientation;
var tempNow = nowWorldOrientation;
tempLast.eulerAngles.y = lockedYaw;
tempNow.eulerAngles.y = lockedYaw;
delta = tempLast:toObjectSpace(tempNow);
} else {
delta = lastWorldOrientation:toObjectSpace(nowWorldOrientation);
}
lastWorldOrientation = nowWorldOrientation;
displayedOrientation = displayedOrientation * delta;
camera.rotation = displayedOrientation;
}
While all of my attempts have been manipulating the euler angles of the HMD / camera rotations, I also have the ability to manipulate and read them in quaternion or matrix form. Any ideas why the current approach I'm using experiences the distortion it does, and how I can lock the global yaw of the camera without interfering with the other two axes?