I'm trying to use Tween in my WebGL project ( http://eyesonmars.com/ ) to move the to a new position smoothly. However, I haven't yet been able to get Tween to work for me.
Instead of Tweening the value of the camera.position.x from -3 to -10 over a period of 3 seconds it simply sends the camera's position to x=-3 and does not continue. I have also confirmed that the Tween object believes it has completed it's task by having Tween's .onComplete() pop up an alert (I have since removed that alert so it is not in the current code).
Here is the code I'm using and it can be found at http://eyesonmars.com/libs/EOM_Utils.js
function zoomOutCamera()
{
var position, target;
// app.camera.position.z = 10;
position = -3.0;
target = -10.0;
myTween = new TWEEN.Tween(position).to(target, 3000);
myTween.onUpdate(function(){
// alert(position);
app.camera.position.x = position;
});
// myTween.onComplete(bananaphone(position));
myTween.start();
}
function myAnimate()
{
if(!myTween.onComplete())
{
requestAnimationFrame( myAnimate);
}
myTween.update();
}
Below I've summarized how I am testing the code and what should've been happening according to what I think I know.
What IS happening: Typed into browsers JavaScript console:
input: camera.position.x
output: 0.5
input: myAnimate()
output: undefined
input: camera.position.x
output: -3
What SHOULD happen (according to me): Typed into browsers JavaScript console:
input: camera.position.x
output: 0.5
input: myAnimate()
output: undefined
input: camera.position.x
output: -10
I have tried different variations of the tween and also researched solutions online and my O'Reilly book. I'm glad to hear any suggestions for how I can post my question more accurately.
Thank you in advance for any help you can provide.