Skip to content

Commit

Permalink
fix projection (for subscenes as well)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel committed Mar 28, 2020
1 parent 82ad903 commit bdbcec5
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
topparent(x::Scene) = isnothing(x.parent) ? x : topparent(x.parent)

This comment has been minimized.

Copy link
@asinghvi17

asinghvi17 Mar 28, 2020

Member

This is also what AbstractPlotting.root does, so we could reuse that

This comment has been minimized.

Copy link
@jkrumbiegel

jkrumbiegel Mar 28, 2020

Author Member

I tried rootparent because it sounded like that's what it was doing, but it isn't

This comment has been minimized.

Copy link
@asinghvi17

asinghvi17 Mar 28, 2020

Member

Looks like rootparent finds the Scene which contains a Plot somewhere deep in a nested structure...


function project_position(scene, point, model)
p4d = to_ndim(Vec4f0, to_ndim(Vec3f0, point, 0f0), 1f0)

clip = scene.camera.projectionview[] * model * p4d
p = (clip / clip[4])[Vec(1, 2)]
p = collect((p .+ 1) ./ 2)
w, h = scene.camera.resolution[]

# p_m1_p1 is in scene-relative -1 to 1 space
p_m1_p1 = (clip / clip[4])[Vec(1, 2)]

# p_0_1 is in scene-relative 0 to 1 space
p_0_1 = collect((p_m1_p1 .+ 1) ./ 2)

subarea = scene.px_area[]
rootarea = topparent(scene).px_area[]

p_subscene = p_0_1 .* subarea.widths .+ subarea.origin

@assert rootarea.origin == Point2f0(0, 0)
p_0_1_root = p_subscene ./ rootarea.widths

w, h = rootarea.widths
if w > h
p[2:2:end] .*= (h / w)
p_0_1_root[2:2:end] .*= (h / w)
else
p[1:2:end] .*= (w / h)
p_0_1_root[1:2:end] .*= (w / h)
end
return Vec2f0(p)
return Vec2f0(p_0_1_root)
end

project_scale(scene::Scene, s::Number) = project_scale(scene, Vec2f0(s))
Expand Down

0 comments on commit bdbcec5

Please sign in to comment.