private animateCamera()

in src/globemap.ts [1302:1351]


        private animateCamera(to: THREE.Vector3, done?: Function) {
            this.hideTooltip();

            if (!this.camera) {
                return;
            }

            cancelAnimationFrame(this.cameraAnimationFrameId);
            const startTime: number = Date.now();
            const duration: number = this.GlobeSettings.cameraAnimDuration;
            const endTime: number = startTime + duration;
            const startPos: THREE.Vector3 = this.camera.position.clone().normalize();
            const endPos: THREE.Vector3 = to.clone().normalize();
            const length: number = this.camera.position.length();
            const alpha: number = 2;
            const beta: number = 1.9;
            const easeInOutQuint = (t) => {
                if (t < alpha) {
                    return beta * t * t * t * t * t;
                }
                return 1 + beta * (--t) * t * t * t * t;
            };

            const onUpdate: FrameRequestCallback = () => {
                const now: number = Date.now();
                let t: number = (now - startTime) / duration;
                if (t > alpha) {
                    t = alpha;
                }
                t = easeInOutQuint(t);

                const pos: THREE.Vector3 = new THREE.Vector3()
                    .add(startPos.clone().multiplyScalar(alpha - t))
                    .add(endPos.clone().multiplyScalar(t))
                    .normalize()
                    .multiplyScalar(length);

                this.camera.position.set(pos.x, pos.y, pos.z);

                if (now < endTime) {
                    this.cameraAnimationFrameId = requestAnimationFrame(onUpdate);
                } else if (done) {
                    done();
                }

                this.needsRender = true;
            };

            this.cameraAnimationFrameId = requestAnimationFrame(onUpdate);
        }