Skip to content

Commit ae194d3

Browse files
mgermeriegchoqueux
authored andcommitted
fix(CameraUtils): the camera rotation animation take the shortest angle
1 parent 880c67d commit ae194d3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Utils/CameraUtils.js

+6
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ class CameraRig extends THREE.Object3D {
215215

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

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

0 commit comments

Comments
 (0)