Rotate camera about point in Makie 3D scene

This is what I’ve got for keeping my 3D scene pointed at the origin. It seems a bit janky, is there a better way?

function lookcenter(scene, stopper)
  @async begin
    while !stopper[] && isopen(scene)
      sleep(0.25)
      ep = scene.camera.eyeposition[]
      update_cam!(scene, ep, Vec3f0(0))
    end
  end
end

stopper = Ref(false)
lookcenter(scene, stopper)

# to end the task later:
stopper[] = true

cam3d_cad! may do what you want. It does not translate the lookat when zooming, only when right-click dragging. You can use one of:

  • fig, ax, p = scatter(rand(Point3f0, 10), camera=cam3d_cad!)
  • ax = LScene(..., scene_kw=(camera=cam3d_cad!,))
  • cam3d_cad!(ax.scene)

I tried that and it doesn’t quite do what I want, as it’s too easy to translate and once that happens it’s hard to get back to where I started.

You can adjust pan_button as a keyword argument to cam3d_cad!. I think the way it’s implemented you could set it to Keyboard.left_control, for example, and it would trigger when you press left control and hold any mouse button down. There’s also move_key which is an additional you’d have to press, though that applies to both rotating and panning.

Thanks, that works!

Relatedly, I’d like if possible to have zooming via the mouse (2-finger drag up/down, equivalent to mouse wheel) also not modify the lookat position. Or maybe better would be for it to operate along the vector from eyeposition to lookat position.

Obviously it can be done with Observables but that seems like an option of last resort.

Edit: Actually, never mind. I was using cam3d! not cam3d_cad. With the latter it has the zoom behavior I’m looking for.