richtr / threeVR

An orientation-aware Virtual Reality controller for web browsers built on top of three.js
http://richtr.github.io/threeVR/examples/vr_basic.html
439 stars 97 forks source link

[Question] How to keep manual drag rotation on touchend? #10

Open carolinex opened 8 years ago

carolinex commented 8 years ago

Hello, I hope it is ok to post a question here.

In my application, I need to keep the rotation around Y axis when the user drags manually and releases on mobile, but I'm having problems understanding how to add the rotation difference using quaternions.

If I edit the updateDeviceMove on DeviceOrientationController.js to add the code below, it almost works... for vertical axis, but the others are messed up.

// this variable is a boolean flag set to true on touchend if( manuallyMoved) { objY = rotation.setFromQuaternion( objQuat, 'YXZ' ).y; realY = rotation.setFromQuaternion( deviceQuat, 'YXZ' ).y; manQuat = new THREE.Quaternion().setFromAxisAngle( new THREE.Vector3(0,1,0), (objY - realY) ); deviceQuat.multiply( manQuat ); manuallyMoved = false; }else{ deviceQuat.multiply( manQuat ); this.object.quaternion.slerp( deviceQuat, 0.07 ); } //this.object.quaternion.slerp( deviceQuat, 0.07 ); // smoothing //this.object.quaternion.copy( deviceQuat );

I put together a very basic example for testing. It's here: http://ec2-54-207-23-212.sa-east-1.compute.amazonaws.com/tests/360/

Can somebody point me in the right direction? Thanks.

liuxiaoyue commented 8 years ago

Hello, this problem can you solve it, can you give suggestions? thanks

carolinex commented 8 years ago

Because I had some urgency I gave up on threeVR, and used the standard DeviceOrientationControls.js from ThreeJS adding a button to switch mode to orbitControls. Not the best UX but it was what I could do at the moment. I think it's only a matter of understanding the math though, quaternions are not for the uninitiated...

liuxiaoyue commented 8 years ago

@carolinex thanks! I try to solve this problem,i find that updateDevice and updateManual functions are modified camera quaternion, i want to handle quaternion,use slerp, but updateDevice is failured,@richtr ,can you give suggestions? thanks....

tristangemus commented 7 years ago

+1 for this

TommyySin commented 5 years ago

+1 Anyone got something close?