Get camera horizontal vector


I’d like to know how can I get the vector that’s perpendicular to the lookAt vector and colinear to the horizontal axis of the camera. Note that the camera is always facing the origin.

In other words, no matter what the camera position is, I’d like to be able to place a mesh that will appear at the centre right of the screen (at a distance of 100 from the origin).

Thanks guys!

Do you mean something like cameraTarget.clone().sub(camera.position).applyAxisAngle(cameraTarget.up, Math.PI / 2) :thinking:?

(You can also just try moving camera.getWorldDirection().clone() to cameraTarget.position and then apply the axis rotation - it should work the same.)

Thanks for answering. However, I don’t get it. What are you calling cameraTarget? The origin vector? What’s cameraTarget.up?

To clarify: I wan’t the mesh, when I place it, to be visually on the same horizontal line as the origin. No matter what the camera position is (I use OrbitControls with autoRotate = true). The camera is always at a distance of 100 from the origin.

This is the effect I want (the left-hand bag is at position (0, 0, 0)):

  1. I may misunderstand, but why consider camera at all then? Wouldn’t object2.position.copy(object1.position).add(new Three.Vector3(1.0, 0.0, 0.0) be sufficient :thinking: ? (x-axis is, in most cases, world horizontal axis left-right, z-axis is horizontal axis front-back.) Orbit controls changes the position of the camera, objects remain untranslated and unrotated at all times, so you are free to create new objects and place them relative to the original ones, no heavy math involved.

Up vector is a direction “upwards” for each object (docs - Object3D.up.)

I think so, I was basing on your post - though as I said, I might not have gotten exactly what you’re aiming for.

Edit: Or maybe it’ll be easier this way - just pick a color that you had on your mind :upside_down_face: Calculations for each vector are marked with color name in the code, so it hopefully won’t be too hard to find the right one.