-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix projection (for subscenes as well)
- Loading branch information
1 parent
82ad903
commit bdbcec5
Showing
1 changed file
with
22 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jkrumbiegel
Author
Member
|
||
|
||
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)) | ||
|
This is also what
AbstractPlotting.root
does, so we could reuse that