Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Creating CAD style camera handling #147

Closed
Kevin-Mattheus-Moerman opened this issue Jun 18, 2019 · 21 comments
Closed

Creating CAD style camera handling #147

Kevin-Mattheus-Moerman opened this issue Jun 18, 2019 · 21 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Kevin-Mattheus-Moerman
Copy link

This relates to:
JuliaGL/GLAbstraction.jl#96 (and also: MakieOrg/Makie.jl#38, JuliaGL/GLAbstraction.jl#76, JuliaGL/GLAbstraction.jl#80, MakieOrg/Makie.jl#329).

Moving discussion here as it is about AbstractPlotting's camera handling (in particular https://github.com/JuliaPlots/AbstractPlotting.jl/blob/master/src/camera/camera3d.jl)

@Kevin-Mattheus-Moerman
Copy link
Author

The goals is to have AbstractPlottings camera handling be like this (screenshot of MeshLab):

cat
i.e. such that moving the cursor to the left or right (screen's/viewer's [1 0] direction) rotates the object around the screen's/viewer's vertical axis ([0 1]). Similarly moving the cursor up or down (screen's/viewer's [0 1] direction) will rotate the object around the screen's/viewer's left-right or horizontal axis ([1 0]).

@asinghvi17 asinghvi17 added enhancement New feature or request help wanted Extra attention is needed labels Jun 18, 2019
@CarpeNecopinum
Copy link
Contributor

Replacing
rotation = rotate_cam(theta_v, right_v, Vec3f0(0, 0, sign(upvector[3])), dir)
in line 189 by
rotation = rotate_cam(theta_v, right_v, upvector, dir)
already gets us most of the way there.

Additionally I suggest removing line 174 (cam.lookat[] = lookat + zoom_translation) for a more CAD-style feeling, as it allows rotation of a zoomed-in object.

If desired, I can open a PR for this.

@CarpeNecopinum
Copy link
Contributor

In general I think we should allow multiple different 3d camera variants to exist in AbstractPlotting.jl, as the old behavior is probably better for "just a plot"-style scenes.

On the other end of the spectrum, I prefer a FPS/Spaceship-style camera movement (like in https://github.com/CarpeNecopinum/Shiny.jl/blob/master/src/movement.jl) for large, complex scenes.

@asinghvi17
Copy link
Member

@CarpeNecopinum, that would be great!

@Kevin-Mattheus-Moerman
Copy link
Author

👏 @CarpeNecopinum please do

CarpeNecopinum added a commit to CarpeNecopinum/AbstractPlotting.jl that referenced this issue Jun 27, 2019
Contains the changes suggested in issue  JuliaPlots#147.
@mschauer
Copy link
Contributor

Can you specify what the mechanics is? Do I understand that this corresponds to picking a vector from the center ending on the plane of view and moving the arrow tip on the plane of view and taking the rotation of the corresponding vector?

@SimonDanisch
Copy link
Member

cameras are also just recipe like, and the camera argument already works with arbitrary functions, that add a camera to the scene ;) So the design is already ready for different cameras!

@CarpeNecopinum
Copy link
Contributor

@mschauer It essentially just translates mouse drags on the x-axis to rotation around some "upwards" axis and mouse drags on the y-axis to rotation around some "right" axis.

The original cam3d! always used the global z-axis as "upwards", which gives you a turntable-style rotation where the up-axis of the camera and the z-axis of the world will always stay somewhat aligned (though you can flip the camera upside down).

The CAD-style camera uses the up-axis of the camera as "upwards" for the rotation, which allows any rotation to be achieved.

@mschauer
Copy link
Contributor

mschauer commented Jun 27, 2019

Ok, get it, thank you. That is equivalent or maybe actually the same as what I said. it would be worth to try to do it as I described and check if that gives a natural feel (if done right, then moving the mouse up and then right gets you to the same rotation as moving first right and then up). So the reference axes should perhaps not change while the mouse key is pressed.

@asinghvi17
Copy link
Member

We could create a CamCAD or something which would have this behaviour, and leave Cam3d intact, if people want that. Or, we could do it the other way around as well - it's simply a matter of dispatching to the correct methods, and the CamCAD could (maybe should) be a subtype of Cam3D (they will probably share a lot of code).

@CarpeNecopinum
Copy link
Contributor

CarpeNecopinum commented Jun 27, 2019

Since all the difference is in the event handlers anyways, we could probably do with just keeping the one Camera3D, but replace cam3d! with cam3d_cad! and cam3d_turntable! (still taking suggestions on the names 😉 , with cam3d! as alias to cam3d_turntable for compatibility with existing code).

@asinghvi17
Copy link
Member

A keyword argument in the constructor is always an option (cam3d!(;mode = :turntable)) for example.

@CarpeNecopinum
Copy link
Contributor

Should we make it part of the Theme then? That way, people could set their preferred style in the scene and rely on the automatic detection of 2d vs. 3d scenes, rather than having to call cam3d! with the preferred mode explicitly.

@asinghvi17
Copy link
Member

So something like cam3dstyle = :cad?

@SimonDanisch
Copy link
Member

Camera is already part of the theme:
https://github.com/JuliaPlots/AbstractPlotting.jl/blob/master/src/theming.jl#L44
and can be set to whatever camera function ;)

A keyword argument in the constructor is always an option (cam3d!(;mode = :turntable)) for example.

I don't like if kw_args change behaviour drastically... Also, this way we can't pass it to the camera keyword argument. Although, that you can't pass kw_args to the camera is a bit lame and something we should fix.

@asinghvi17
Copy link
Member

One thing we can do, is implement this suggestion:

Since all the difference is in the event handlers anyways, we could probably do with just keeping the one Camera3D, but replace cam3d! with cam3d_cad! and cam3d_turntable! (still taking suggestions on the names 😉 , with cam3d! as alias to cam3d_turntable for compatibility with existing code).

and leave the default as it is, with the option to change the default at 1.0.0 release.

asinghvi17 pushed a commit that referenced this issue Jul 6, 2019
Contains the changes suggested in issue  #147.
@CarpeNecopinum
Copy link
Contributor

Camera is already part of the theme:
https://github.com/JuliaPlots/AbstractPlotting.jl/blob/master/src/theming.jl#L44
and can be set to whatever camera function ;)

One issue I just found is that setup_camera! checks for a limited list of function names, and errors out if the function in the theme doesn't match any of (cam2d!, cam3d!, campixel!).
(https://github.com/JuliaPlots/AbstractPlotting.jl/blob/master/src/interfaces.jl#L598)

You can still add a custom camera function by calling it explicitly, but it being able to be part of the theme would definitely be nicer.

I thought about replacing the check by testing if the camera function can be called on scene, but that'll effectively done by Julia already, so I'd suggest just leaving it out entirely.

@SimonDanisch
Copy link
Member

We could leave the check to open this up ;) or add the new camera to the list! The question is, do we want to have cameras live in packages, or are we fine with adding all custom cameras to AbstractPlotting?

@asinghvi17
Copy link
Member

I think it's perfectly fine for a package to define it's own camera style...

@SimonDanisch
Copy link
Member

Yeah it's fine, but I wonder if it wouldn't be better to enforce that people add it as a PR, so that different cameras are more visible!

@asinghvi17
Copy link
Member

asinghvi17 commented Jul 12, 2019

Sure, that makes sense...perhaps we should add a warning in the docs, along with any new camera page that's added - which I could get around to in a week or so. We could also print a request to upstream a new camera type if it's detected.

@asinghvi17 asinghvi17 added this to To do / Planned in Makie.jl planned features via automation Jul 14, 2019
@asinghvi17 asinghvi17 moved this from To do / Planned to Done in Makie.jl planned features Jul 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Development

No branches or pull requests

5 participants