Skip to content

Commit

Permalink
do not connect transformations in different spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Oct 12, 2023
1 parent 1e4d153 commit 5a495ce
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/camera/camera2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ end
"""
cam2d!(scene::SceneLike, kwargs...)
Creates a 2D camera for the given `scene`. The camera implements zooming by
scrolling and translation using mouse drag. It also implements rectangle
Creates a 2D camera for the given `scene`. The camera implements zooming by
scrolling and translation using mouse drag. It also implements rectangle
selections.
## Keyword Arguments
Expand Down Expand Up @@ -46,6 +46,7 @@ function cam2d!(scene::SceneLike; kw_args...)
cam
end

get_space(::Camera2D) = :data
wscale(screenrect, viewrect) = widths(viewrect) ./ widths(screenrect)


Expand Down Expand Up @@ -310,13 +311,15 @@ function add_restriction!(cam, window, rarea::Rect2, minwidths::Vec)
end

struct PixelCamera <: AbstractCamera end
get_space(::PixelCamera) = :pixel


struct UpdatePixelCam
camera::Camera
near::Float32
far::Float32
end
get_space(::UpdatePixelCam) = :pixel

function (cam::UpdatePixelCam)(window_size)
w, h = Float32.(widths(window_size))
Expand All @@ -327,7 +330,7 @@ end
"""
campixel!(scene; nearclip=-1000f0, farclip=1000f0)
Creates a pixel camera for the given `scene`. This means that the positional
Creates a pixel camera for the given `scene`. This means that the positional
data of a plot will be interpreted in pixel units. This camera does not feature
controls.
"""
Expand All @@ -345,11 +348,12 @@ function campixel!(scene::Scene; nearclip=-10_000f0, farclip=10_000f0)
end

struct RelativeCamera <: AbstractCamera end
get_space(::RelativeCamera) = :relative

"""
cam_relative!(scene)
Creates a camera for the given `scene` which maps the scene area to a 0..1 by
Creates a camera for the given `scene` which maps the scene area to a 0..1 by
0..1 range. This camera does not feature controls.
"""
function cam_relative!(scene::Scene; nearclip=-10_000f0, farclip=10_000f0)
Expand Down
2 changes: 2 additions & 0 deletions src/camera/camera3d.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
abstract type AbstractCamera3D <: AbstractCamera end

get_space(::AbstractCamera3D) = :data

struct Camera3D <: AbstractCamera3D
# User settings
settings::Attributes
Expand Down
2 changes: 2 additions & 0 deletions src/camera/old_camera3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ function old_cam3d_cad!(scene::Scene; kw_args...)
cam
end

get_space(::OldCamera3D) = :data

"""
old_cam3d_turntable!(scene; kw_args...)
Expand Down
6 changes: 6 additions & 0 deletions src/camera/projection_math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ function clip_to_space(cam::Camera, space::Symbol)
end
end

get_space(scene::Scene) = get_space(cameracontrols(scene))
# TODO: Should we default to something invalid?
get_space(::AbstractCamera) = :data
# TODO: Should this be less specialized? ScenePlot? AbstractPlot?
get_space(plot::Combined) = to_value(get(plot, :space, :data))

function project(cam::Camera, input_space::Symbol, output_space::Symbol, pos)
input_space === output_space && return to_ndim(Point3f, pos, 0)
clip_from_input = space_to_clip(cam, input_space)
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ function connect_plot!(parent::SceneLike, plot::Combined{F}) where {F}
transform!(t, t_user)
plot.transformation = t
end
connect!(transformation(parent), transformation(plot))
if get_space(parent) === get_space(plot)
connect!(transformation(parent), transformation(plot))
end
end
plot.model = transformationmatrix(plot)
convert_arguments!(plot)
Expand Down

0 comments on commit 5a495ce

Please sign in to comment.