# Plot the camera field of view in Makie?

There is probably a way to achieve this using `camera` properties, but how could the field of view of the current camera be displayed onto another scene in Makie ?

In terms of rendering, one could expect something like

take from https://www.rerun.io/

This is of particular interest when zooming in a large scene but while having an overall picture in a corner. The idea would be to show the current vision cone upon updating of the camera of the main scene.

I’ll try to provide an example of what I have in mind.

One way to do it is to do an inverse transform from clip space back to data space. (And maybe that’s also a good way to do it since you don’t depend on what kind of projection the camera uses.)

``````fig = Figure()
ax = LScene(fig[1, 1], show_axis = false)
cam3d!(ax)

mesh!(ax, Rect2f(-10, -10, 20, 20), color = :lightgray)
meshscatter!(ax, [2 .* rand(Point3f) .- 1 for _ in 1:100], color = rand(100))

# generate clip space rectangle coordinates
frustum_ps = Observable(Point3f[])
r = Rect3f(Point3f(-1, -1, 0), Vec3f(2, 2, 1))
rect_ps = coordinates(r) .|> Point3f
insert!(rect_ps, 13, Point3f(1, -1, 1)) # fix bad line

# on key press, convert clip space back to data space
on(events(fig).keyboardbutton) do e
if (e.key == Keyboard.t) && (e.action == Keyboard.press)
inv_pv = inv(ax.scene.camera.projectionview[])
ps = map(rect_ps) do p
p = inv_pv * to_ndim(Point4f, p, 1)
return p[Vec(1,2,3)] / p[4]
end
frustum_ps[] = ps
end
end

# show frustum
lines!(ax, frustum_ps, color = :red)

update_cam!(ax.scene, Rect3f(Point3f(-1), Vec3f(2)))

fig
``````
1 Like

Thanks for you answer @ffreyer ! My Makie seems to complain about the `coordinates` function though. I’m running this on GLMakie v0.8.2, is this function part of master ?

It’s part of GeometrBasics