Skip to content

Commit

Permalink
fix camera clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Jan 4, 2024
1 parent ececc62 commit 3830568
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Changes for Bonito rename and WGLMakie docs improvements [#3477](https://github.com/MakieOrg/Makie.jl/pull/3477).
- Add stroke and glow support to scatter and text in WGLMakie [#3518](https://github.com/MakieOrg/Makie.jl/pull/3518).
- Fix clipping issues with Camera3D when zooming in [#3529](https://github.com/MakieOrg/Makie.jl/pull/3529)

## 0.20.3

Expand Down
6 changes: 3 additions & 3 deletions src/camera/camera3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function Camera3D(scene::Scene; kwargs...)
fixed_axis = true,
cad = false,
center = true,
clipping_mode = :adaptive
clipping_mode = :adaptive # TODO: use bbox to adjust near/far automatically
)

replace!(settings, :Camera3D, scene, overwrites)
Expand Down Expand Up @@ -728,7 +728,7 @@ function update_cam!(scene::Scene, cam::Camera3D)
far = far_dist * far
elseif cam.settings.clipping_mode[] === :adaptive
view_dist = norm(eyeposition - lookat)
near = view_dist * near; far = max(1f0, view_dist) * far
near = view_dist * near; far = max(radius(bounding_sphere), view_dist) * far
elseif cam.settings.clipping_mode[] !== :static
@error "clipping_mode = $(cam.settings.clipping_mode[]) not recognized, using :static."
end
Expand Down Expand Up @@ -775,7 +775,7 @@ function update_cam!(scene::Scene, cam::Camera3D, area3d::Rect, recenter::Bool =
cam.far[] = 2f0 * dist
elseif cam.settings.clipping_mode[] === :adaptive
cam.near[] = 0.1f0 * dist / norm(cam.eyeposition[] - cam.lookat[])
cam.far[] = 2.2f0 * dist / norm(cam.eyeposition[] - cam.lookat[])
cam.far[] = 2f0 * dist / radius
end

update_cam!(scene, cam)
Expand Down

0 comments on commit 3830568

Please sign in to comment.