Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set the first lookAt/target of a Control

I need to set the initial 'lookAt' point of the scene, that will be the center of the screen and of the control's rotation. If possible, I would prefer to set a point (or an object's position), not rotation angles.

The control is OrbitControl. If I simply set lookAt before the Control initialization, the center is restored to (0,0,0) on the first user interaction, which causes a 'gap' ...

// camera
camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 0.1, 20000);
camera.position.set(0,20,20);
camera.lookAt(new THREE.Vector3(0,10,0));

// controls
controls = new THREE.OrbitControls( camera );
controls.addEventListener( 'change', render );

How can I set the initial point in a proper way?

like image 989
jeum Avatar asked Jan 05 '14 11:01

jeum


2 Answers

Try setting the control's target and remove the camera.lookAt call:

controls.target = new THREE.Vector3(0, 10, 0);
controls.update();
like image 72
Bjarte Haram Avatar answered Nov 11 '22 06:11

Bjarte Haram


Or more directly : controls.target.set(0, 10, 0);

like image 42
jeum Avatar answered Nov 11 '22 06:11

jeum