benvanik/vr.js

Keyboard Movement Does Not Follow Direction You Are Facing

Opened this issue · 3 comments

I've noticed in the "Three.js Floating Boxes Demo" that your perspective follows the oculus rift, but movement with the keyboard does not. So, for instance, when you first open the demo if you don't move your head, UP on the keyboard will move you forward, but if you rotate your head to the left or right, UP on the keyboard still moves the same direction even though you are facing a different direction. This should work similar to the Three.js Pointer Lock Demo http://threejs.org/examples/#misc_controls_pointerlock where UP on the keyboard will move you in the direction you are facing.

That is very arguable point, as a lot of players prefer independent movement direction from view direction.
Same way as in real life you are able to walk forward and by turning your head to the right wont change direction of your movement.

If I want the movement as @wlindner described, what should I do to achieve that?

I tried to cooperate the original PointerLockerControl.js method, adding back pitchObject and yawObject, as below
......
pitchObject.add( camera );
.......
yawObject.add( pitchObject );
.......

and in update() function, adding
.......
var qq = new THREE.Quaternion(vrstate.hmd.rotation[0], vrstate.hmd.rotation[1], vrstate.hmd.rotation[2], vrstate.hmd.rotation[3]);
var roTemp = new THREE.Object3D();
roTemp.rotation.setFromQuaternion( qq );
yawObject.rotation.y = roTemp.rotation.y;
.....

but it doesn't really work. I guess I messed it up with the OculusRiftEffect.js, thus view doesn't really follow the oculus(0 and 360 degree the same, but weird transition between), and the movement doesn't 100% follow the rotation as well. Does anyone know the right way to do this? Sorry for the awful description and hope it makes sense.. Thanks!

Ohhh I found the solution :D

@OculusRiftControls.js
I) Use the PointerLockerControl.js method, with pitchObject and yawObject.
2) Update yawObject.rotation with vrstate.hmd.rotation in undate()

@OculusRiftEffect.js
3) Command out "eyeWorldMatrix.multiply(rotMat);" in THREE.OculusRiftEffect.prototype.render()

see the changes of OculusRiftControls.js here http://jsfiddle.net/jhclaura/abnjvfyc/