Im trying to Tween the camera movement from one to another place but i can't seem to work it out. Im using the Globe from Chrome Experiments and added this function on it
function changeCountry(lat,lng){
var phi = (90 - lat) * Math.PI / 180;
var theta = (180 - lng) * Math.PI / 180;
var from = {
x : camera.position.x,
y : camera.position.y,
z : distance
};
var to = {
posX : 200 * Math.sin(phi) * Math.cos(theta),
posY : 200 * Math.cos(phi),
posZ : distance
};
var tween = new TWEEN.Tween(from)
.to(to,2000)
.easing(TWEEN.Easing.Linear.None)
.onUpdate(function () {
camera.position.set(this.x, this.y, this.z);
camera.lookAt(new THREE.Vector3(0,0,0));
})
.onComplete(function () {
camera.lookAt(new THREE.Vector3(0,0,0));
})
.start();
console.log(to,from,lat,lng);}
I've console printed the values and it all works perfectly with getting the lat&long and converting them to the right values, also the x,y,z values are great but it just don't move the camera at all. In console i get this errors:
Uncaught TypeError: n is not a function
,
90Tween.js:4 Uncaught TypeError: is not a function
&
419Tween.js:4 Uncaught TypeError: is not a function
and the last endlessly counts ++.
If anyone can help me sort it out it would be from a lot of help.
edit: I fixed the error with replacing .easing(TWEEN.Easing.Linear.None)
with
.easing(TWEEN.Easing.Linear.EaseNone)
.
However the camera does irregular movement - always the same and then goes back to the normal position before the animation. When playing with TWEEN.update()
in my render() function i get different results but none of them works as it should.
The render() function is like this:
zoom(curZoomSpeed);
rotation.x += (target.x - rotation.x) * 0.1;
rotation.y += (target.y - rotation.y) * 0.1;
distance += (distanceTarget - distance) * 0.3;
camera.position.x = distance * Math.sin(rotation.x) * Math.cos(rotation.y);
camera.position.y = distance * Math.sin(rotation.y);
camera.position.z = distance * Math.cos(rotation.x) * Math.cos(rotation.y);
camera.lookAt(mesh.position);
TWEEN.update();
renderer.render(scene, camera);