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
437 stars 99 forks source link

Set min and max angles for camera #13

Open Carpetfizz opened 8 years ago

Carpetfizz commented 8 years ago

It would be great if there was an API to set max and min horizontal and vertical rotation. For example, if I wanted my camera to rotate from [Math.PI, 0] on the y-axis. Orbit Controls has the ability to camera.minPolarAngle or camera.maxAzimuthAngle

ob6160 commented 8 years ago

Out of curiosity has anyone managed to solve this issue?

Carpetfizz commented 8 years ago

@ob6160 I didn't actually, I just changed my application to get around the issue, which wasn't the best solution

ob6160 commented 8 years ago

If I knew more maths than I did I'd have a go at solving this haha

Carpetfizz commented 8 years ago

@ob6160 haha same, I haven't taken linear algebra yet :stuck_out_tongue:

ob6160 commented 8 years ago

I found a solution which works for me :)

After the quaternion has been set, to limit the rotation of the camera on either side I just ran this:

this.object.rotation.y = Math.min(Math.max(this.object.rotation.y, -Math.PI*0.5), Math.PI*0.5);