How does the editor's viewport camera determine where the focus is?

Godot Version

4.2.1

Question

I’m trying to create a program where I need to let the user inspect an object by moving around it using a mouse and keyboard. Basically, I’d like to create an interactive experience very similar to what happens when you use the mouse and keyboard to navigate in Godot’s editor viewport.

I’m having trouble figuring out how to set the focal point, though. The focal point is the point in front of the camera that you rotate around when you middle mouse click and drag in the viewport. And while the focal point seems to always be somewhere on the camera’s -Z axis, how far along that axis keeps changing as you move around the viewport. Is there some document that explains exactly how this value changes? How would I implement this in my own control?

One method you could use is have a Marker3D (I’m assuming you are working in 3D), then your camera as a child of that. This way, you rotate the marker instead of the camera, and the marker acts as your focal point, which you can then manipulate.

That wouldn’t really let me move the camera the way it moves in the viewport. It would just give me a camera tracking tool.