Skip to content

setTarget doesn't respect azimuthAngle bounds #575

@UX3D-becher

Description

@UX3D-becher

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions