camera-controls icon indicating copy to clipboard operation
camera-controls copied to clipboard

setTarget doesn't respect azimuthAngle bounds

Open mobecher opened this issue 1 year ago • 2 comments

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 setTarget or
  • Change normalizeRotations to return values between minAzimuthAngle and maxAzimuthAngle. This would also affect setLookAt

To Reproduce

  1. Set bounds for the azimuthAngle, min has to be negative
cameraControls.minAzimuthAngle = THREE.MathUtils.degToRad(-90);
cameraControls.maxAzimuthAngle = THREE.MathUtils.degToRad(90);
  1. Reach a state of a negative azimuthAngle (e.g. with user input)
cameraControls.azimuthAngle = THREE.MathUtils.degToRad(-45);
  1. At some point call setTarget, which will call normalizeRotations internally
cameraControls.setTarget(0, 0, 0);
  1. normalizeRotations erroneously sets azimuthAngle to a value outside the specified bounds

  2. 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

mobecher avatar May 25 '25 23:05 mobecher

Anyone in need of a quick workaround might want to take a look at setOrbitPoint

mobecher avatar May 25 '25 23:05 mobecher

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?

yomotsu avatar Jun 15 '25 16:06 yomotsu