setTarget doesn't respect azimuthAngle bounds
Describe the bug
With minAzumuthAngle set to a negative value and maxAzimuthAngle set to a positive value (< pi), setTarget (and more specifically normalizeRotations) results in an azimuthAngle that doesn't respect the bounds and eventually leads to a jumping motion whenever the bounds are enforced (e.g. after user input)
Based on this bug report, I could submit a pull request that would fix the issue according to my understanding of the problem. As I'm otherwise unfamiliar with the codebase I might do more damage than good, and would therefore first like to get the maintainers' opinion.
My proposed fixes:
- Don't apply normalizeRotations in
setTargetor - Change normalizeRotations to return values between
minAzimuthAngleandmaxAzimuthAngle. This would also affectsetLookAt
To Reproduce
- Set bounds for the
azimuthAngle, min has to be negative
cameraControls.minAzimuthAngle = THREE.MathUtils.degToRad(-90);
cameraControls.maxAzimuthAngle = THREE.MathUtils.degToRad(90);
- Reach a state of a negative
azimuthAngle(e.g. with user input)
cameraControls.azimuthAngle = THREE.MathUtils.degToRad(-45);
- At some point call
setTarget, which will callnormalizeRotationsinternally
cameraControls.setTarget(0, 0, 0);
-
normalizeRotations erroneously sets azimuthAngle to a value outside the specified bounds
-
any input to controls (e.g. mouse orbit) will cause the bounds to be enforced, leading to a jumping motion
Code
Live example
https://playcode.io/2397871
Expected behavior
Calling setTarget should not result in an azimuthAngle that is outside minAzimuthAngle and maxAzimuthAngle when called from a valid state (i.e., azimuthAngle being within minAzimuthAngle and maxAzimuthAngle)
Screenshots or Video
No response
Device
No response
OS
No response
Browser
No response
Anyone in need of a quick workaround might want to take a look at setOrbitPoint
Thank you for reporting this issue and offering to submit a PR.
Regarding setTarget and the other camera-positioning methods, these functions move the camera (or the target) to the specified coordinates.
As I understand it, to reach those coordinates, the methods have to ignore the angle limits.
Although this might not be the desired behavior...
Alternatively, we could choose to throw an error when the requested position is out of bounds.
What do you think?