Skip to content

Orbit Controls: Issue clamping theta/azimuth when min == max #20627

@luna-magicad

Description

@luna-magicad

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:

  1. Have a camera with position const position = new Vector3(0.08933252424548495, 0.012991545009608613, 9.693299999994998)

  2. Set controls.minAzimuth = 0 // This could be anything between 0 -> 1.0218421804140996

  3. Set controls.maxAzimuth = 0

  4. Set the controls.target = new Vector3(-0.5014164999999999, 0.012999999999999984, -0.3067)

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

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