Camera Position and Lookat

Hi, I am new to Three JS. I want to know a simple thing(for you), a visual.explanation would be much appreciated. Lets say I have a 3D cube in my scene. Since its a 3D cube it has 6 sides. If I want to see all the 6 sides of the cube one by one, how would I do that? I mean if I place my camera whose X position is greater than my object and look at the object, shouldn’t I see the right plane of the cube? Again if mu camera Y is greater and lookAt the object, i should see top side of the object. I mean Isn’t it work this way? I know camera is looking at negative Z, but if i position the camera (changing its x,y,z relative to the cube) and lookat the cube from that position, shouldn’t I see that side of the cube? Isnt it like this?

Thank you, it may feel silly. But any reference or docs would be appreciated.

Hello @mahadi , if I understood your question correctly

Yes, you are correct that positioning the camera in relation to the cube and using the lookAt() method will allow you to see different sides of the cube. Specifically, positioning the camera on the positive X-axis relative to the cube and using the lookAt() method will allow you to see the right side of the cube, positioning the camera on the positive Y-axis relative to the cube and using the lookAt() method will allow you to see the top side of the cube, and so on.

Here is an example of how you might rotate the camera to see the different sides of the cube:

// create a camera
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

// position the camera to the right of the cube
camera.position.x = 1;
camera.lookAt(new THREE.Vector3(0, 0, 0));

// render the scene
renderer.render(scene, camera);

// change the camera position to the top of the cube
camera.position.y = 1;
camera.lookAt(new THREE.Vector3(0, 0, 0));

// render the scene again
renderer.render(scene, camera);

The camera will be positioned on the right of the cube and then on the top of the cube and it will look at the cube’s center. You can also use animation to rotate the cube and camera together to see all the sides.

I hope it helps you with your question.

Hi, thank you so much. I was just being sure, coz lately I am working in a project and um i have position of the cube and position of the camera (both in world space) and they are like comeing from a continuous source, so in animation frame both the camera and cune position is updating continuously. The expected output was the right side of the cube to be visible in the screen. But however, i tried all the possible ways to think, draw and implement it, i always see the rigjt side of the cube from a specific angle. Not directly from right side, it looks like as of my camera has a Z value greater/less than my cune position which ultimately creates the view like this. So i was thinking what I am doing wrong and all.

Btw thank you for clearing my confusion.