Skip to content

Commit

Permalink
fix(CameraUtils): the camera rotation animation take the shortest angle
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermerie authored and gchoqueux committed May 17, 2021
1 parent 880c67d commit ae194d3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Utils/CameraUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ class CameraRig extends THREE.Object3D {

this.addPlaceTargetOnGround(view, camera, params.coord, factor);
this.end.applyParams(view, params);
// compute the angle along z-axis between the starting position and the end position
const difference = this.end.target.rotation.z - this.start.target.rotation.z;
// if that angle is superior to 180°, recompute the rotation as the complementary angle.
if (Math.abs(difference) > Math.PI) {
this.end.target.rotation.z = this.start.target.rotation.z + difference - Math.sign(difference) * 2 * Math.PI;
}

animations.push(new TWEEN.Tween(factor, tweenGroup).to({ t: 1 }, time)
.easing(params.easing)
Expand Down

0 comments on commit ae194d3

Please sign in to comment.