Hey there, I'm working on a tricky exercise involving setting up a camera and cube with THREE.js. The goal is to maintain the cube's initial ratio while ensuring the camera is focused on the center of the cube. Although I believe I've successfully implemented an isometric projection, I'm struggling to figure out how to direct the camera towards the center.
Here are my attempts so far:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Cube</title>
<style>
</style>
</head>
<body>
<script src="js/three.min.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.OrthographicCamera(-3,3,3,-3, 0, 100);
var ambientLight = new THREE.AmbientLight(0x222222);
scene.add(ambientLight);
var light = new THREE.PointLight( 0xffffff );
light.position.set(-10, 10, 10);
scene.add(light);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(800,800);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.BoxGeometry(1,1,1);
var cube = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial( { color: 0x00ffff }));
scene.add( cube );
function render() { //this is to be used for animation later
requestAnimationFrame(render);
camera.position.x=1;
camera.position.y=1;
camera.position.z=1;
camera.lookAt(new THREE.Vector3(0,0,0));
renderer.render( scene, camera);
}
render();
</script>