Skip to content

Commit 7b80c00

Browse files
committed
fix: normalizeRotations should return between -180deg to 180deg range
1 parent 9e46b77 commit 7b80c00

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ Set current camera position as the default position
656656

657657
#### `normalizeRotations()`
658658

659-
Normalize camera azimuth angle (horizontal rotation) between 0 and 360 degrees.
659+
Normalize camera azimuth angle (horizontal rotation) between -180 and 180 degrees.
660660
This is useful when you want to keep the azimuth angle normalized before calling methods like `.setLookAt()`, `.lerpLookAt()`, `.setTarget()`, `.setPosition()`, and `.reset()`.
661661

662662
This method returns the CameraControls instance itself, so you can chain it with other methods.

src/CameraControls.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,14 +2432,14 @@ export class CameraControls extends EventDispatcher {
24322432
}
24332433

24342434
/**
2435-
* Normalize camera azimuth angle (horizontal rotation) between 0 and 360 degrees.
2435+
* Normalize camera azimuth angle (horizontal rotation) between -180 and 180 degrees.
24362436
* @returns This CameraControls instance.
24372437
* @category Methods
24382438
*/
24392439
normalizeRotations(): CameraControls {
24402440

2441-
this._sphericalEnd.theta = this._sphericalEnd.theta % PI_2;
2442-
if ( this._sphericalEnd.theta < 0 ) this._sphericalEnd.theta += PI_2;
2441+
this._sphericalEnd.theta = ( ( this._sphericalEnd.theta % PI_2 ) + PI_2 ) % PI_2;
2442+
if ( this._sphericalEnd.theta > Math.PI ) this._sphericalEnd.theta -= PI_2;
24432443
this._spherical.theta += PI_2 * Math.round( ( this._sphericalEnd.theta - this._spherical.theta ) / PI_2 );
24442444

24452445
return this;

0 commit comments

Comments
 (0)