# How to make fly-through animations?

**URL:** <https://discourse.julialang.org/t/how-to-make-fly-through-animations/129775>\
**Category:** Visualization\
**Tags:** makie, glmakie\
**Created:** [June 10, 2025, 5:15am UTC](https://discourse.julialang.org/t/how-to-make-fly-through-animations/129775 "2025-06-10T05:15:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsgg](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hsgg](https://discourse.julialang.org/u/hsgg)\
**Post date:** [June 10, 2025, 5:15am UTC](https://discourse.julialang.org/t/how-to-make-fly-through-animations/129775/1 "2025-06-10T05:15:31Z")

</div>

I am trying to use `Makie.jl` to create a nice 3D visualization of a galaxy survey. Essentially, I count the number of galaxies within a grid cell, and then use `GLMakie.volume(vol)`. The interactive display is already pretty nice!

Now, I would like to make an animation where the camera flies through the survey volume. I’m trying to follow [this tutorial](https://docs.makie.org/stable/tutorials/scenes.html#Projections-and-Camera). However, I’m not sure how to control the camera. Here is a minimal example:

```julia
using GLMakie
vol = randn(128, 128, 128);
fig, scene, _ = GLMakie.volume(vol)

camera = Makie.camera(scene)

eyeposition = Vec3f(300, 300, 300)
lookat = Vec3f(-0.5, -0.5, -0.5)
upvector = Vec3f(0, 0, 1)
camera.view[] = Makie.lookat(eyeposition, lookat, upvector)

```

Problems:

- The camera view seems to only sporadically update in a nondeterministic way. That makes it very difficult to develop some intuition on the correct parameters.
- Changing the `lookat` vector seems to have much smaller effect than I would expect. For example, changing it to `(0,0,1)`, I would expect the camera to look straight up and miss the cube entirely. Instead, the cube is still there.
- After a few attempts the cube no longer looks the same, even with the original view. Though using the mouse to rotate the cube fixes it - after the cube jumps to a new place.
- How to control the zoom?

Any help much appreciated!

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [June 10, 2025, 10:50am UTC](https://discourse.julialang.org/t/how-to-make-fly-through-animations/129775/2 "2025-06-10T10:50:06Z")

</div>

Try FlyThroughPaths.jl, it was made for this kind of thing!

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [June 10, 2025, 5:51pm UTC](https://discourse.julialang.org/t/how-to-make-fly-through-animations/129775/3 "2025-06-10T17:51:48Z")

</div>

I’m not sure how `Makie.camera` works exactly or what goes wrong, but you could instead use

```julia
using GLMakie
vol = randn(128, 128, 128)
fig, scene, _ = GLMakie.volume(vol)

camera = cameracontrols(scene)

camera.lookat[] = Vec3f(-0.5, -0.5, -0.5)
camera.upvector[] = Vec3f(0, 0, 1)
camera.eyeposition[] = Vec3f(300, 300, 300)

update_cam!(scene.scene)

```

or update the three `Observables` via `update_cam!` arguments, as is used later in the tutorial you refer to. Replacing the `camera = cameracontrols(scene)` line by `camera = Camera3D(scene.scene, projectiontype = Makie.Perspective)` yields the same result, cf. [this example](https://docs.makie.org/dev/explanations/cameras#Example-Visualizing-the-cameras-view-box) in the Makie documentation.

- We’re explicitly using `update_cam!` here to update the scene camera.
- `lookat` refers to a point in space, not a viewing direction. (You might want to use `Point3f` to emphasise this.) For the scene scale, `(0, 0, 1)` is just quite close to `(-0.5, -0.5, -0.5)`, so that the difference is not very noticeable. Try something like `Vec3f(0, 0, 300)` to look above the cube.
- In the `Makie.camera` approach I can indeed replicate this, but not using `cameracontrols` or `Camera3D`. In the latter case our `camera` gets updated when manually interacting with the figure, while this is not the case in the former case: manual interaction causes the camera to snap back to its old settings. Perhaps the issue is related to the fact Makie then needs to store two separate cameras?
- You can adjust the zoom level using `zoom!(scene.scene, relative_zoom_factor)`. See [https://docs.makie.org/dev/explanations/cameras#3D-Camera](https://docs.makie.org/dev/explanations/cameras#3D-Camera). E.g. `zoom!(scene.scene, 0.5)` makes everything bigger. Alternatively, you could change `camera.fov[]` (in degrees).

---

<div class="post-metadata">

**Author:** ![hsgg](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hsgg](https://discourse.julialang.org/u/hsgg)\
**Post date:** [June 11, 2025, 6:33am UTC](https://discourse.julialang.org/t/how-to-make-fly-through-animations/129775/4 "2025-06-11T06:33:54Z")

</div>

@eldee: Extremely helpful answer! Thanks!

The link to the Cameras documentation is very useful. My feedback would be that core concepts like the meaning of `lookat` are a bit buried under the heading “other kwargs…”. I also find it surprising that “zoom” changes the eyeposition.

I need to play a little more with all the options, especially `near` and `far`, and the FlyThroughPaths.jl package, but thank you both for excellent answers.

---

<div class="post-metadata">

**Author:** ![hsgg](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hsgg](https://discourse.julialang.org/u/hsgg)\
**Post date:** [June 15, 2025, 8:53pm UTC](https://discourse.julialang.org/t/how-to-make-fly-through-animations/129775/5 "2025-06-15T20:53:28Z")

</div>

OK, I have another question: When entering the volume, it seems that regions from behind get shown, moving forward. Here is a minimal example:

```julia
using GLMakie
vol = rand(1000,50,50);
fig, scene, _ = volume(vol)

controls = cameracontrols(scene)

# position the camera at the long end:
controls.eyeposition[] = Vec3f(1300, 25, 25)
controls.lookat[] = Point3f(1200, 25, 25)
update_cam!(scene.scene)

```

Next, press `w` to enter the volume. Once inside notice how elements from behind seem to get mirrored across the direction of view, creating an effect where part of the volume is moving past you from behind.

(I’ve attempted to create a new `Camera3D` with different `clipping_mode`s and setting `near` and `far`, but all just seems to make things worse than the default.)

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [June 16, 2025, 10:26pm UTC](https://discourse.julialang.org/t/how-to-make-fly-through-animations/129775/7 "2025-06-16T22:26:05Z")

</div>

That’s probably a bug with volume. I’d guess the rays don’t clamp to the view box correctly and end up starting behind the camera. Would be good to have an issue for this

---

<div class="post-metadata">

**Author:** ![hsgg](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hsgg](https://discourse.julialang.org/u/hsgg)\
**Post date:** [June 17, 2025, 4:54am UTC](https://discourse.julialang.org/t/how-to-make-fly-through-animations/129775/8 "2025-06-17T04:54:11Z")

</div>

Made a bug report: [volume shows objects from behind the camera · Issue #5085 · MakieOrg/Makie.jl · GitHub](https://github.com/MakieOrg/Makie.jl/issues/5085)
