# what function creates rotation effect in three.js?

which part of the code is responsible for the rotation in this example? Is it the camera or the scene itself?

http://threejs.org/examples/#canvas_camera_orthographic

in the render function, you have

function render() {

var timer = Date.now() * 0.0001;

camera.position.x = Math.cos( timer ) * 200;
camera.position.z = Math.sin( timer ) * 200;
camera.lookAt( scene.position );

renderer.render( scene, camera );

}


That makes the camera take a circular path of radius 200 , always looking at the center of the scene

• all this should be in a rotate function or something.. var timer = Date.now() * 0.0001; camera.position.x = Math.cos( timer ) * 200; camera.position.z = Math.sin( timer ) * 200; Jun 7, 2014 at 17:37
• Yes, it would have been more clean in a function. May be the apropiate name would be updateCameraPosition
– vals
Jun 9, 2014 at 16:47
• Why not rotate the object at the center of the scene instead of rotating the camera? I'm just wondering because when you rotate the camera you loose lighting positions, etc since they are not constrained to the camera position. Jul 21, 2016 at 22:33
• How would I adjust this to make a quick succession of short rotations, just to give the object the appearance of a short "wiggle". We want to catch the user's eye. I'm thinking we would issue a series of positions and lookAt commands with a timeout in between, but I haven't been able to make it work. Aug 5, 2016 at 21:04

According to the source they call the render method and it simply updates the camera position and uses camera.lookAt() to calculate the matrix to look at the center.

• I was thinking the same thing, but could you be more specific about where that happens? Jun 2, 2014 at 4:43