Jump to content

tween rotate a camera in three.js


rockfish
 Share

Recommended Posts

I'm trying to develop a globe in three.js. Pretty much got everything I want working but I'm have trouble getting a camera to rotate from one position to another when I click a button. I know that the cordinates are correct because if I use some simple code the camera jumps to the new position when I do this

 

camera.position.set(posX,posY,posZ);
camera.lookAt(new THREE.Vector3(0,0,0));

 

So give that my destination is correct I struggling to understand why the following function that uses tween.js doesn't work. I'd appreciate any help as I'm really struggling with this

 

var from = {
x : camera.position.x,
y : camera.position.y,
z : camera.position.z
};

var to = {
x : posX,
y : posY,
z : posZ
};
var tween = new TWEEN.Tween(from)
.to(to,600)
.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();

 

Many thanks

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...