-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Description
Describe the bug
I was adding animation to an orbit controls and I noticed that it was rotating the camera around the an despite me having set the min & max azimuth to the same value. And when digging through the source code I found out that the value isn't clamped between min & max if min < max.
To Reproduce
Steps to reproduce the behavior:
-
Have a camera with position
const position = new Vector3(0.08933252424548495, 0.012991545009608613, 9.693299999994998) -
Set controls.minAzimuth = 0 // This could be anything between 0 -> 1.0218421804140996
-
Set controls.maxAzimuth = 0
-
Set the
controls.target = new Vector3(-0.5014164999999999, 0.012999999999999984, -0.3067) -
controls.update()
Code
The line that I found to be the culprit is this one and should be min <= max
https://github.com/mrdoob/three.js/blob/dev/examples/jsm/controls/OrbitControls.js#L186
I think alternatively it could be done next to this line:
spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
Live example
Broken example:
https://codepen.io/luna_magicad/pen/rNLrGdv
Fixed example:
https://luna-magicad.github.io/three-js-playground/orbit-controls-bug-fixed.html
Expected behavior
I expect that if minAzimuth == maxAzimuth then the value won't change.
Platform:
- Device: Desktop
- OS: Windows, MacOS, Linux, Android, iOS
- Browser: Chrome, Firefox
- Three.js version: r122, dev, probably many older versions.