Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  58] [ 3]  / answers: 1 / hits: 27774  / 12 Years ago, wed, april 25, 2012, 12:00:00

In Three.js, I want a camera to be pointed at a point in 3D space.



For this purpose, I tried using the camera.lookAt function like so:



camera.lookAt(new THREE.Vector3(-100,-100,0));


However, I found out that the call has no effect whatsoever. It just does nothing at all. I tried changing the numbers in the vector, and I always get the same look on screen, when it should be changing.



I just found now that if I remove the THREE.TrackballControls I have in my code, the camera.lookAt() works as it should. Is there something wrong with how I use THREE.TrackballControls? This is how I initialize them:



    controls = new THREE.TrackballControls( camera, renderer.domElement );

controls.rotateSpeed = 10.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.2;

controls.noZoom = false;
controls.noPan = false;

controls.staticMoving = true;
controls.dynamicDampingFactor = 1.0;

var radius = 5;
controls.minDistance = radius * 1.1;
controls.maxDistance = radius * 100;

controls.keys = [ 65, 83, 68 ]; // [ rotateKey, zoomKey, panKey ]*/


And then in my render function I do:



function render() {
controls.update();
renderer.render(scene, camera);
}


Documentation on Three.js is pretty scarce, so I thought I'd ask here. Am I doing something wrong?


More From » macos

 Answers
85

Looking at the source code of THREE.TrackballControls, I figured out that I can make the camera look where I want by setting trackballControls.target to the THREE.Vector3 I want it to look at, and then rerendering the scene.


[#85971] Wednesday, April 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leog

Total Points: 225
Total Questions: 113
Total Answers: 118

Location: Oman
Member since Wed, Apr 12, 2023
1 Year ago
;