LookAt behaviour difference between Camera and Object3D

I’ve got a “camera rig” setup where a Camera is parented to an Object3D which I move around. When it comes down to rotating it, I’m expecting this (pseudocode):

const rig = new Object3D();
const camera = new PerspectiveCamera();

to have the same effect as this:

const camera = new PerspectiveCamera();

But it doesn’t seem to work as I’m expecting - thought transforms would propagate normally down the hierarchy but the camera’s direction is fine when I call lookAting on it directly, but not when I do it on the parent object.

Checking the Object3D source code it does seem indeed that the lookAt behaviour differs if the object is a camera or not. Any idea on how I could get this to work with the parent object setup above?

THREE’s cameras are oriented into negative z space eg. opposite of object 3D’s ( -1 on the z axis for Objects is equal to +1 for cameras) try this after adding the camera to the rig…

camera.rotation.y = - Math.PI

There’s likely good reason for cameras having this behaviour, I’m not sure exactly why but may be better to figure a way of inverting the rigs y rotation instead of the camera although I’m not exactly sure…

1 Like

The bigger picture is - there are no cameras in 3D, a camera is an object that holds a transformation matrix to rotate the world before “you”.

My take on it:

“You” are looking down Z-axis because the computer screen for compatibility with 2D represents XY plane and in OpenGL the bottom left corner is the origin (so +X points right and +Y points up). In the right-handed coordinate system Z then points out of the screen and you are looking into the screen, down the Z axis.

NDC space (cube), the “near” plane of which is mapped onto the canvas, is left-handed coordinate system, so the depth Z axis goes into the screen.