Reputation: 2817
I'm wondering if anyone has an idea on how to rotate a camera so the camera faces directly above a point on the sphere.
UPDATE
Radio's answer is correct. After some debugging it looks like my coordinates were reversed.
Upvotes: 0
Views: 1305
Reputation: 2853
I have created a fiddle: http://jsfiddle.net/kbtn6pz5/
This moves the camera over a random point on the sphere, applies a lookAt property and then sets the altitude of the camera over the sphere's surface.
Based on the fiddle boilerplate...
var camera, scene, renderer, geometry, material, mesh;
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 10000);
scene.add(camera);
var rad = 200;
geometry = new THREE.SphereGeometry( rad, 32, 32 );
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
var point = THREE.GeometryUtils.randomPointsInGeometry( geometry, 1 );
var altitude = 100;
var coeff = 1+ altitude/rad;
camera.position.x = point[0].x * coeff;
camera.position.y = point[0].y * coeff;
camera.position.z = point[0].z * coeff;
camera.lookAt(mesh.position);
renderer = new THREE.CanvasRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
}
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
renderer.render(scene, camera);
}
Upvotes: 2